Example 10 - Osirium/vcdriver GitHub Wiki

Further management

There are a couple of methods that let you do further management. One retrieves all the existing virtual machines that the user can access:

>>> from vcdriver.vm import get_all_virtual_machines
>>> vms = get_all_virtual_machines()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Retrieving all Vcenter objects of type "<class 'pyVmomi.VmomiSupport.vim.VirtualMachine'>" ... 0:00:00.317417
>>> vms[5].name
'vm_name'
>>> vms[5].ip()
Waiting for [Get IP] ... 0:01:03.292489
'10.0.0.1'
>>> vms[5].ssh('ls', vcdriver_vm_ssh_username='admin', vcdriver_vm_ssh_password='pass')
[[email protected]] run: ls

The other method lets you empty a Vsphere folder. Be careful with this one!

>>> from vcdriver.folder import destroy_virtual_machines
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> destroy_virtual_machines('folder_name')
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Power off virtual machine "vm_name1"] ... 0:00:01.084497
Waiting for [Destroy virtual machine "vm_name1"] ... 0:00:01.081120
Waiting for [Power off virtual machine "vm_name2"] ... 0:00:01.084497
Waiting for [Destroy virtual machine "vm_name2"] ... 0:00:01.081120
Waiting for [Power off virtual machine "vm_name3"] ... 0:00:01.084497
Waiting for [Destroy virtual machine "vm_name3"] ... 0:00:01.081120