-
Notifications
You must be signed in to change notification settings - Fork 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 commands #5453
Changes from 7 commits
bfeb127
72eff01
76dba43
9ff171d
b8b37c4
8072792
4e61167
e05d0dc
0647fb6
ae8572e
3b9e493
2ab09b1
f84f839
f025c4a
356c646
d718b4b
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. :changelog: | ||
|
||
Release History | ||
=============== | ||
|
||
0.1.0 | ||
+++++++++++++++++++++ | ||
|
||
* Initial preview release. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include *.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Microsoft Azure CLI 'subscription' Command Module | ||
================================================= | ||
|
||
This package is for the 'subscription' module. | ||
i.e. 'az subscription' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import pkg_resources | ||
pkg_resources.declare_namespace(__name__) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import pkg_resources | ||
pkg_resources.declare_namespace(__name__) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import pkg_resources | ||
pkg_resources.declare_namespace(__name__) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 import AzCommandsLoader | ||
|
||
import azure.cli.command_modules.subscription._help # pylint: disable=unused-import | ||
|
||
|
||
class SubscriptionCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
subscription_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.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 azure.cli.command_modules.subscription.commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azure.cli.command_modules.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 azure.mgmt.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,11 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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.decorators import Completer | ||
|
||
|
||
@Completer | ||
def get_offer_type_completion_list(cmd, prefix, namespace): # pylint: disable=unused-argument | ||
return ['MS-AZR-0017P', 'MS-AZR-0148P'] | ||
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 azure.mgmt.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,12 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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'] = """ | ||
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. This is a very lengthy name for a top-level command. Also, the 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. Moved it under the account subgroup. Agree the name is long, but unfortunately I believe "definition" is too generic. Is there precedent for using shortened names, such as "subdef", so it becomes "account subdef list"? |
||
type: group | ||
short-summary: Manage Azure 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 azure.cli.command_modules.subscription._completers import get_offer_type_completion_list | ||
|
||
|
||
# pylint: disable=line-too-long | ||
def load_arguments(self, _): | ||
with self.argument_context('subscriptiondefinition show') as c: | ||
c.argument('subscription_definition_name', options_list=['--name', '-n'], required=False, help='Name of the subscription definition to 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. You don't need to call out "...to show". That way you only need to apply this alias once, with a scope of 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. |
||
|
||
with self.argument_context('subscriptiondefinition create') as c: | ||
c.argument('name', options_list=['--name', '-n'], required=True, help='Name of the subscription definition.') | ||
c.argument('offer_type', options_list=['--offer_type', '-ot'], required=True, help='The subscription\'s offer type.', completer=get_offer_type_completion_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. You cannot have a two-character short option. If anything there shouldn't be a short option, but if you really want one, You cannot use underscore in you long options. Just use Finally, you don't need/should not provide required=True/False. The CLI will infer that from your command signature based on whether you provided a default value. 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. |
||
c.argument('subscription_display_name', options_list=['--subscription_display_name', '-sdn'], required=False, 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. Same comments as above. Also, I would recommend shortening 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. Regarding subscription-display-name - just "display-name" doesn't properly capture the semantic here, so I'm leaving that as-is. |
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 azure.cli.command_modules.subscription._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='azure.mgmt.subscription.operations.subscription_definitions_operations#SubscriptionDefinitionsOperations.{}', | ||
client_factory=subscription_definitions_mgmt_client_factory, | ||
exception_handler=subscription_exception_handler | ||
) | ||
|
||
with self.command_group('subscriptiondefinition', 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') |
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. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.mgmt.subscription.models import SubscriptionDefinition | ||
|
||
|
||
def cli_subscription_create_subscription_definition(client, name, offer_type, subscription_display_name=None): | ||
"""Create a 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. Don't use custom command doc strings to populate help. Instead, add a command entry to you help.py file with this as the short-summary. The reason is because the live docs edit functionality will link directly to that, and will never find it here. |
||
new_def = SubscriptionDefinition( | ||
subscription_display_name=subscription_display_name if subscription_display_name else name, | ||
offer_type=offer_type) | ||
|
||
return client.create(name, new_def) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
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.
A completer is overkill for this. They are only used when you need to query the server for completions. Instead use:
arg_type=get_enum_typ(['MS-AZR-0017P', 'MS-AZR-0148P'])
in your params.py file for this parameter.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.