Skip to content
Merged
Prev Previous commit
Next Next commit
Changes suggested in PR/after review
  • Loading branch information
rajshah11 committed May 30, 2018
commit 80d08ab5e015c59b2c2ca9e16bb52710ceca7460
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ def cf_management_groups(cli_ctx, _):


def cf_management_group_subscriptions(cli_ctx, _):
return _resource_managementgroups_client_factory(cli_ctx).management_group_subscriptions
return _resource_managementgroups_client_factory(cli_ctx).management_group_subscriptions
Original file line number Diff line number Diff line change
Expand Up @@ -177,102 +177,102 @@
short-summary: Get a specific management group.
long-summary: Get the details of the management group.
parameters:
- name: --group-name --name -n
- 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.
short-summary: If given, 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.
short-summary: If given, lists the children in all levels of hierarchy.
examples:
- name: Get a management group.
text: >
az managementgroups group get --group-name GroupName
az managementgroups group show --name GroupName
- name: Get a management group with children in the first level of hierarchy.
text: >
az managementgroups group get --group-name GroupName -e
az managementgroups group show --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
az managementgroups group show --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.
short-summary: Create a new management group.
long-summary: Create a new management group.
Copy link
Member

Choose a reason for hiding this comment

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

long-summary should provide additional information, instead of being a duplicate of short-summary.

parameters:
- name: --group-name --name -n
- 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
- name: --parent -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.
short-summary: Sets the parent of the management group. Can be the fully qualified id or the name of the management group. If null, the root tenant group is set as the parent.
examples:
- name: Add a new management group.
- name: Create a new management group.
text: >
az managementgroups group new --group-name GroupName
- name: Add a new management group with a specific display name.
az managementgroups group create --name GroupName
- name: Create 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.
az managementgroups group create --name GroupName --display-name DisplayName
- name: Create 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.
az managementgroups group create --name GroupName --parent ParentId/ParentName
- name: Create 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
az managementgroups group create --name GroupName --display-name DisplayName --parent ParentId/ParentName
"""

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
- 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
- name: --parent -p
type: string
short-summary: Update the parent of the management group. A fully qualified id is required. If null, no change is made.
short-summary: Update the parent of the management group. Can be the fully qualified id or the name of the management group. 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
az managementgroups group update --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
az managementgroups group update --name GroupName --parent ParentId/ParentName
- 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
az managementgroups group update --name GroupName --display-name DisplayName --parent ParentId/ParentName
"""

helps['account management-group delete'] = """
type: command
short-summary: Remove an existing management group.
long-summary: Remove an existing management group.
short-summary: Delete an existing management group.
long-summary: Delete an existing management group.
parameters:
- name: --group-name --name -n
- name: --name -n
type: string
short-summary: Name of the management group.
examples:
- name: Remove an existing management group
- name: Delete an existing management group
text: >
az managementgroups group remove --group-name GroupName
az managementgroups group delete --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
- name: --name -n
type: string
short-summary: Name of the management group.
- name: --subscription
Expand All @@ -281,15 +281,15 @@
examples:
- name: Add a subscription to a management group.
text: >
az managementgroups group new --group-name GroupName --subscription Subscription
az managementgroups group new --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
- name: --name -n
type: string
short-summary: Name of the management group.
- name: --subscription
Expand All @@ -298,7 +298,7 @@
examples:
- name: Remove an existing subscription from a management group.
text: >
az managementgroups group remove --group-name GroupName --subscription Subscription
az managementgroups group remove --name GroupName --subscription Subscription
"""

helps['policy'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ def load_arguments(self, _):
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'])
c.argument('group_name', options_list=['--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'])
c.argument('expand', arg_type=get_three_state_flag(), options_list=['--expand', '-e'], action='store_true')
c.argument('recurse', arg_type=get_three_state_flag(), options_list=['--recurse', '-r'], action='store_true')

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'])
c.argument('parent', options_list=['--parent', '-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'])
c.argument('parent', options_list=['--parent', '-p'])
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ def _get_subscription_id_from_subscription(cli_ctx, subscription): # pylint: di
from azure.cli.core.util import CLIError
raise CLIError("Subscription not found in the current context.")

def _get_parent_id_from_parent(parent):
if parent is None or parent.startswith("/providers/Microsoft.Management/managementGroups/"):
return parent
return "/providers/Microsoft.Management/managementGroups/"+parent

def cli_managementgroups_group_list(cmd, client):
_register_rp(cmd.cli_ctx)
Expand All @@ -1127,8 +1131,9 @@ def cli_managementgroups_group_create(
client,
group_name,
display_name=None,
parent_id=None):
parent=None):
_register_rp(cmd.cli_ctx)
parent_id=_get_parent_id_from_parent(parent)
from azure.mgmt.managementgroups.models import (CreateManagementGroupRequest, CreateManagementGroupDetails, CreateParentGroupInfo)
create_parent_grp_info = CreateParentGroupInfo(id=parent_id)
create_mgmt_grp_details = CreateManagementGroupDetails(parent=create_parent_grp_info)
Expand All @@ -1139,22 +1144,23 @@ def cli_managementgroups_group_create(
def cli_managementgroups_group_update_custom_func(
instance,
display_name=None,
parent_id=None):
parent=None):
instance["display_name"] = display_name
instance["parent_id"] = parent_id
instance["parent"] = parent
return instance
Copy link
Member

Choose a reason for hiding this comment

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

If the instance is the object, these simply become instance.foo = foo. A little cleaner.



def cli_managementgroups_group_update_get():
update_parameters = {'display_name': None, 'parent_id': None}
update_parameters = {'display_name': None, 'parent': None}
return update_parameters
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating a dictionary, you could just create the PatchManagementGroupRequest object here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Thanks!



def cli_managementgroups_group_update_set(
cmd, client, group_name, parameters=None):
_register_rp(cmd.cli_ctx)
parent_id=_get_parent_id_from_parent(parameters["parent"])
from azure.mgmt.managementgroups.models import PatchManagementGroupRequest
patch_mgmt_grp_request = PatchManagementGroupRequest(display_name=parameters["display_name"], parent_id=parameters["parent_id"])
patch_mgmt_grp_request = PatchManagementGroupRequest(display_name=parameters["display_name"], parent_id=parent_id)
return client.update(group_name, patch_mgmt_grp_request)
Copy link
Member

Choose a reason for hiding this comment

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

This could be made cleaner:

def cli_managmentgroups_group_update_set(…):
   return client.update(group_name, parameters)



Expand Down
Loading