use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class VirtualDiskManagerMO method eagerZeroVirtualDisk.
public void eagerZeroVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
ManagedObjectReference morTask = _context.getService().eagerZeroVirtualDisk_Task(_mor, name, morDc);
String result = _context.getServiceUtil().waitForTask(morTask);
if (!result.equals("sucess"))
throw new Exception("Unable to eager zero virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
_context.waitForTaskProgressDone(morTask);
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method relocate.
public boolean relocate(ManagedObjectReference morTargetHost) throws Exception {
VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
relocateSpec.setHost(morTargetHost);
ManagedObjectReference morTask = _context.getService().relocateVM_Task(_mor, relocateSpec, null);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware relocateVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class VmwareContext method getHostMorByPath.
public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
assert (inventoryPath != null);
String[] tokens;
if (inventoryPath.startsWith("/"))
tokens = inventoryPath.substring(1).split("/");
else
tokens = inventoryPath.split("/");
ManagedObjectReference mor = getRootFolder();
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
ObjectContent[] ocs;
if (mor.getType().equalsIgnoreCase("Datacenter")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec dcHostFolderTraversal = new TraversalSpec();
dcHostFolderTraversal.setType("Datacenter");
dcHostFolderTraversal.setPath("hostFolder");
dcHostFolderTraversal.setName("dcHostFolderTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { dcHostFolderTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else if (mor.getType().equalsIgnoreCase("Folder")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec folderChildrenTraversal = new TraversalSpec();
folderChildrenTraversal.setType("Folder");
folderChildrenTraversal.setPath("childEntity");
folderChildrenTraversal.setName("folderChildrenTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { folderChildrenTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else if (mor.getType().equalsIgnoreCase("ClusterComputeResource")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec clusterHostTraversal = new TraversalSpec();
clusterHostTraversal.setType("ClusterComputeResource");
clusterHostTraversal.setPath("host");
clusterHostTraversal.setName("folderChildrenTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { clusterHostTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else {
s_logger.error("Invalid inventory path, path element can only be datacenter and folder");
return null;
}
if (ocs != null && ocs.length > 0) {
boolean found = false;
for (ObjectContent oc : ocs) {
String name = oc.getPropSet()[0].getVal().toString();
if (name.equalsIgnoreCase(token) || name.equalsIgnoreCase("host")) {
mor = oc.getObj();
found = true;
if (name.equalsIgnoreCase("host"))
i--;
break;
}
}
if (!found) {
s_logger.error("Path element points to an un-existing inventory entity");
return null;
}
} else {
s_logger.error("Path element points to an un-existing inventory entity");
return null;
}
}
return mor;
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class BaseMO method destroy.
public boolean destroy() throws Exception {
ManagedObjectReference morTask = _context.getService().destroy_Task(_mor);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware destroy_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class BaseMO method rename.
public boolean rename(String newName) throws Exception {
ManagedObjectReference morTask = _context.getService().rename_Task(_mor, newName);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware rename_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
Aggregations