Skip to content

Commit

Permalink
[Account] Add new alias, tenant commands (#2308)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhou-msft authored Sep 9, 2020
1 parent 3713392 commit 120196e
Show file tree
Hide file tree
Showing 34 changed files with 4,181 additions and 1,135 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

/src/import-export/ @arrownj

/src/account/ @zikalino
/src/account/ @arrownj @jiasli @fengzhou-msft

/src/datashare/ @fengzhou-msft

Expand Down
7 changes: 7 additions & 0 deletions src/account/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
===============

0.2.0
+++++
* Breaking Change: remove `az account subscription create`.
* Add az account alias commands.
* Add az account tenant commands.
* Support sovereign clouds.

0.1.0
++++++
* Initial release.
2 changes: 1 addition & 1 deletion src/account/azext_account/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import

from azext_account.generated.action import * # noqa: F403
# from azext_account.generated.action import * # noqa: F403
try:
from azext_account.manual.action import * # noqa: F403
except ImportError:
Expand Down
10 changes: 5 additions & 5 deletions src/account/azext_account/generated/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ def cf_account(cli_ctx, *_):
from ..vendored_sdks.subscription import SubscriptionClient
return _get_mgmt_service_client(cli_ctx, SubscriptionClient,
subscription_bound=False,
base_url_bound=False)[0]
base_url_bound=True)[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_tenant(cli_ctx, *_):
return cf_account(cli_ctx).tenant


def cf_operation(cli_ctx, *_):
return cf_account(cli_ctx).operation
def cf_alias(cli_ctx, *_):
return cf_account(cli_ctx).alias
125 changes: 90 additions & 35 deletions src/account/azext_account/generated/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,123 @@
short-summary: Manage subscriptions
"""

helps['account subscription create'] = """
helps['account subscription rename'] = """
type: command
short-summary: Create a new WebDirect or EA Azure subscription.
short-summary: Rename subscription
examples:
- name: Create subscription
- name: Rename 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"
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 create-in-enrollment-account'] = """
helps['account subscription enable'] = """
type: command
short-summary: Create subscription in enrolment account
short-summary: Enable subscription
examples:
- name: Create subscription in enrollment account
- name: Enable subscription
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"
az account subscription enable --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
"""

helps['account subscription create-csp'] = """
helps['account subscription list'] = """
type: command
short-summary: Create a new CSP subscription.
short-summary: Get all subscriptions for a tenant.
examples:
- name: Create CSP subscription
- name: listSubscriptions
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"
az account subscription list
"""

helps['account subscription rename'] = """
helps['account subscription show'] = """
type: command
short-summary: Rename subscription
short-summary: Get details about a specified subscription.
examples:
- name: Rename subscription
- name: getSubscription
text: |-
az account subscription rename --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
az account subscription show --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
"""

helps['account subscription cancel'] = """
helps['account subscription list-location'] = """
type: command
short-summary: Cancel subscription
short-summary: This operation provides all the locations that are available for resource providers; however, each r\
esource provider may support a subset of this list.
examples:
- name: Cancel subscription
- name: listLocations
text: |-
az account subscription cancel --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
az account subscription list-location --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
"""

helps['account subscription enable'] = """
helps['account tenant'] = """
type: group
short-summary: Manage tenant
"""

helps['account tenant list'] = """
type: command
short-summary: Enable subscription
short-summary: Get the tenants for your account.
examples:
- name: Enable subscription
- name: listTenants
text: |-
az account subscription enable --subscription-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
az account tenant list
"""

helps['account alias'] = """
type: group
short-summary: Manage subscription alias
"""

helps['account alias list'] = """
type: command
short-summary: List Alias Subscriptions.
examples:
- name: List Alias Subscriptions
text: |-
az account alias list
"""

helps['account alias show'] = """
type: command
short-summary: Get Alias Subscription.
examples:
- name: GetAlias
text: |-
az account alias show --name "aliasForNewSub"
"""

helps['account alias create'] = """
type: command
short-summary: "Create Alias Subscription."
examples:
- name: CreateAlias
text: |-
az account alias create --name "aliasForNewSub" --billing-scope "/providers/Microsoft.Billing/billingAcc\
ounts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31/billingProfiles/PE2Q-NOIT-BG\
7-TGB/invoiceSections/MTT4-OBS7-PJA-TGB" --display-name "Contoso MCA subscription" --workload "Production"
"""

helps['account alias delete'] = """
type: command
short-summary: Delete Alias.
examples:
- name: DeleteAlias
text: |-
az account alias delete --name "aliasForNewSub"
"""

helps['account alias wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the account alias is met.
examples:
- name: Pause executing next line of CLI script until the account alias is successfully created.
text: |-
az account alias wait --name "aliasForNewSub" --created
"""
71 changes: 40 additions & 31 deletions src/account/azext_account/generated/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,52 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements

from azure.cli.core.commands.parameters import (
get_enum_type
)
from azure.cli.core.commands.parameters import get_enum_type
from ._validators import alias_validator


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')
c.argument('subscription_id', options_list=['--id', '--subscription-id'], help='Subscription Id.')
c.argument('subscription_name', options_list=['--name', '-n', '--subscription-name'], help='New subscription name')

with self.argument_context('account subscription cancel') as c:
c.argument('subscription_id', help='Subscription Id.')
c.argument('subscription_id', options_list=['--id', '--subscription-id'], help='Subscription Id.')

with self.argument_context('account subscription enable') as c:
c.argument('subscription_id', help='Subscription Id.')
c.argument('subscription_id', options_list=['--id', '--subscription-id'], help='Subscription Id.')

with self.argument_context('account subscription list') as c:
pass

with self.argument_context('account subscription show') as c:
c.argument('subscription_id', options_list=['--id', '--subscription-id'], help='The ID of the target subscription.', id_part='subscription')

with self.argument_context('account subscription list-location') as c:
c.argument('subscription_id', options_list=['--id', '--subscription-id'], help='The ID of the target subscription.')

with self.argument_context('account tenant list') as c:
pass

with self.argument_context('account alias list') as c:
pass

with self.argument_context('account alias show') as c:
c.argument('alias_name', options_list=['--name', '-n'], help='Alias Name')

with self.argument_context('account alias create', validator=alias_validator) as c:
c.argument('alias_name', options_list=['--name', '-n'], type=str, help='Alias Name')
c.argument('display_name', type=str, help='The friendly name of the subscription.')
c.argument('workload', arg_type=get_enum_type(['Production', 'DevTest']), help='The workload type of the '
'subscription. It can be either Production or DevTest.')
c.argument('billing_scope', type=str, help='Billing scope. It determines whether the subscription is Field-Led, Partner-Led or '
'LegacyEA')
c.argument('subscription_id', type=str, help='This parameter can be used to create alias for existing '
'subscription ID')

with self.argument_context('account alias delete') as c:
c.argument('alias_name', options_list=['--name', '-n'], help='Alias Name')

with self.argument_context('account alias wait') as c:
c.argument('alias_name', options_list=['--name', '-n'], help='Alias Name')
12 changes: 12 additions & 0 deletions src/account/azext_account/generated/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
# 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 alias_validator(namespace):
if namespace.subscription_id:
if namespace.billing_scope or namespace.display_name:
raise CLIError('--billing-scope or --display-name is not allowed when --subscription-id is provided.')
else:
if not namespace.billing_scope or not namespace.display_name or not namespace.workload:
raise CLIError('--billing-scope, --display-name and --workload are required when creating '
'an alias with a new susbcription.')
26 changes: 22 additions & 4 deletions src/account/azext_account/generated/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,28 @@ def load_command_table(self, _):
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)
with self.command_group('account subscription', account_subscription, client_factory=cf_subscription, is_experimental=True) as g:
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)
g.custom_command('list', 'account_subscription_list')
g.custom_show_command('show', 'account_subscription_show')
g.custom_command('list-location', 'account_subscription_list_location')

from azext_account.generated._client_factory import cf_tenant
account_tenant = CliCommandType(
operations_tmpl='azext_account.vendored_sdks.subscription.operations._tenant_operations#TenantOperations.{}',
client_factory=cf_tenant)
with self.command_group('account tenant', account_tenant, client_factory=cf_tenant, is_experimental=True) as g:
g.custom_command('list', 'account_tenant_list')

from azext_account.generated._client_factory import cf_alias
account_alias = CliCommandType(
operations_tmpl='azext_account.vendored_sdks.subscription.operations._alias_operations#AliasOperations.{}',
client_factory=cf_alias)
with self.command_group('account alias', account_alias, client_factory=cf_alias, is_experimental=True) as g:
g.custom_command('list', 'account_alias_list')
g.custom_show_command('show', 'account_alias_show')
g.custom_command('create', 'account_alias_create', supports_no_wait=True)
g.custom_command('delete', 'account_alias_delete')
g.custom_wait_command('wait', 'account_alias_show')
Loading

0 comments on commit 120196e

Please sign in to comment.