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

AzCli support for checkpoint operations and added deleteFromHost flag for VM delete #6300

Merged
merged 10 commits into from
May 29, 2023
42 changes: 42 additions & 0 deletions src/scvmm/azext_scvmm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@
text: |-
az scvmm vm delete --subscription contoso-sub \
--resource-group contoso-rg --name contoso-avset --force

- name: Delete the VM from SCVMM
text: |-
az scvmm vm delete --subscription contoso-sub \
--resource-group contoso-rg --name contoso-avset --deleteFromHost
"""

helps[
Expand Down Expand Up @@ -684,6 +689,43 @@
--resource-group contoso-rg --name contoso-vm
"""

helps[
'scvmm vm create-checkpoint'
] = """
type: command
short-summary: Create a VM checkpoint
examples:
- name: Create VM checkpoint
text: |-
az scvmm vm create-checkpoint --subscription contoso-sub \
--resource-group contoso-rg --name contoso-vm --checkpoint-name contoso-chkpt-name \
--checkpoint-description contoso-chkpt-description
"""

helps[
'scvmm vm delete-checkpoint'
] = """
type: command
short-summary: Deletes the specified VM checkpoint
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
examples:
- name: Delete VM checkpoint
text: |-
az scvmm vm delete-checkpoint --subscription contoso-sub \
--resource-group contoso-rg --name contoso-vm --checkpoint-id checkpoint-guid
"""

helps[
'scvmm vm restore-checkpoint'
] = """
type: command
short-summary: Restores to VM checkpoint
examples:
- name: Restores VM checkpoint
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
text: |-
az scvmm vm restore-checkpoint --subscription contoso-sub \
--resource-group contoso-rg --name contoso-vm --checkpoint-id checkpoint-guid
"""

helps[
'scvmm vm update'
] = """
Expand Down
32 changes: 32 additions & 0 deletions src/scvmm/azext_scvmm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ def load_arguments(self: AzCommandsLoader, _):
help="Skip shutdown and power-off immediately.",
)

with self.argument_context('scvmm vm create-checkpoint') as c:
c.argument(
'checkpoint_name',
options_list=['--checkpoint-name'],
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
help="Name of the checkpoint to be created.",
)

c.argument(
'checkpoint_description',
options_list=['--checkpoint-description'],
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
help="Description of the checkpoint to be created.",
)

with self.argument_context('scvmm vm delete-checkpoint') as c:
c.argument(
'checkpoint_id',
options_list=['--checkpoint-id'],
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
help="Checkpoint UUID.",
)

with self.argument_context('scvmm vm restore-checkpoint') as c:
c.argument(
'checkpoint_id',
options_list=['--checkpoint-id'],
mchoubey2021 marked this conversation as resolved.
Show resolved Hide resolved
help="Checkpoint UUID.",
)

with self.argument_context('scvmm vm nic') as c:
c.argument('nic_name', options_list=['--name', '-n'], help="Name of the NIC.")
c.argument('nic_id', options_list=['--nic-id'], help="UUID of the NIC.")
Expand Down Expand Up @@ -255,6 +282,11 @@ def load_arguments(self: AzCommandsLoader, _):
action='store_true',
help='Disable the VM from azure but retain the VM in VMM.',
)
c.argument(
'deleteFromHost',
action='store_true',
help='Delete the VM from the SCVMM.',
)

with self.argument_context('scvmm avset') as c:
c.argument(
Expand Down
3 changes: 3 additions & 0 deletions src/scvmm/azext_scvmm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def load_command_table(self: AzCommandsLoader, _):
g.custom_command('start', 'start_vm', supports_no_wait=True)
g.custom_command('stop', 'stop_vm', supports_no_wait=True)
g.custom_command('restart', 'restart_vm', supports_no_wait=True)
g.custom_command('create-checkpoint', 'create_vm_checkpoint', supports_no_wait=True)
g.custom_command('delete-checkpoint', 'delete_vm_checkpoint', supports_no_wait=True)
g.custom_command('restore-checkpoint', 'restore_vm_checkpoint', supports_no_wait=True)
g.wait_command('wait')

with self.command_group(
Expand Down
48 changes: 48 additions & 0 deletions src/scvmm/azext_scvmm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
HardwareProfileUpdate,
OsProfile,
VirtualMachine,
VirtualMachineCreateCheckpoint,
VirtualMachineDeleteCheckpoint,
VirtualMachineRestoreCheckpoint,
VirtualMachineUpdate,
VirtualMachineUpdateProperties,
VirtualMachineTemplate,
Expand Down Expand Up @@ -607,6 +610,7 @@ def delete_vm(
resource_name,
retain=None,
force=None,
deleteFromHost=None,
no_wait=False,
):
return sdk_no_wait(
Expand All @@ -616,6 +620,7 @@ def delete_vm(
resource_name,
retain,
force,
deleteFromHost,
)


Expand Down Expand Up @@ -665,6 +670,49 @@ def restart_vm(
)


def create_vm_checkpoint(
cmd,
client: VirtualMachinesOperations,
resource_group_name,
resource_name,
checkpoint_name,
checkpoint_description,
no_wait=False,
):
body = VirtualMachineCreateCheckpoint(name=checkpoint_name, description=checkpoint_description)
return sdk_no_wait(
no_wait, client.begin_create_checkpoint, resource_group_name, resource_name, body
)


def delete_vm_checkpoint(
cmd,
client: VirtualMachinesOperations,
resource_group_name,
resource_name,
checkpoint_id,
no_wait=False,
):
body = VirtualMachineDeleteCheckpoint(id=checkpoint_id)
return sdk_no_wait(
no_wait, client.begin_delete_checkpoint, resource_group_name, resource_name, body
)


def restore_vm_checkpoint(
cmd,
client: VirtualMachinesOperations,
resource_group_name,
resource_name,
checkpoint_id,
no_wait=False,
):
body = VirtualMachineRestoreCheckpoint(id=checkpoint_id)
return sdk_no_wait(
no_wait, client.begin_restore_checkpoint, resource_group_name, resource_name, body
)


def get_network_interfaces(
cmd, client: VirtualMachinesOperations, resource_group_name, input_nics
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
virtual_machine_name: str,
retain: Optional[bool] = None,
force: Optional[bool] = None,
delete_from_host: Optional[bool] = None,
**kwargs: Any
) -> None:
cls = kwargs.pop('cls', None) # type: ClsType[None]
Expand All @@ -259,6 +260,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
api_version=api_version,
retain=retain,
force=force,
delete_from_host=delete_from_host,
template_url=self._delete_initial.metadata['url'],
)
request = _convert_request(request)
Expand Down Expand Up @@ -288,6 +290,7 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements
virtual_machine_name: str,
retain: Optional[bool] = None,
force: Optional[bool] = None,
delete_from_host: Optional[bool] = None,
**kwargs: Any
) -> AsyncLROPoller[None]:
"""Implements VirtualMachine DELETE method.
Expand All @@ -304,6 +307,8 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements
:param force: Forces the resource to be deleted from azure. The corresponding CR would be
attempted to be deleted too. Default value is None.
:type force: bool
:param delete_from_host: Delete the VM from SCVMM. Default value is None.
:type delete_from_host: bool
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
Expand All @@ -330,6 +335,7 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements
virtual_machine_name=virtual_machine_name,
retain=retain,
force=force,
delete_from_host=delete_from_host,
api_version=api_version,
cls=lambda x,y,z: x,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def build_delete_request_initial(
api_version = kwargs.pop('api_version', "2020-06-05-preview") # type: str
retain = kwargs.pop('retain', None) # type: Optional[bool]
force = kwargs.pop('force', None) # type: Optional[bool]
deleteFromHost = kwargs.pop('deleteFromHost', None) # type: Optional[bool]

accept = "application/json"
# Construct URL
Expand All @@ -139,6 +140,8 @@ def build_delete_request_initial(
_query_parameters['retain'] = _SERIALIZER.query("retain", retain, 'bool')
if force is not None:
_query_parameters['force'] = _SERIALIZER.query("force", force, 'bool')
if deleteFromHost is not None:
_query_parameters['deleteFromHost'] = _SERIALIZER.query("deleteFromHost", deleteFromHost, 'bool')

# Construct headers
_header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
Expand Down Expand Up @@ -714,6 +717,7 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements
virtual_machine_name, # type: str
retain=None, # type: Optional[bool]
force=None, # type: Optional[bool]
deleteFromHost=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> None
Expand All @@ -733,6 +737,7 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements
api_version=api_version,
retain=retain,
force=force,
deleteFromHost=deleteFromHost,
template_url=self._delete_initial.metadata['url'],
)
request = _convert_request(request)
Expand Down Expand Up @@ -762,6 +767,7 @@ def begin_delete( # pylint: disable=inconsistent-return-statements
virtual_machine_name, # type: str
retain=None, # type: Optional[bool]
force=None, # type: Optional[bool]
deleteFromHost=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> LROPoller[None]
Expand All @@ -779,6 +785,8 @@ def begin_delete( # pylint: disable=inconsistent-return-statements
:param force: Forces the resource to be deleted from azure. The corresponding CR would be
attempted to be deleted too. Default value is None.
:type force: bool
:param deleteFromHost: Deletes the VM from the SCVMM. Default value is None.
:type deleteFromHost: bool
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: By default, your polling method will be ARMPolling. Pass in False for this
Expand All @@ -805,6 +813,7 @@ def begin_delete( # pylint: disable=inconsistent-return-statements
virtual_machine_name=virtual_machine_name,
retain=retain,
force=force,
deleteFromHost=deleteFromHost,
api_version=api_version,
cls=lambda x,y,z: x,
**kwargs
Expand Down