ServiceInstance si = new ServiceInstance(
new URL(args[0]), args[1], args[2], true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
rootFolder).searchManagedEntity("VirtualMachine", vmname);
if(vm==null)
{
System.out.println("No VM " + vmname + " found");
si.getServerConnection().logout();
return;
}
if("create".equalsIgnoreCase(op))
{
Task task = vm.createSnapshot_Task(
snapshotname, desc, false, false);
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println("Snapshot was created.");
}
}
else if("list".equalsIgnoreCase(op))
{
listSnapshots(vm);
}
else if(op.equalsIgnoreCase("revert"))
{
VirtualMachineSnapshot vmsnap = getSnapshotInTree(
vm, snapshotname);
if(vmsnap!=null)
{
Task task = vmsnap.revertToSnapshot_Task(null);
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println("Reverted to snapshot:"
+ snapshotname);
}
}
}
else if(op.equalsIgnoreCase("removeall"))
{
Task task = vm.removeAllSnapshots_Task();
if(task.waitForMe()== Task.SUCCESS)
{
System.out.println("Removed all snapshots");
}
}