Example 4 - Osirium/vcdriver GitHub Wiki

Destroying virtual machines and power methods

Virtual machines can be destroyed easily with the idempotent destroy method.

>>> from vcdriver.vm import VirtualMachine
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> vm = VirtualMachine(name='vm_name', template='vm_template')
>>> vm.create()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Create virtual machine "vm_name" from template "vm_template"] ... 0:00:10.074632
>>> vm.destroy()
Waiting for [Power off virtual machine "vm_name"] ... 0:00:01.327433
Waiting for [Destroy virtual machine "vm_name"] ... 0:00:01.019329

There are three idempotent power methods that don't rely on Vmwaretools: power_on, power_off and reset.

>>> from vcdriver.vm import VirtualMachine
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> vm = VirtualMachine(name='vm_name', template='vm_template')
>>> vm.create()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Create virtual machine "vm_name" from template "vm_template"] ... 0:00:10.074632
>>> vm.power_off()
Waiting for [Power off virtual machine "vm_name"] ... 0:00:01.183452
>>> vm.power_on()
Waiting for [Power on virtual machine "vm_name"] ... 0:00:01.678678
>>> vm.reset()
Waiting for [Reset virtual machine "vm_name"] ... 0:00:01.345543

reboot and shutdown methods need Vmware tools. These methods are async, that is, they are not blocking, they just trigger the OS call.

>>> from vcdriver.vm import VirtualMachine
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> vm = VirtualMachine(name='vm_name', template='vm_template')
>>> vm.create()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Create virtual machine "vm_name" from template "vm_template"] ... 0:00:10.074632
>>> vm.reboot()
Waiting for [Vmware tools readiness] ... 0:00:01.884545
>>> vm.shutdown()
Waiting for [Vmware tools readiness] ... 0:00:01.137234