VirtualMachinesOperations Class
Warning
DO NOT instantiate this class directly.
Instead, you should access the following operations through
<xref:virtual_machines> attribute.
Constructor
VirtualMachinesOperations(*args, **kwargs)
Methods
| begin_assess_patches |
Assess patches on the VM. |
| begin_attach_detach_data_disks |
Attach and detach data disks to/from the virtual machine. |
| begin_capture |
Captures the VM by copying virtual hard disks of the VM and outputs a template that can be used to create similar VMs. |
| begin_convert_to_managed_disks |
Converts virtual machine disks from blob-based to managed disks. Virtual machine must be stop-deallocated before invoking this operation. |
| begin_create_or_update |
The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation. |
| begin_deallocate |
Shuts down the virtual machine and releases the compute resources. You are not billed for the compute resources that this virtual machine uses. |
| begin_delete |
The operation to delete a virtual machine. |
| begin_install_patches |
Installs patches on the VM. |
| begin_migrate_to_vm_scale_set |
Migrate a virtual machine from availability set to Flexible Virtual Machine Scale Set. |
| begin_perform_maintenance |
The operation to perform maintenance on a virtual machine. |
| begin_power_off |
The operation to power off (stop) a virtual machine. The virtual machine can be restarted with the same provisioned resources. You are still charged for this virtual machine. |
| begin_reapply |
The operation to reapply a virtual machine's state. |
| begin_redeploy |
Shuts down the virtual machine, moves it to a new node, and powers it back on. |
| begin_reimage |
Reimages (upgrade the operating system) a virtual machine which don't have a ephemeral OS disk, for virtual machines who have a ephemeral OS disk the virtual machine is reset to initial state. NOTE: The retaining of old OS disk depends on the value of deleteOption of OS disk. If deleteOption is detach, the old OS disk will be preserved after reimage. If deleteOption is delete, the old OS disk will be deleted after reimage. The deleteOption of the OS disk should be updated accordingly before performing the reimage. |
| begin_restart |
The operation to restart a virtual machine. |
| begin_run_command |
Run command on the VM. |
| begin_start |
The operation to start a virtual machine. |
| begin_update |
The operation to update a virtual machine. |
| generalize |
Sets the OS state of the virtual machine to generalized. It is recommended to sysprep the virtual machine before performing this operation. For Windows, please refer to Create a managed image of a generalized VM in Azure. For Linux, please refer to How to create an image of a virtual machine or VHD. |
| get |
Retrieves information about the model view or the instance view of a virtual machine. |
| instance_view |
Retrieves information about the run-time state of a virtual machine. |
| list |
Lists all of the virtual machines in the specified resource group. Use the nextLink property in the response to get the next page of virtual machines. |
| list_all |
Lists all of the virtual machines in the specified subscription. Use the nextLink property in the response to get the next page of virtual machines. |
| list_available_sizes |
Lists all available virtual machine sizes to which the specified virtual machine can be resized. |
| list_by_location |
Gets all the virtual machines under the specified subscription for the specified location. |
| retrieve_boot_diagnostics_data |
The operation to retrieve SAS URIs for a virtual machine's boot diagnostic logs. |
| simulate_eviction |
The operation to simulate the eviction of spot virtual machine. |
begin_assess_patches
Assess patches on the VM.
begin_assess_patches(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[VirtualMachineAssessPatchesResult]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns VirtualMachineAssessPatchesResult. The VirtualMachineAssessPatchesResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_attach_detach_data_disks
Attach and detach data disks to/from the virtual machine.
begin_attach_detach_data_disks(resource_group_name: str, vm_name: str, parameters: _models.AttachDetachDataDisksRequest, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[_models.StorageProfile]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
Required
|
Parameters supplied to the attach and detach data disks operation on the virtual machine. Is one of the following types: AttachDetachDataDisksRequest, JSON, IO[bytes] Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns StorageProfile. The StorageProfile is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_capture
Captures the VM by copying virtual hard disks of the VM and outputs a template that can be used to create similar VMs.
begin_capture(resource_group_name: str, vm_name: str, parameters: _models.VirtualMachineCaptureParameters, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[_models.VirtualMachineCaptureResult]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
Required
|
Parameters supplied to the Capture Virtual Machine operation. Is one of the following types: VirtualMachineCaptureParameters, JSON, IO[bytes] Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns VirtualMachineCaptureResult. The VirtualMachineCaptureResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_convert_to_managed_disks
Converts virtual machine disks from blob-based to managed disks. Virtual machine must be stop-deallocated before invoking this operation.
begin_convert_to_managed_disks(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_create_or_update
The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
begin_create_or_update(resource_group_name: str, vm_name: str, parameters: _models.VirtualMachine, *, content_type: str = 'application/json', etag: str | None = None, match_condition: MatchConditions | None = None, **kwargs: Any) -> LROPoller[_models.VirtualMachine]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
Required
|
Parameters supplied to the Create Virtual Machine operation. Is one of the following types: VirtualMachine, JSON, IO[bytes] Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
etag
|
check if resource is changed. Set None to skip checking etag. Default value is None. Default value: None
|
|
match_condition
|
The match condition to use upon the etag. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns VirtualMachine. The VirtualMachine is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_deallocate
Shuts down the virtual machine and releases the compute resources. You are not billed for the compute resources that this virtual machine uses.
begin_deallocate(resource_group_name: str, vm_name: str, *, hibernate: bool | None = None, force_deallocate: bool | None = None, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
hibernate
|
Optional parameter to hibernate a virtual machine. Default value is None. Default value: None
|
|
force_deallocate
|
Optional parameter to force deallocate a virtual machine. Default is false. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_delete
The operation to delete a virtual machine.
begin_delete(resource_group_name: str, vm_name: str, *, force_deletion: bool | None = None, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
force_deletion
|
Optional parameter to force delete virtual machines. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_install_patches
Installs patches on the VM.
begin_install_patches(resource_group_name: str, vm_name: str, install_patches_input: _models.VirtualMachineInstallPatchesParameters, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[_models.VirtualMachineInstallPatchesResult]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
install_patches_input
Required
|
Input for InstallPatches as directly received by the API. Is one of the following types: VirtualMachineInstallPatchesParameters, JSON, IO[bytes] Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns VirtualMachineInstallPatchesResult. The VirtualMachineInstallPatchesResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_migrate_to_vm_scale_set
Migrate a virtual machine from availability set to Flexible Virtual Machine Scale Set.
begin_migrate_to_vm_scale_set(resource_group_name: str, vm_name: str, parameters: _models.MigrateVMToVirtualMachineScaleSetInput | None = None, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
|
Parameters supplied to the Migrate Virtual Machine operation. Is one of the following types: MigrateVMToVirtualMachineScaleSetInput, JSON, IO[bytes] Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_perform_maintenance
The operation to perform maintenance on a virtual machine.
begin_perform_maintenance(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_power_off
The operation to power off (stop) a virtual machine. The virtual machine can be restarted with the same provisioned resources. You are still charged for this virtual machine.
begin_power_off(resource_group_name: str, vm_name: str, *, skip_shutdown: bool | None = None, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
skip_shutdown
|
The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_reapply
The operation to reapply a virtual machine's state.
begin_reapply(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_redeploy
Shuts down the virtual machine, moves it to a new node, and powers it back on.
begin_redeploy(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_reimage
Reimages (upgrade the operating system) a virtual machine which don't have a ephemeral OS disk, for virtual machines who have a ephemeral OS disk the virtual machine is reset to initial state. NOTE: The retaining of old OS disk depends on the value of deleteOption of OS disk. If deleteOption is detach, the old OS disk will be preserved after reimage. If deleteOption is delete, the old OS disk will be deleted after reimage. The deleteOption of the OS disk should be updated accordingly before performing the reimage.
begin_reimage(resource_group_name: str, vm_name: str, parameters: _models.VirtualMachineReimageParameters | None = None, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
|
Parameters supplied to the Reimage Virtual Machine operation. Is one of the following types: VirtualMachineReimageParameters, JSON, IO[bytes] Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_restart
The operation to restart a virtual machine.
begin_restart(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_run_command
Run command on the VM.
begin_run_command(resource_group_name: str, vm_name: str, parameters: _models.RunCommandInput, *, content_type: str = 'application/json', **kwargs: Any) -> LROPoller[_models.RunCommandResult]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
Required
|
Parameters supplied to the Run command operation. Is one of the following types: RunCommandInput, JSON, IO[bytes] Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns RunCommandResult. The RunCommandResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
begin_start
The operation to start a virtual machine.
begin_start(resource_group_name: str, vm_name: str, **kwargs: Any) -> LROPoller[None]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns None |
Exceptions
| Type | Description |
|---|---|
begin_update
The operation to update a virtual machine.
begin_update(resource_group_name: str, vm_name: str, parameters: _models.VirtualMachineUpdate, *, content_type: str = 'application/json', etag: str | None = None, match_condition: MatchConditions | None = None, **kwargs: Any) -> LROPoller[_models.VirtualMachine]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
|
parameters
Required
|
Parameters supplied to the Update Virtual Machine operation. Is one of the following types: VirtualMachineUpdate, JSON, IO[bytes] Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
etag
|
check if resource is changed. Set None to skip checking etag. Default value is None. Default value: None
|
|
match_condition
|
The match condition to use upon the etag. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An instance of LROPoller that returns VirtualMachine. The VirtualMachine is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
generalize
Sets the OS state of the virtual machine to generalized. It is recommended to sysprep the virtual machine before performing this operation. For Windows, please refer to Create a managed image of a generalized VM in Azure. For Linux, please refer to How to create an image of a virtual machine or VHD.
generalize(resource_group_name: str, vm_name: str, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|
get
Retrieves information about the model view or the instance view of a virtual machine.
get(resource_group_name: str, vm_name: str, *, expand: str | InstanceViewTypes | None = None, **kwargs: Any) -> VirtualMachine
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
expand
|
The expand expression to apply on the operation. 'InstanceView' retrieves a snapshot of the runtime properties of the virtual machine that is managed by the platform and can change outside of control plane operations. 'UserData' retrieves the UserData property as part of the VM model view that was provided by the user during the VM Create/Update operation. Known values are: "instanceView", "userData", and "resiliencyView". Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
VirtualMachine. The VirtualMachine is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
instance_view
Retrieves information about the run-time state of a virtual machine.
instance_view(resource_group_name: str, vm_name: str, **kwargs: Any) -> VirtualMachineInstanceView
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
VirtualMachineInstanceView. The VirtualMachineInstanceView is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
list
Lists all of the virtual machines in the specified resource group. Use the nextLink property in the response to get the next page of virtual machines.
list(resource_group_name: str, *, filter: str | None = None, expand: str | ExpandTypeForListVMs | None = None, **kwargs: Any) -> ItemPaged[VirtualMachine]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
filter
|
The system query option to filter VMs returned in the response. Allowed value is 'virtualMachineScaleSet/id' eq /subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}'. Default value is None. Default value: None
|
|
expand
|
The expand expression to apply on operation. 'instanceView' enables fetching run time status of all Virtual Machines, this can only be specified if a valid $filter option is specified. "instanceView" Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of VirtualMachine |
Exceptions
| Type | Description |
|---|---|
list_all
Lists all of the virtual machines in the specified subscription. Use the nextLink property in the response to get the next page of virtual machines.
list_all(*, status_only: str | None = None, filter: str | None = None, expand: str | ExpandTypesForListVMs | None = None, **kwargs: Any) -> ItemPaged[VirtualMachine]
Keyword-Only Parameters
| Name | Description |
|---|---|
|
status_only
|
statusOnly=true enables fetching run time status of all Virtual Machines in the subscription. Default value is None. Default value: None
|
|
filter
|
The system query option to filter VMs returned in the response. Allowed value is 'virtualMachineScaleSet/id' eq /subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}'. Default value is None. Default value: None
|
|
expand
|
The expand expression to apply on operation. 'instanceView' enables fetching run time status of all Virtual Machines, this can only be specified if a valid $filter option is specified. "instanceView" Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of VirtualMachine |
Exceptions
| Type | Description |
|---|---|
list_available_sizes
Lists all available virtual machine sizes to which the specified virtual machine can be resized.
list_available_sizes(resource_group_name: str, vm_name: str, **kwargs: Any) -> ItemPaged[VirtualMachineSize]
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
An iterator like instance of VirtualMachineSize |
Exceptions
| Type | Description |
|---|---|
list_by_location
Gets all the virtual machines under the specified subscription for the specified location.
list_by_location(location: str, **kwargs: Any) -> ItemPaged[VirtualMachine]
Parameters
| Name | Description |
|---|---|
|
location
Required
|
The location name. Required. |
Returns
| Type | Description |
|---|---|
|
An iterator like instance of VirtualMachine |
Exceptions
| Type | Description |
|---|---|
retrieve_boot_diagnostics_data
The operation to retrieve SAS URIs for a virtual machine's boot diagnostic logs.
retrieve_boot_diagnostics_data(resource_group_name: str, vm_name: str, *, sas_uri_expiration_time_in_minutes: int | None = None, **kwargs: Any) -> RetrieveBootDiagnosticsDataResult
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
sas_uri_expiration_time_in_minutes
|
Expiration duration in minutes for the SAS URIs with a value between 1 to 1440 minutes. Note: If not specified, SAS URIs will be generated with a default expiration duration of 120 minutes. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
RetrieveBootDiagnosticsDataResult. The RetrieveBootDiagnosticsDataResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
simulate_eviction
The operation to simulate the eviction of spot virtual machine.
simulate_eviction(resource_group_name: str, vm_name: str, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
resource_group_name
Required
|
The name of the resource group. The name is case insensitive. Required. |
|
vm_name
Required
|
The name of the virtual machine. Required. |
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|