Skip to content
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def load_command_table(self, _):
g.custom_show_command('identity show', 'show_vmss_identity')
g.custom_command('deallocate', 'deallocate_vmss', supports_no_wait=True)
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True)
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)

with self.command_group('vmss application', operation_group='virtual_machine_scale_sets') as g:
g.custom_command('set', 'set_vmss_applications', validator=process_set_applications_namespace)
Expand All @@ -416,7 +417,6 @@ def load_command_table(self, _):
g.custom_command('list-instance-public-ips', 'list_vmss_instance_public_ips')
g.custom_command('list-instances', 'get_instances_list')
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
g.custom_command('stop', 'stop_vmss', supports_no_wait=True, validator=process_vm_vmss_stop)
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)
Expand Down
37 changes: 26 additions & 11 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4550,19 +4550,34 @@ def restart_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None,

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

vmss.sku.capacity = new_capacity
vmss_new = VirtualMachineScaleSet(location=vmss.location, sku=vmss.sku)
if vmss.extended_location is not None:
vmss_new.extended_location = vmss.extended_location
return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_create_or_update,
resource_group_name, vm_scale_set_name, vmss_new)
vmss_new = {
'resource_group': resource_group_name,
'vm_scale_set_name': vm_scale_set_name,
'no_wait': no_wait
}

if vmss.get('extended_location'):
vmss_new['extended_location'] = vmss['extendedLocation']

if vmss.get('location'):
vmss_new['location'] = vmss['location']

if vmss.get('sku'):
vmss_new['sku'] = vmss['sku']
else:
vmss_new['sku'] = {}

vmss_new['sku']['capacity'] = new_capacity

return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss_new)


def stop_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None, no_wait=False, skip_shutdown=False):
Expand Down
Loading