Skip to content
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 management groups commands to azure-cli-resource #6426

Merged
merged 13 commits into from
May 31, 2018
Binary file not shown.
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-resource/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

2.0.30
++++++
* Add management-group commands
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be more explicit especially since these commands live in the command tree that is predominantly in a different module.
"* add account management-group commands."

Copy link
Contributor Author

@rajshah11 rajshah11 May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok will make this change. Also, just checked the travis build. Will make the changes.


2.0.29
++++++
* Minor changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def _resource_managedapps_client_factory(cli_ctx, **_):
return get_mgmt_service_client(cli_ctx, ApplicationClient)


def _resource_managementgroups_client_factory(cli_ctx, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.managementgroups import ManagementGroupsAPI
return get_mgmt_service_client(cli_ctx, ManagementGroupsAPI, subscription_bound=False)


def cf_resource_groups(cli_ctx, _):
return _resource_client_factory(cli_ctx).resource_groups

Expand Down Expand Up @@ -96,3 +102,11 @@ def cf_resource_managedapplications(cli_ctx, _):

def cf_resource_managedappdefinitions(cli_ctx, _):
return _resource_managedapps_client_factory(cli_ctx).application_definitions


def cf_management_groups(cli_ctx, _):
return _resource_managementgroups_client_factory(cli_ctx).management_groups


def cf_management_group_subscriptions(cli_ctx, _):
return _resource_managementgroups_client_factory(cli_ctx).management_group_subscriptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# --------------------------------------------------------------------------------------------
# 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.util import CLIError


def managementgroups_exception_handler(ex):
from azure.mgmt.managementgroups.models import ErrorResponseException
if isinstance(ex, ErrorResponseException):
if ex.error.error:
raise CLIError(ex.error.error)
else:
raise CLIError(ex.error)
else:
import sys
from six import reraise
reraise(*sys.exc_info())
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,155 @@
text: >
az account lock update --name lockName --notes newNotesHere --lock-type CanNotDelete
"""
helps['account management-group'] = """
type: group
short-summary: Manage Azure Management Groups.
"""

helps['account management-group subscription'] = """
type: group
short-summary: Subscription operations for Management Groups.
"""

helps['account management-group list'] = """
type: command
short-summary: List all management groups.
long-summary: List of all management groups in the current tenant.
examples:
- name: List all management groups
text: >
az managementgroups group list
"""

helps['account management-group show'] = """
type: command
short-summary: Get a specific management group.
long-summary: Get the details of the management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
- name: --expand -e
type: bool
short-summary: If given or true, lists the children in the first level of hierarchy.
- name: --recurse -r
type: bool
short-summary: If given or true, lists the children in all levels of hierarchy.
examples:
- name: Get a management group.
text: >
az managementgroups group get --group-name GroupName
- name: Get a management group with children in the first level of hierarchy.
text: >
az managementgroups group get --group-name GroupName -e
- name: Get a management group with children in all levels of hierarchy.
text: >
az managementgroups group get --group-name GroupName -e -r
"""

helps['account management-group create'] = """
type: command
short-summary: Add a new management group.
long-summary: Add a new management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
- name: --display-name -d
type: string
short-summary: Sets the display name of the management group. If null, the group name is set as the display name.
- name: --parent-id -p
type: string
short-summary: Sets the parent of the management group. A fully qualified id is required. If null, the root tenant group is set as the parent.
examples:
- name: Add a new management group.
text: >
az managementgroups group new --group-name GroupName
- name: Add a new management group with a specific display name.
text: >
az managementgroups group new --group-name GroupName --display-name DisplayName
- name: Add a new management group with a specific parent id.
text: >
az managementgroups group new --group-name GroupName --parent-id ParentId
- name: Add a new management group with a specific display name and parent id.
text: >
az managementgroups group new --group-name GroupName --display-name DisplayName --parent-id ParentId
"""

helps['account management-group update'] = """
type: command
short-summary: Update an existing management group.
long-summary: Update an existing management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
- name: --display-name -d
type: string
short-summary: Updates the display name of the management group. If null, no change is made.
- name: --parent-id -p
type: string
short-summary: Update the parent of the management group. A fully qualified id is required. If null, no change is made.
examples:
- name: Update an existing management group with a specific display name.
text: >
az managementgroups group update --group-name GroupName --display-name DisplayName
- name: Update an existing management group with a specific parent id.
text: >
az managementgroups group update --group-name GroupName --parent-id ParentId
- name: Update an existing management group with a specific display name and parent id.
text: >
az managementgroups group update --group-name GroupName --display-name DisplayName --parent-id ParentId
"""

helps['account management-group delete'] = """
type: command
short-summary: Remove an existing management group.
long-summary: Remove an existing management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
examples:
- name: Remove an existing management group
text: >
az managementgroups group remove --group-name GroupName
"""

helps['account management-group subscription add'] = """
type: command
short-summary: Add a subscription to a management group.
long-summary: Add a subscription to a management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
- name: --subscription
type: string
short-summary: Subscription Id or Name
examples:
- name: Add a subscription to a management group.
text: >
az managementgroups group new --group-name GroupName --subscription Subscription
"""

helps['account management-group subscription remove'] = """
type: command
short-summary: Remove an existing subscription from a management group.
long-summary: Remove an existing subscription from a management group.
parameters:
- name: --group-name --name -n
type: string
short-summary: Name of the management group.
- name: --subscription
type: string
short-summary: Subscription Id or Name
examples:
- name: Remove an existing subscription from a management group.
text: >
az managementgroups group remove --group-name GroupName --subscription Subscription
"""

helps['policy'] = """
type: group
short-summary: Manage resource policies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,18 @@ def load_arguments(self, _):
c.argument('authorizations', options_list=('--authorizations', '-a'), nargs='+', help="space-separated authorization pairs in a format of <principalId>:<roleDefinitionId>")
c.argument('createUiDefinition', options_list=('--create-ui-definition', '-c'), help='JSON formatted string or a path to a file with such content', type=file_type)
c.argument('mainTemplate', options_list=('--main-template', '-t'), help='JSON formatted string or a path to a file with such content', type=file_type)

with self.argument_context('account management-group') as c:
c.argument('group_name', options_list=['--group-name', '--name', '-n'])

with self.argument_context('account management-group show') as c:
c.argument('expand', arg_type=get_three_state_flag(), options_list=['--expand', '-e'])
c.argument('recurse', arg_type=get_three_state_flag(), options_list=['--recurse', '-r'])

with self.argument_context('account management-group create') as c:
c.argument('display_name', options_list=['--display-name', '-d'])
c.argument('parent_id', options_list=['--parent-id', '-p'])

with self.argument_context('account management-group update') as c:
c.argument('display_name', options_list=['--display-name', '-d'])
c.argument('parent_id', options_list=['--parent-id', '-p'])
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
from azure.cli.command_modules.resource._client_factory import (
cf_resource_groups, cf_providers, cf_features, cf_tags, cf_deployments,
cf_deployment_operations, cf_policy_definitions, cf_policy_set_definitions, cf_resource_links,
cf_resource_managedapplications, cf_resource_managedappdefinitions)
cf_resource_managedapplications, cf_resource_managedappdefinitions, cf_management_groups, cf_management_group_subscriptions)
from azure.cli.command_modules.resource._validators import process_deployment_create_namespace

from ._exception_handler import managementgroups_exception_handler


# Resource group commands
def transform_resource_group_list(result):
Expand Down Expand Up @@ -119,6 +121,24 @@ def load_command_table(self, _):
resource_type=ResourceType.MGMT_RESOURCE_RESOURCES
)

resource_managementgroups_sdk = CliCommandType(
operations_tmpl='azure.mgmt.managementgroups.operations.management_groups_operations#ManagementGroupsOperations.{}',
client_factory=cf_management_groups,
exception_handler=managementgroups_exception_handler
)

resource_managementgroups_subscriptions_sdk = CliCommandType(
operations_tmpl='azure.mgmt.managementgroups.operations.management_group_subscriptions_operations#ManagementGroupSubscriptionsOperations.{}',
client_factory=cf_management_group_subscriptions,
exception_handler=managementgroups_exception_handler
)

resource_managementgroups_update_type = CliCommandType(
operations_tmpl='azure.cli.command_modules.resource.custom#{}',
client_factory=cf_management_groups,
exception_handler=managementgroups_exception_handler
)

with self.command_group('account lock', resource_lock_sdk, resource_type=ResourceType.MGMT_RESOURCE_LOCKS) as g:
g.custom_command('create', 'create_lock')
g.custom_command('delete', 'delete_lock')
Expand Down Expand Up @@ -244,3 +264,22 @@ def load_command_table(self, _):
g.command('delete', 'delete')
g.custom_command('show', 'show_applicationdefinition')
g.command('list', 'list_by_resource_group', exception_handler=empty_on_404)

with self.command_group('account management-group', resource_managementgroups_sdk, client_factory=cf_management_groups) as g:
g.custom_command('list', 'cli_managementgroups_group_list')
g.custom_command('show', 'cli_managementgroups_group_show')
g.custom_command('create', 'cli_managementgroups_group_create')
g.custom_command('delete', 'cli_managementgroups_group_delete')
g.generic_update_command(
'update',
getter_name='cli_managementgroups_group_update_get',
getter_type=resource_managementgroups_update_type,
setter_name='cli_managementgroups_group_update_set',
setter_type=resource_managementgroups_update_type,
custom_func_name='cli_managementgroups_group_update_custom_func',
custom_func_type=resource_managementgroups_update_type,
exception_handler=managementgroups_exception_handler)

with self.command_group('account management-group subscription', resource_managementgroups_subscriptions_sdk, client_factory=cf_management_group_subscriptions) as g:
g.custom_command('add', 'cli_managementgroups_subscription_add')
g.custom_command('remove', 'cli_managementgroups_subscription_remove')
Loading