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

[Compute] az ppg create/update: Add parameter --intentvmsizes to support one or more VM sizes and --zone to support specifying availability zone where the ppg should be created #23167

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,14 @@
text: |
az ppg create --name MyProximityPlacementGroup --resource-group MyResourceGroup
crafted: true
- name: Create a proximity placement group with specifying vm sizes that can be created.
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
text: |
az ppg create --name MyProximityPlacementGroup --resource-group MyResourceGroup \\
--intentvmsizes Standard_E64s_v4 Standard_M416ms_v2
- name: Create a proximity placement group with specifying vm sizes that can be created and availability zone.
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
text: |
az ppg create --name MyProximityPlacementGroup --resource-group MyResourceGroup \\
--intentvmsizes Standard_E64s_v4 Standard_M416ms_v2 --zone 1
"""

helps['ppg list'] = """
Expand All @@ -654,6 +662,11 @@
helps['ppg update'] = """
type: command
short-summary: Update a proximity placement group
examples:
- name: Update a proximity placement group with specifying vm sizes that can be created.
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
text: |
az ppg update --name MyProximityPlacementGroup --resource-group MyResourceGroup \\
--intentvmsizes Standard_E64s_v4 Standard_M416ms_v2
"""

helps['sig'] = """
Expand Down
7 changes: 7 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,13 @@ def load_arguments(self, _):
c.argument('ppg_type', options_list=['--type', '-t'], help="The type of the proximity placement group. Allowed values: Standard.")
c.argument('tags', tags_type)

with self.argument_context('ppg create', min_api='2021-11-01') as c:
c.argument('zone', nargs='*', help="Specifies the availability zone where virtual machine, virtual machine scale set or availability set associated with the proximity placement group can be created. Accepted values 1,2,3.")
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved

for scope in ['ppg create', 'ppg update']:
with self.argument_context(scope, min_api='2021-11-01') as c:
c.argument('intentvmsizes', nargs='*', help="Specifies possible sizes of virtual machines that can be created in the proximity placement group.")
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved

with self.argument_context('ppg show', min_api='2019-07-01') as c:
c.argument('include_colocation_status', action='store_true', help='Enable fetching the colocation status of all the resources in the proximity placement group.')

Expand Down
10 changes: 10 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,16 @@ def _disk_encryption_set_format(cmd, namespace, name):
# endregion


def process_ppg_create_namespace(namespace):
"""
The availability zone can be provided only when an intent is provided
"""
if namespace.zone and not namespace.intentvmsizes:
raise RequiredArgumentMissingError('Please use parameter --intentvmsizes to specify possible sizes of virtual '
'machines that can be created in the proximity placement group.')
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
# endregion


def process_image_version_create_namespace(cmd, namespace):
process_gallery_image_version_namespace(cmd, namespace)
process_image_resource_id_namespace(namespace)
Expand Down
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
process_disk_encryption_namespace, process_assign_identity_namespace,
process_remove_identity_namespace, process_vm_secret_format, process_vm_vmss_stop, validate_vmss_update_namespace,
process_vm_update_namespace, process_set_applications_namespace, process_vm_disk_attach_namespace,
process_image_version_create_namespace, process_image_version_update_namespace)
process_image_version_create_namespace, process_image_version_update_namespace, process_ppg_create_namespace)

from azure.cli.command_modules.vm._image_builder import (
process_image_template_create_namespace, process_img_tmpl_output_add_namespace,
Expand Down Expand Up @@ -641,9 +641,9 @@ def load_command_table(self, _):

with self.command_group('ppg', compute_proximity_placement_groups_sdk, min_api='2018-04-01', client_factory=cf_proximity_placement_groups) as g:
g.show_command('show', 'get')
g.custom_command('create', 'create_proximity_placement_group')
g.custom_command('create', 'create_proximity_placement_group', validator=process_ppg_create_namespace)
g.custom_command('list', 'list_proximity_placement_groups')
g.generic_update_command('update')
g.generic_update_command('update', setter_name='create_or_update', custom_func_name='update_ppg')
g.command('delete', 'delete')

with self.command_group('vm monitor log', client_factory=cf_log_analytics_data_plane) as g:
Expand Down
17 changes: 15 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4496,7 +4496,7 @@ def update_image_version(cmd, resource_group_name, gallery_name, gallery_image_n

# region proximity placement groups
def create_proximity_placement_group(cmd, client, proximity_placement_group_name, resource_group_name,
ppg_type=None, location=None, tags=None):
ppg_type=None, location=None, tags=None, zone=None, intentvmsizes=None):
from knack.arguments import CaseInsensitiveList

location = location or _get_resource_group_location(cmd.cli_ctx, resource_group_name)
Expand All @@ -4509,12 +4509,25 @@ def create_proximity_placement_group(cmd, client, proximity_placement_group_name
raise CLIError("Usage error: invalid value for --type/-t")

ppg_params = ProximityPlacementGroup(name=proximity_placement_group_name, proximity_placement_group_type=ppg_type,
location=location, tags=(tags or {}))
location=location, tags=(tags or {}), zones=zone)

if intentvmsizes:
Intent = cmd.get_models('ProximityPlacementGroupPropertiesIntent')
intent = Intent(vm_sizes=intentvmsizes)
ppg_params.intent = intent

return client.create_or_update(resource_group_name=resource_group_name,
proximity_placement_group_name=proximity_placement_group_name, parameters=ppg_params)


def update_ppg(cmd, instance, intentvmsizes=None):
if intentvmsizes:
Intent = cmd.get_models('ProximityPlacementGroupPropertiesIntent')
intent = Intent(vm_sizes=intentvmsizes)
instance.intent = intent
return instance


def list_proximity_placement_groups(client, resource_group_name=None):
if resource_group_name:
return client.list_by_resource_group(resource_group_name=resource_group_name)
Expand Down
Loading