pyvcloud.vcd.vm module

class pyvcloud.vcd.vm.VM(client, href=None, resource=None)

Bases: object

A helper class to work with Virtual Machines.

deploy(power_on=True, force_customization=False)

Deploys the vm.

Deploying the vm will allocate all resources assigned to the vm. If an attempt is made to deploy an already deployed vm, an exception will be raised.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is deploying the vm.
Return type:lxml.objectify.ObjectifiedElement
get_cpus()

Returns the number of CPUs in the vm.

Returns:number of cpus (int) and number of cores per socket (int) of the vm.
Return type:dict
get_memory()

Returns the amount of memory in MB.

Returns:amount of memory in MB.
Return type:int
get_power_state(vm_resource=None)

Returns the status of the vm.

Parameters:vm_resource (lxml.objectify.ObjectifiedElement) – object containing EntityType.VM XML data representing the vm whose power state we want to retrieve.
Returns:The status of the vm, the semantics of the value returned is captured in pyvcloud.vcd.client.VCLOUD_STATUS_MAP
Return type:int
get_resource()

Fetches the XML representation of the vm from vCD.

Will serve cached response if possible.

Returns:object containing EntityType.VM XML data representing the vm.
Return type:lxml.objectify.ObjectifiedElement
get_vc()

Returns the vCenter where this vm is located.

Returns:name of the vCenter server.
Return type:str
is_deployed(vm_resource=None)

Checks if a vm is deployed or not.

Parameters:vm_resource (lxml.objectify.ObjectifiedElement) – object containing EntityType.VM XML data representing the vm whose power state we want to check.
Returns:True if the vm is deployed else False.
Return type:bool
is_powered_off(vm_resource=None)

Checks if a vm is powered off or not.

Parameters:vm_resource (lxml.objectify.ObjectifiedElement) – object containing EntityType.VM XML data representing the vm whose power state we want to check.
Returns:True if the vm is powered off else False.
Return type:bool
is_powered_on(vm_resource=None)

Checks if a vm is powered on or not.

Parameters:vm_resource (lxml.objectify.ObjectifiedElement) – object containing EntityType.VM XML data representing the vm whose power state we want to check.
Returns:True if the vm is powered on else False.
Return type:bool
is_suspended(vm_resource=None)

Checks if a vm is suspended or not.

Parameters:vm_resource (lxml.objectify.ObjectifiedElement) – object containing EntityType.VM XML data representing the vm whose power state we want to check.
Returns:True if the vm is suspended else False.
Return type:bool
modify_cpu(virtual_quantity, cores_per_socket=None)

Updates the number of CPUs of a vm.

Parameters:
  • virtual_quantity (int) – number of virtual CPUs to configure on the vm.
  • cores_per_socket (int) – number of cores per socket.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that updates the vm.

Return type:

lxml.objectify.ObjectifiedElement

modify_memory(virtual_quantity)

Updates the memory of a vm.

Parameters:virtual_quantity (int) – number of MB of memory to configure on the vm.
Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that updates the vm.
Return type:lxml.objectify.ObjectifiedElement
power_off()

Powers off the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is powering off the vm.
Return type:lxml.objectify.ObjectifiedElement
power_on()

Powers on the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is powering on the vm.
Return type:lxml.objectify.ObjectifiedElement
power_reset()

Powers reset the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is power resetting the vm.
Return type:lxml.objectify.ObjectifiedElement
reboot()

Reboots the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task rebooting the vm.
Return type:lxml.objectify.ObjectifiedElement
reload()

Reloads the resource representation of the vm.

This method should be called in between two method invocations on the VM object, if the former call changes the representation of the vm in vCD.

shutdown()

Shutdown the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task shutting down the vm.
Return type:lxml.objectify.ObjectifiedElement
snapshot_create(memory=None, quiesce=None, name=None)

Create a snapshot of the vm.

Parameters:
  • memory (bool) – True, if the snapshot should include the virtual machine’s memory.
  • quiesce (bool) – True, if the file system of the virtual machine should be quiesced before the snapshot is created. Requires VMware tools to be installed on the vm.
  • name (str) – name of the snapshot.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is creating the snapshot.

Return type:

lxml.objectify.ObjectifiedElement

snapshot_remove_all()

Removes all user created snapshots of a virtual machine.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task removing the snapshots.
Return type:lxml.objectify.ObjectifiedElement
snapshot_revert_to_current()

Reverts a virtual machine to the current snapshot, if any.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is reverting the snapshot.
Return type:lxml.objectify.ObjectifiedElement
undeploy(action='default')

Undeploy the vm.

Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is undeploying the vm.
Return type:lxml.objectify.ObjectifiedElement