Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to delete a guest vm using the pyvmomi API?

I've been pouring through the documents and example for the official VMWare pyvmomi API and for the life of me I cannot find an obvious way to just nuke a VM off of an ESXi server.

Can anyone provide an example or point me to someone who has implmented this already - it seems like the only alternative is to roll something myself that would

  • Shutdown the VM
  • Unregister it
  • Delete the VM
  • Delete the disks that were associated with the VM?

I think each part is there but I really hope someone could point me in the right direction.

like image 456
synthesizerpatel Avatar asked Sep 29 '22 04:09

synthesizerpatel


1 Answers

I will be glad to help with this. First off you are correct in that you have to do the steps. They would be locate the VM, next power it off, and finally destroy the VM. The destroy task will remove the files and remove from inventory.

I have created a sample script to show you what to do. This has been tested in 4.1, 5.0, and 5.5 vSphere. https://github.com/virtdevninja/pyvmomi-community-samples/blob/master/samples/destroy_vm.py

like image 188
Michael Rice Avatar answered Oct 11 '22 12:10

Michael Rice