Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -408,6 +408,7 @@ def load_command_table(self, _):
g.custom_command('list-instances', 'get_instances_list')
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True)
g.custom_command('restart', 'restart_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, _):
with self.command_group('vmss', compute_vmss_sdk, operation_group='virtual_machine_scale_sets') as g:
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)
g.custom_command('get-instance-view', 'get_vmss_instance_view', table_transformer='{ProvisioningState:statuses[0].displayStatus, PowerState:statuses[1].displayStatus}')
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 @@ -4562,19 +4562,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