diff --git a/src/vmm_mad/vmware/DeployVM.java b/src/vmm_mad/vmware/DeployVM.java index 45ae9c7e66..dda349eab2 100644 --- a/src/vmm_mad/vmware/DeployVM.java +++ b/src/vmm_mad/vmware/DeployVM.java @@ -39,9 +39,10 @@ public class DeployVM static AppUtil cb = null; private static VimPortType service; - private String datacenterName =""; - private String datastoreName =""; - private String vmName =""; + private String datacenterName = ""; + private String datastoreName = ""; + private String vmName = ""; + private String vmDiskName = ""; ParseXML pXML; @@ -111,7 +112,7 @@ public class DeployVM if(hostFound) { - String vmxPath = "[" + getDataStoreName() + "]"+getVmName()+"/"+getVmName()+".vmx"; + String vmxPath = "[" + getDataStoreName() + "]"+getDiskName()+"/"+getDiskName()+".vmx"; // Resource Pool ManagedObjectReference resourcePool = cb.getServiceUtil().getFirstDecendentMoRef(null, "ResourcePool"); @@ -149,6 +150,15 @@ public class DeployVM { return vmName; } + + /** + * Gets the name of the VMX file and folder + * @returns name of the VMX file and folder + */ + private String getDiskName() + { + return vmDiskName; + } /** @@ -382,22 +392,71 @@ public class DeployVM } */ - DeployVM(AppUtil _cb, String hostName, ParseXML _pXML) throws Exception + DeployVM(String[] args, String hostName, ParseXML _pXML) throws Exception { - cb = _cb; + + String[] argsWithHost = new String[args.length+2]; + + for(int i=0;i 0) + { + ObjectContent snapobj = snaps[0]; + DynamicProperty[] snapary = snapobj.getPropSet(); + if (snapary != null && snapary.length > 0) + { + snapInfo = ((VirtualMachineSnapshotInfo)(snapary[0]).getVal()); + } + } + else + { + throw new Exception("No Snapshots found for VirtualMachine : " + vmName); + } + + VirtualMachineSnapshotTree[] snapTree = snapInfo.getRootSnapshotList(); + + if (snapTree == null) + { + throw new Exception("No Snapshots Tree found for VirtualMachine : " + vmName); + } + + snapmor = traverseSnapshotInTree(snapTree, checkpointName); + + if (snapmor == null) + { + throw new Exception("No Snapshot named " + checkpointName + + " found for VirtualMachine : " + vmName); + } + + ManagedObjectReference taskMor + = cb.getConnection().getService().revertToSnapshot_Task(snapmor,null); + String res = cb.getServiceUtil().waitForTask(taskMor); + + if(!res.equalsIgnoreCase("sucess")) // sic + { + throw new Exception("Unknown problem while creating the snapshot."); + } + + return true; + } + catch(Exception e) + { + System.out.println("Error checkpointing VirtualMachine [" + vmName + "]. Reason:" + e.getMessage()); + return false; + } + } + + private ManagedObjectReference traverseSnapshotInTree( + VirtualMachineSnapshotTree[] snapTree, + String checkpointName) + { + ManagedObjectReference snapmor = null; + if (snapTree == null) + { + return snapmor; + } + + for (int i = 0; i < snapTree.length && snapmor == null; i++) + { + VirtualMachineSnapshotTree node = snapTree[i]; + if ( checkpointName != null && node.getName().equals(checkpointName) ) + { + snapmor = node.getSnapshot(); + } + else + { + VirtualMachineSnapshotTree[] childTree = node.getChildSnapshotList(); + snapmor = traverseSnapshotInTree(childTree, checkpointName); + } + } + + return snapmor; + } + + + OperationsOverVM(String[] args, String hostName) throws Exception + { + String[] argsWithHost = new String[args.length+2]; + + for(int i=0;i