To run the code, the user must have “VirtualMachine.Inventory.Delete” privilege on the virtual machine object. For other types of objects, the required privileges are different even though the method called is exactly the same. For the data center, for example, it’s “Datacenter.Delete.” You can check out the full table in the API reference.

Using destroy_Task() method can be a dangerous because it deletes everything of a VM, which cannot be reversed. If you call the method by mistake, then you’re screwed.

To play safe, you have another method to call: unregisterVM() method defined in VirtualMachine. When it’s called, the virtual machine disappears from the inventory tree, but all the files are still there. If you regret what you just called, you can add the virtual machine any time by calling the registerVM_Task() defined in Folder managed object.

The downside of this approach is you haven’t really released the disk space. If you have many of such virtual machines, you may find your data store out of space easily. To deal with it, you can run a script that scan for unregistered VM and remove them once in a while.

In the end, I have a fun question for you: what happens if you call destroy_Task() on a HostSystem? Will it destroy your ESX or ESXi?

For the last question:
I think, disabling HostSystem.config.service.service[“DCUI”] and HostSystem.enterLockdownMode() will do the job if you loose the connection between vCenter and ESXi permanently
Cheers,
Joerg

NEED HELP?

My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.