Here is the code:
public class VmDelete
{
public static void main(String[] args) throws Exception
{
ServiceInstance si = new ServiceInstance(new URL(), "user", "password", true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", "MyVmName");
Task task = vm.destroy_Task();
try{
task.waitForMe();
} catch(MethodFault mf)
{
System.out.println("The vm cannot be deleted.");
}
System.out.println("The vm has been deleted.");
si.getServerConnection().logout();
}
}
Note:
1. Change the IP and username/pass to your own.
2. Download the VI Java API binary zip which includes two jars which should be added to your classpath. No complicated installation/configuration as would with AXIS.
I am sure you can get it running in 5 minutes. Check it out http://communities.vmware.com/docs/DOC-9602
Steve JIN, VMware Engineering
Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)
Get Connected with Other Developers in the Community?
Steve JIN
Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org