Skip to content

Commit a607920

Browse files
william051200nddq
authored andcommitted
{Compute} az vmss scale: Migrate command to aaz-based implementation (Azure#32795)
1 parent 438e45f commit a607920

File tree

6 files changed

+1380
-1211
lines changed

6 files changed

+1380
-1211
lines changed

src/azure-cli/azure/cli/command_modules/vm/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def load_command_table(self, _):
408408
g.custom_command('list-instances', 'get_instances_list')
409409
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True)
410410
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
411+
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
411412

412413
with self.command_group('vmss application', operation_group='virtual_machine_scale_sets') as g:
413414
g.custom_command('set', 'set_vmss_applications', validator=process_set_applications_namespace)
@@ -416,7 +417,6 @@ def load_command_table(self, _):
416417
with self.command_group('vmss', compute_vmss_sdk, operation_group='virtual_machine_scale_sets') as g:
417418
g.custom_command('create', 'create_vmss', transform=DeploymentOutputLongRunningOperation(self.cli_ctx, 'Starting vmss create'), supports_no_wait=True, table_transformer=deployment_validate_table_format, validator=process_vmss_create_namespace, exception_handler=handle_template_based_exception)
418419
g.custom_command('get-instance-view', 'get_vmss_instance_view', table_transformer='{ProvisioningState:statuses[0].displayStatus, PowerState:statuses[1].displayStatus}')
419-
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
420420
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
421421
g.custom_command('stop', 'stop_vmss', supports_no_wait=True, validator=process_vm_vmss_stop)
422422
g.generic_update_command('update', getter_name='get_vmss_modified_by_aaz', setter_name='update_vmss', supports_no_wait=True, command_type=compute_custom, validator=validate_vmss_update_namespace)

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,19 +4562,34 @@ def restart_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None,
45624562

45634563
# pylint: disable=inconsistent-return-statements
45644564
def scale_vmss(cmd, resource_group_name, vm_scale_set_name, new_capacity, no_wait=False):
4565-
VirtualMachineScaleSet = cmd.get_models('VirtualMachineScaleSet')
4566-
client = _compute_client_factory(cmd.cli_ctx)
4567-
vmss = client.virtual_machine_scale_sets.get(resource_group_name, vm_scale_set_name)
4568-
# pylint: disable=no-member
4569-
if vmss.sku.capacity == new_capacity:
4565+
from .operations.vmss import VMSSCreate, VMSSShow
4566+
vmss = VMSSShow(cli_ctx=cmd.cli_ctx)(command_args={
4567+
'resource_group': resource_group_name,
4568+
'vm_scale_set_name': vm_scale_set_name
4569+
})
4570+
if vmss.get('sku', {}).get('capacity') == new_capacity:
45704571
return
45714572

4572-
vmss.sku.capacity = new_capacity
4573-
vmss_new = VirtualMachineScaleSet(location=vmss.location, sku=vmss.sku)
4574-
if vmss.extended_location is not None:
4575-
vmss_new.extended_location = vmss.extended_location
4576-
return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_create_or_update,
4577-
resource_group_name, vm_scale_set_name, vmss_new)
4573+
vmss_new = {
4574+
'resource_group': resource_group_name,
4575+
'vm_scale_set_name': vm_scale_set_name,
4576+
'no_wait': no_wait
4577+
}
4578+
4579+
if vmss.get('extended_location'):
4580+
vmss_new['extended_location'] = vmss['extendedLocation']
4581+
4582+
if vmss.get('location'):
4583+
vmss_new['location'] = vmss['location']
4584+
4585+
if vmss.get('sku'):
4586+
vmss_new['sku'] = vmss['sku']
4587+
else:
4588+
vmss_new['sku'] = {}
4589+
4590+
vmss_new['sku']['capacity'] = new_capacity
4591+
4592+
return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss_new)
45784593

45794594

45804595
def stop_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None, no_wait=False, skip_shutdown=False):

0 commit comments

Comments
 (0)