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
3 changes: 2 additions & 1 deletion src/command_modules/azure-cli-vm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Release History

2.2.9
++++++
* `vm extension show / wait`: deprecated --expand parameter
* `vm extension show / wait`: deprecated --expand parameter.
* `vm restart`: Added `--force` which redeploys unresponsive VMs.

2.2.8
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ def load_arguments(self, _):
c.argument('zone', options_list=['--zone', '-z'], arg_type=get_three_state_flag(), help="show all vm size supporting availability zones")
c.argument('show_all', options_list=['--all'], help="show all information including vm sizes not available under the current subscription")
c.argument('resource_type', options_list=['--resource-type', '-r'], help='resource types e.g. "availabilitySets", "snapshots", "disk", etc')

with self.argument_context('vm restart') as c:
c.argument('force', action='store_true', help='Force the VM to restart by redeploying it. Use if the VM is unresponsive.')
# endregion

# region VMSS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def load_command_table(self, _):
g.command('perform-maintenance', 'perform_maintenance', min_api='2017-03-30')
g.command('redeploy', 'redeploy', supports_no_wait=True)
g.custom_command('resize', 'resize_vm', supports_no_wait=True)
g.command('restart', 'restart', supports_no_wait=True)
g.custom_command('restart', 'restart_vm', supports_no_wait=True)
g.custom_show_command('show', 'show_vm', table_transformer=transform_vm)
g.command('start', 'start', supports_no_wait=True)
g.command('stop', 'power_off', supports_no_wait=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ def resize_vm(cmd, resource_group_name, vm_name, size, no_wait=False):
return set_vm(cmd, vm, no_wait=no_wait)


def restart_vm(cmd, resource_group_name, vm_name, no_wait=False, force=False):
client = _compute_client_factory(cmd.cli_ctx)
if force:
return sdk_no_wait(no_wait, client.virtual_machines.redeploy, resource_group_name, vm_name)
return sdk_no_wait(no_wait, client.virtual_machines.restart, resource_group_name, vm_name)


def set_vm(cmd, instance, lro_operation=None, no_wait=False):
instance.resources = None # Issue: https://github.com/Azure/autorest/issues/934
client = _compute_client_factory(cmd.cli_ctx)
Expand Down
Loading