forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created subscription extensions (Azure#1202)
* created subscription extensions * added sdk * updated with recent version o autorest.cli * actions * actions -> action * generated with new version * regenerated * fix params * moved files into the generated folder * fix path * fixed more imports * empty line at the end of file * fixed a few sanity issues * sanity fixes * adding entry to CODEOWNERS * added license header to actions * examples & test fixes * regenerated with proper tag * removed test for now * empty init * import custom properly * fixed problem * fixed custom * action * updated commands & vendored sdks * relative import * missing __init__.py in vendored_sdks * regenerated with flattened sdk * now actions more complete * action is fixed now * removed unnecessary stuff * fixes * sanity fixes * wildcard imports * fixed vendored_sdks location * unused imports again * fixed import * fixed sanity * try to disable flake8 * f403 * two spaces * moved sdk * removed old, added .flake8 * another try * try to dump checked files * navy's changes * two more fixes * fixes * sdk is regenerated * updated commands * fixed client factory * hack for config * undo config thing * add credential thingy * fix for owner * fixed body_owners * fix * fixes * one more space * more sanity * subscription_id help * removed pass * fixed examples * fixing examples * example fixes * one more fix * fix to manual part of sdk * fix import * try * too many blank lines * fixed help * unused import * updated example descriptions * confirmation and isexperimental * subscription create * one more * removed isPreview * one more blank * updated * undo one change
- Loading branch information
Zim Kalinowski
authored
Apr 20, 2020
1 parent
f737485
commit 25e160b
Showing
33 changed files
with
2,299 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 |
---|---|---|
|
@@ -97,3 +97,5 @@ | |
/src/databox/ @jsntcy | ||
|
||
/src/hpc-cache/ @qianwens | ||
|
||
/src/account/ @zikalino |
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,8 @@ | ||
.. :changelog: | ||
Release History | ||
=============== | ||
|
||
0.1.0 | ||
++++++ | ||
* Initial release. |
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,5 @@ | ||
Microsoft Azure CLI 'account' Extension | ||
========================================== | ||
|
||
This package is for the 'account' extension. | ||
i.e. 'az account' |
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 @@ | ||
[flake8] | ||
exclude = | ||
vendored_sdks |
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,41 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
from azext_account.generated._help import helps # pylint: disable=unused-import | ||
|
||
|
||
class SubscriptionClientCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
from azext_account.generated._client_factory import cf_account | ||
account_custom = CliCommandType( | ||
operations_tmpl='azext_account.custom#{}', | ||
client_factory=cf_account) | ||
super(SubscriptionClientCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
custom_command_type=account_custom) | ||
|
||
def load_command_table(self, args): | ||
from azext_account.generated.commands import load_command_table | ||
load_command_table(self, args) | ||
try: | ||
from azext_account.manual.commands import load_command_table as load_command_table_manual | ||
load_command_table_manual(self, args) | ||
except ImportError: | ||
pass | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azext_account.generated._params import load_arguments | ||
load_arguments(self, command) | ||
try: | ||
from azext_account.manual._params import load_arguments as load_arguments_manual | ||
load_arguments_manual(self, command) | ||
except ImportError: | ||
pass | ||
|
||
|
||
COMMAND_LOADER_CLS = SubscriptionClientCommandsLoader |
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,13 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=wildcard-import | ||
# pylint: disable=unused-wildcard-import | ||
|
||
from azext_account.generated.action import * # noqa: F403 | ||
try: | ||
from azext_account.manual.action import * # noqa: F403 | ||
except ImportError: | ||
pass |
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,4 @@ | ||
{ | ||
"azext.isExperimental": true, | ||
"azext.minCliCoreVersion": "2.3.1" | ||
} |
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,13 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=wildcard-import | ||
# pylint: disable=unused-wildcard-import | ||
|
||
from azext_account.generated.custom import * # noqa: F403 | ||
try: | ||
from azext_account.manual.custom import * # noqa: F403 | ||
except ImportError: | ||
pass |
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,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
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. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
def cf_account(cli_ctx, *_): | ||
from azure.cli.core.commands.client_factory import _get_mgmt_service_client | ||
from ..vendored_sdks.subscription import SubscriptionClient | ||
return _get_mgmt_service_client(cli_ctx, SubscriptionClient, | ||
subscription_bound=False, | ||
base_url_bound=False)[0] | ||
|
||
|
||
def cf_subscription(cli_ctx, *_): | ||
return cf_account(cli_ctx).subscription | ||
|
||
|
||
def cf_subscription_operation(cli_ctx, *_): | ||
return cf_account(cli_ctx).subscription_operation | ||
|
||
|
||
def cf_operation(cli_ctx, *_): | ||
return cf_account(cli_ctx).operation |
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,80 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
# pylint: disable=too-many-lines | ||
|
||
from knack.help_files import helps | ||
|
||
|
||
helps['account subscription'] = """ | ||
type: group | ||
short-summary: Manage subscriptions | ||
""" | ||
|
||
helps['account subscription create'] = """ | ||
type: command | ||
short-summary: Create a new WebDirect or EA Azure subscription. | ||
examples: | ||
- name: Create subscription | ||
text: |- | ||
az account subscription create --billing-account-name \\ | ||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_XXXX-XX-XX" \\ | ||
--billing-profile-name "27VR-HDWX-BG7-TGB" --cost-center "135366376" --display-name \\ | ||
"Contoso MCA subscription" --owner xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \\ | ||
--sku-id "0001" --invoice-section-name "JGF7-NSBG-PJA-TGB" | ||
""" | ||
|
||
|
||
helps['account subscription create-in-enrollment-account'] = """ | ||
type: command | ||
short-summary: Create subscription in enrolment account | ||
examples: | ||
- name: Create subscription in enrollment account | ||
text: |- | ||
az account subscription create-in-enrollment-account --display-name \\ | ||
"Test Ea Azure Sub" --offer-type "MS-AZR-0017P" --owners \\ | ||
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \\ | ||
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --enrollment-account-name \\ | ||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
""" | ||
|
||
helps['account subscription create-csp'] = """ | ||
type: command | ||
short-summary: Create a new CSP subscription. | ||
examples: | ||
- name: Create CSP subscription | ||
text: |- | ||
az account subscription create-csp --billing-account-name \\ | ||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_XXXX-XX-XX" \\ | ||
--display-name "Contoso MCA subscription" --sku-id "0001" --customer-name \\ | ||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
""" | ||
|
||
helps['account subscription rename'] = """ | ||
type: command | ||
short-summary: Rename subscription | ||
examples: | ||
- name: Rename subscription | ||
text: |- | ||
az account subscription rename --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
""" | ||
|
||
helps['account subscription cancel'] = """ | ||
type: command | ||
short-summary: Cancel subscription | ||
examples: | ||
- name: Cancel subscription | ||
text: |- | ||
az account subscription cancel --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
""" | ||
|
||
helps['account subscription enable'] = """ | ||
type: command | ||
short-summary: Enable subscription | ||
examples: | ||
- name: Enable subscription | ||
text: |- | ||
az account subscription enable --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
""" |
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,48 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
# pylint: disable=too-many-lines | ||
# pylint: disable=too-many-statements | ||
|
||
from azure.cli.core.commands.parameters import ( | ||
get_enum_type | ||
) | ||
|
||
|
||
def load_arguments(self, _): | ||
|
||
with self.argument_context('account subscription create') as c: | ||
c.argument('billing_account_name', help='The name of the Microsoft Customer Agreement billing account for which you want to create the subscription.') | ||
c.argument('billing_profile_name', help='The name of the billing profile in the billing account for which you want to create the subscription.') | ||
c.argument('invoice_section_name', help='The name of the invoice section in the billing account for which you want to create the subscription.') | ||
c.argument('display_name', help='The friendly name of the subscription.') | ||
c.argument('sku_id', help='The SKU ID of the Azure plan. Azure plan determines the pricing and service-level agreement of the subscription. Use 001 for Microsoft Azure Plan and 002 for Microsoft Azure Plan for DevTest.') | ||
c.argument('cost_center', help='If set, the cost center will show up on the Azure usage and charges file.') | ||
c.argument('owner', help='Active Directory Principal who’ll get owner access on the new subscription.') | ||
c.argument('management_group_id', help='The identifier of the management group to which this subscription will be associated.') | ||
|
||
with self.argument_context('account subscription create-in-enrollment-account') as c: | ||
c.argument('enrollment_account_name', help='The name of the enrollment account to which the subscription will be billed.') | ||
c.argument('display_name', help='The display name of the subscription.') | ||
c.argument('management_group_id', help='The Management Group Id.') | ||
c.argument('owners', nargs='+', help='The list of principals that should be granted Owner access on the subscription. Principals should be of type User, Service Principal or Security Group.') | ||
c.argument('offer_type', arg_type=get_enum_type(['MS-AZR-0017P', 'MS-AZR-0148P']), help='The offer type of the subscription. For example, MS-AZR-0017P (EnterpriseAgreement) and MS-AZR-0148P (EnterpriseAgreement devTest) are available. Only valid when creating a subscription in a enrollment account scope.') | ||
|
||
with self.argument_context('account subscription create-csp') as c: | ||
c.argument('billing_account_name', help='The name of the Microsoft Customer Agreement billing account for which you want to create the subscription.') | ||
c.argument('customer_name', help='The name of the customer.') | ||
c.argument('display_name', help='The friendly name of the subscription.') | ||
c.argument('sku_id', help='The SKU ID of the Azure plan. Azure plan determines the pricing and service-level agreement of the subscription. Use 001 for Microsoft Azure Plan and 002 for Microsoft Azure Plan for DevTest.') | ||
c.argument('reseller_id', help='Reseller ID, basically MPN Id.') | ||
|
||
with self.argument_context('account subscription rename') as c: | ||
c.argument('subscription_id', help='Subscription Id.') | ||
c.argument('subscription_name', help='New subscription name') | ||
|
||
with self.argument_context('account subscription cancel') as c: | ||
c.argument('subscription_id', help='Subscription Id.') | ||
|
||
with self.argument_context('account subscription enable') as c: | ||
c.argument('subscription_id', help='Subscription Id.') |
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,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
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,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
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,25 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
# pylint: disable=too-many-lines | ||
# pylint: disable=too-many-statements | ||
# pylint: disable=too-many-locals | ||
from azure.cli.core.commands import CliCommandType | ||
|
||
|
||
def load_command_table(self, _): | ||
|
||
from azext_account.generated._client_factory import cf_subscription | ||
account_subscription = CliCommandType( | ||
operations_tmpl='azext_account.vendored_sdks.subscription.operations._subscription_operations#SubscriptionOperations.{}', | ||
client_factory=cf_subscription) | ||
with self.command_group('account subscription', account_subscription, client_factory=cf_subscription) as g: | ||
g.custom_command('create', 'account_subscription_create_subscription', supports_no_wait=True) | ||
g.custom_command('rename', 'account_subscription_rename') | ||
g.custom_command('cancel', 'account_subscription_cancel', confirmation=True) | ||
g.custom_command('enable', 'account_subscription_enable') | ||
g.custom_command('create-csp', 'account_subscription_create_csp_subscription', supports_no_wait=True) | ||
g.custom_command('create-in-enrollment-account', 'account_subscription_create_subscription_in_enrollment_account', supports_no_wait=True) |
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,76 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
# pylint: disable=too-many-statements | ||
# pylint: disable=too-many-lines | ||
# pylint: disable=too-many-locals | ||
# pylint: disable=unused-argument | ||
|
||
from azure.cli.core.util import sdk_no_wait | ||
|
||
|
||
def account_subscription_create_subscription(cmd, client, | ||
billing_account_name, | ||
billing_profile_name, | ||
invoice_section_name, | ||
display_name, | ||
sku_id, | ||
cost_center=None, | ||
owner=None, | ||
management_group_id=None, | ||
no_wait=False): | ||
|
||
body = {} | ||
body['display_name'] = display_name | ||
body['sku_id'] = sku_id | ||
body['cost_center'] = cost_center | ||
body['owner'] = {'object_id': owner} | ||
body['management_group_id'] = management_group_id | ||
return sdk_no_wait(no_wait, client.create_subscription, billing_account_name=billing_account_name, billing_profile_name=billing_profile_name, invoice_section_name=invoice_section_name, body=body) | ||
|
||
|
||
def account_subscription_create_subscription_in_enrollment_account(cmd, client, | ||
enrollment_account_name, | ||
display_name=None, | ||
management_group_id=None, | ||
owners=None, | ||
offer_type=None, | ||
no_wait=False): | ||
if owners is not None: | ||
owners = [{'object_id': x} for x in owners] | ||
|
||
body = {} | ||
body['display_name'] = display_name | ||
body['management_group_id'] = management_group_id | ||
body['owners'] = owners | ||
body['offer_type'] = offer_type | ||
return sdk_no_wait(no_wait, client.create_subscription_in_enrollment_account, enrollment_account_name=enrollment_account_name, body=body) | ||
|
||
|
||
def account_subscription_create_csp_subscription(cmd, client, | ||
billing_account_name, | ||
customer_name, | ||
display_name, | ||
sku_id, | ||
reseller_id=None, | ||
no_wait=False): | ||
body = {} | ||
body['display_name'] = display_name | ||
body['sku_id'] = sku_id | ||
body['reseller_id'] = reseller_id | ||
return sdk_no_wait(no_wait, client.create_csp_subscription, billing_account_name=billing_account_name, customer_name=customer_name, body=body) | ||
|
||
|
||
def account_subscription_rename(cmd, client, subscription_id, | ||
subscription_name=None): | ||
return client.rename(subscription_id=subscription_id, subscription_name=subscription_name) | ||
|
||
|
||
def account_subscription_cancel(cmd, client, subscription_id): | ||
return client.cancel(subscription_id=subscription_id) | ||
|
||
|
||
def account_subscription_enable(cmd, client, subscription_id): | ||
return client.enable(subscription_id=subscription_id) |
Oops, something went wrong.