Created
February 13, 2012 07:11
-
-
Save grier/1814550 to your computer and use it in GitHub Desktop.
vSphere API - Snapshot.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void doSnapshot(String url, String username, String password, String vmname, String snapshotname) throws Exception | |
{ | |
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true); | |
Folder rootFolder = si.getRootFolder(); | |
VirtualMachine vm = null; | |
vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname); | |
if(vm==null) | |
{ | |
System.out.println("VM not found"); | |
return; | |
} | |
Task task = vm.createSnapshot_Task(snapshotname, "auto", false, false); | |
if(task.waitForMe()==Task.SUCCESS) | |
{ | |
System.out.println("Successfully created snapshot " + snapshotname + " on " + vmname); | |
} | |
else | |
{ | |
throw new Exception("Error creating snapshot!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment