-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Subscription RP extension. #49
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e70ef24
Add Subscription Definition commands.
wilcobmsft 87e2013
Add client arg parameter.
wilcobmsft a960ec4
Update tests
wilcobmsft a6d7711
Re-generate Python SDK.
wilcobmsft 742cdb5
Revert "Re-generate Python SDK."
wilcobmsft 1914cce
Ignore line-too-long errors.
wilcobmsft d3c1f47
Ignore subscription sdk pylint errors
wilcobmsft 28feacd
Update ignore list to reflect broader range of types typically coming…
wilcobmsft 4acc2fa
Style fixes
wilcobmsft d304a8c
Add codeowner entry
wilcobmsft a05fdae
PR feedback:
wilcobmsft fefe82d
Addressing PR feedback:
wilcobmsft b8d04fe
Merge branch 'master' into wilcob/subscription
derekbekoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ | |
/src/webapp/ @panchagnula | ||
|
||
/src/aem/ @yugangw-msft | ||
|
||
/src/subscription/ @wilcobmsft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=unused-import | ||
# pylint: disable=line-too-long | ||
|
||
from azure.cli.core import AzCommandsLoader | ||
from ._help import helps | ||
|
||
|
||
class SubscriptionCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
subscription_custom = CliCommandType(operations_tmpl='azext_subscription.custom#{}') | ||
super(SubscriptionCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=subscription_custom, | ||
min_profile="2017-03-10-profile") | ||
|
||
def load_command_table(self, args): | ||
from azext_subscription.commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azext_subscription._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = SubscriptionCommandsLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
def cf_subscription(cli_ctx, **_): | ||
from azure.cli.core.commands.client_factory import _get_mgmt_service_client | ||
from azext_subscription.subscription import SubscriptionClient | ||
client, _ = _get_mgmt_service_client(cli_ctx, SubscriptionClient, subscription_bound=False) | ||
return client | ||
|
||
|
||
def subscription_definitions_mgmt_client_factory(cli_ctx, kwargs): | ||
return cf_subscription(cli_ctx, **kwargs).subscription_definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from knack.util import CLIError | ||
|
||
|
||
def subscription_exception_handler(ex): | ||
from azext_subscription.subscription.models import ErrorResponseException | ||
if isinstance(ex, ErrorResponseException): | ||
message = ex.error.error.message | ||
raise CLIError(message) | ||
else: | ||
import sys | ||
from six import reraise | ||
reraise(*sys.exc_info()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from knack.help_files import helps | ||
|
||
|
||
helps['account subscription-definition'] = """ | ||
type: group | ||
short-summary: Manage Azure Subscription Definitions. | ||
""" | ||
|
||
helps['account subscription-definition create'] = """ | ||
type: command | ||
short-summary: Create a subscription definition. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.cli.core.commands.parameters import get_enum_type | ||
|
||
|
||
# pylint: disable=line-too-long | ||
def load_arguments(self, _): | ||
with self.argument_context('account subscription-definition create') as c: | ||
c.argument('offer_type', required=True, help='The offer type of the subscription. For example, MS-AZR-0017P (EnterpriseAgreement) and MS-AZR-0148P (EnterpriseAgreement devTest) are available.', arg_type=get_enum_type(['MS-AZR-0017P', 'MS-AZR-0148P'])) | ||
c.argument('subscription_display_name', help='The subscription display name of the subscription definition.') | ||
|
||
for scope in ['account subscription-definition create', 'account subscription-definition show']: | ||
with self.argument_context(scope) as c: | ||
c.argument('subscription_definition_name', options_list=['--name', '-n'], help='Name of the subscription definition.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"azext.minCliCoreVersion": "2.0.24" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=line-too-long | ||
|
||
from azure.cli.core.commands import CliCommandType | ||
from ._client_factory import subscription_definitions_mgmt_client_factory | ||
from ._exception_handler import subscription_exception_handler | ||
|
||
|
||
def load_command_table(self, _): | ||
subscription_definition_util = CliCommandType( | ||
operations_tmpl='azext_subscription.subscription.operations.subscription_definitions_operations#SubscriptionDefinitionsOperations.{}', | ||
client_factory=subscription_definitions_mgmt_client_factory, | ||
client_arg_name='self', | ||
exception_handler=subscription_exception_handler | ||
) | ||
|
||
with self.command_group('account subscription-definition', subscription_definition_util, client_factory=subscription_definitions_mgmt_client_factory) as g: | ||
g.command('list', 'list') | ||
g.command('show', 'get') | ||
g.custom_command('create', 'cli_subscription_create_subscription_definition') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azext_subscription.subscription.models import SubscriptionDefinition | ||
|
||
|
||
def cli_subscription_create_subscription_definition(client, subscription_definition_name, | ||
offer_type, subscription_display_name=None): | ||
if subscription_display_name is None: | ||
subscription_display_name = subscription_definition_name | ||
|
||
new_def = SubscriptionDefinition( | ||
subscription_display_name=subscription_display_name, | ||
offer_type=offer_type) | ||
|
||
return client.create(subscription_definition_name, new_def) |
17 changes: 17 additions & 0 deletions
17
src/subscription/azext_subscription/subscription/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from .subscription_client import SubscriptionClient | ||
from .version import VERSION | ||
|
||
__all__ = ['SubscriptionClient'] | ||
|
||
__version__ = VERSION |
46 changes: 46 additions & 0 deletions
46
src/subscription/azext_subscription/subscription/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from .subscription_definition import SubscriptionDefinition | ||
from .operation_display import OperationDisplay | ||
from .operation import Operation | ||
from .error_response import ErrorResponse, ErrorResponseException | ||
from .location import Location | ||
from .subscription_policies import SubscriptionPolicies | ||
from .subscription import Subscription | ||
from .tenant_id_description import TenantIdDescription | ||
from .operation_paged import OperationPaged | ||
from .subscription_definition_paged import SubscriptionDefinitionPaged | ||
from .location_paged import LocationPaged | ||
from .subscription_paged import SubscriptionPaged | ||
from .tenant_id_description_paged import TenantIdDescriptionPaged | ||
from .subscription_client_enums import ( | ||
SubscriptionState, | ||
SpendingLimit, | ||
) | ||
|
||
__all__ = [ | ||
'SubscriptionDefinition', | ||
'OperationDisplay', | ||
'Operation', | ||
'ErrorResponse', 'ErrorResponseException', | ||
'Location', | ||
'SubscriptionPolicies', | ||
'Subscription', | ||
'TenantIdDescription', | ||
'OperationPaged', | ||
'SubscriptionDefinitionPaged', | ||
'LocationPaged', | ||
'SubscriptionPaged', | ||
'TenantIdDescriptionPaged', | ||
'SubscriptionState', | ||
'SpendingLimit', | ||
] |
44 changes: 44 additions & 0 deletions
44
src/subscription/azext_subscription/subscription/models/error_response.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from msrest.serialization import Model | ||
from msrest.exceptions import HttpOperationError | ||
|
||
|
||
class ErrorResponse(Model): | ||
"""Describes the format of Error response. | ||
|
||
:param code: Error code | ||
:type code: str | ||
:param message: Error message indicating why the operation failed. | ||
:type message: str | ||
""" | ||
|
||
_attribute_map = { | ||
'code': {'key': 'code', 'type': 'str'}, | ||
'message': {'key': 'message', 'type': 'str'}, | ||
} | ||
|
||
def __init__(self, code=None, message=None): | ||
self.code = code | ||
self.message = message | ||
|
||
|
||
class ErrorResponseException(HttpOperationError): | ||
"""Server responsed with exception of type: 'ErrorResponse'. | ||
|
||
:param deserialize: A deserializer | ||
:param response: Server response to be deserialized. | ||
""" | ||
|
||
def __init__(self, deserialize, response, *args): | ||
|
||
super(ErrorResponseException, self).__init__(deserialize, response, 'ErrorResponse', *args) |
60 changes: 60 additions & 0 deletions
60
src/subscription/azext_subscription/subscription/models/location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from msrest.serialization import Model | ||
|
||
|
||
class Location(Model): | ||
"""Location information. | ||
|
||
Variables are only populated by the server, and will be ignored when | ||
sending a request. | ||
|
||
:ivar id: The fully qualified ID of the location. For example, | ||
/subscriptions/00000000-0000-0000-0000-000000000000/locations/westus. | ||
:vartype id: str | ||
:ivar subscription_id: The subscription ID. | ||
:vartype subscription_id: str | ||
:ivar name: The location name. | ||
:vartype name: str | ||
:ivar display_name: The display name of the location. | ||
:vartype display_name: str | ||
:ivar latitude: The latitude of the location. | ||
:vartype latitude: str | ||
:ivar longitude: The longitude of the location. | ||
:vartype longitude: str | ||
""" | ||
|
||
_validation = { | ||
'id': {'readonly': True}, | ||
'subscription_id': {'readonly': True}, | ||
'name': {'readonly': True}, | ||
'display_name': {'readonly': True}, | ||
'latitude': {'readonly': True}, | ||
'longitude': {'readonly': True}, | ||
} | ||
|
||
_attribute_map = { | ||
'id': {'key': 'id', 'type': 'str'}, | ||
'subscription_id': {'key': 'subscriptionId', 'type': 'str'}, | ||
'name': {'key': 'name', 'type': 'str'}, | ||
'display_name': {'key': 'displayName', 'type': 'str'}, | ||
'latitude': {'key': 'latitude', 'type': 'str'}, | ||
'longitude': {'key': 'longitude', 'type': 'str'}, | ||
} | ||
|
||
def __init__(self): | ||
self.id = None | ||
self.subscription_id = None | ||
self.name = None | ||
self.display_name = None | ||
self.latitude = None | ||
self.longitude = None |
27 changes: 27 additions & 0 deletions
27
src/subscription/azext_subscription/subscription/models/location_paged.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from msrest.paging import Paged | ||
|
||
|
||
class LocationPaged(Paged): | ||
""" | ||
A paging container for iterating over a list of :class:`Location <azure.mgmt.subscription.models.Location>` object | ||
""" | ||
|
||
_attribute_map = { | ||
'next_link': {'key': 'nextLink', 'type': 'str'}, | ||
'current_page': {'key': 'value', 'type': '[Location]'} | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
|
||
super(LocationPaged, self).__init__(*args, **kwargs) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client_arg_name
shouldn't be needed. What happens if you omit it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be due to Azure/azure-cli@6808e6b#diff-103131eb32c8ff55661bc902248c80a6R322?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my commands don't work without this ("missing parameter: self"). This was one of the main surprises I hit when converting from module to extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derekbekoe I see. Can you open an issue in the main CLI repo so I look into this in an upcoming sprint? Ideally this shouldn't be needed.