-
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
Changes from 10 commits
e70ef24
87e2013
a960ec4
a6d7711
742cdb5
1914cce
d3c1f47
28feacd
4acc2fa
d304a8c
a05fdae
fefe82d
b8d04fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ | |
/src/webapp/ @panchagnula | ||
|
||
/src/aem/ @yugangw-msft | ||
|
||
/src/subscription/ @wilcobmsft |
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 |
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 |
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()) |
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['subscriptiondefinition'] = """ | ||
type: group | ||
short-summary: Manage Azure Subscription Definitions. | ||
""" | ||
|
||
helps['subscriptiondefinition create'] = """ | ||
type: group | ||
short-summary: Create a subscription definition. | ||
""" |
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 subscriptiondefinition create') as c: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the help file, looks like the command is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the help file to use "account subscription-definition create". |
||
c.argument('offer_type', required=True, help='The subscription\'s offer type.', arg_type=get_enum_type(['MS-AZR-0017P', 'MS-AZR-0148P'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to provide a description of what each offer type means? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
c.argument('subscription_display_name', options_list=['--subscription-display-name', '-sdn'], help='The subscription display name of the subscription definition.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by removing the short-option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short options should only have a single character so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
for scope in ['account subscriptiondefinition create', 'account subscriptiondefinition show']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hyphenate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same q. about the command name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show + list help is coming directly from the generated SDK. |
||
with self.argument_context(scope) as c: | ||
c.argument('subscription_definition_name', options_list=['--name', '-n'], help='Name of the subscription definition.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"azext.minCliCoreVersion": "2.0.24" | ||
} |
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||
exception_handler=subscription_exception_handler | ||
) | ||
|
||
with self.command_group('account subscriptiondefinition', subscription_definition_util, client_factory=subscription_definitions_mgmt_client_factory) as g: | ||
g.command('list', 'list') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List command isn't defined in help.py. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show + list help is coming directly from the generated SDK. |
||
g.command('show', 'get') | ||
g.custom_command('create', 'cli_subscription_create_subscription_definition') |
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) |
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 |
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', | ||
] |
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) |
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 |
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) |
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.
The type should be command.
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.
Fixed