use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class HostDatastoreSystemMO method getStorageTraversalSpec.
private SelectionSpec[] getStorageTraversalSpec() {
// create a traversal spec that start from root folder
SelectionSpec ssFolders = new SelectionSpec();
ssFolders.setName("visitFolders");
TraversalSpec datacenterSpec = new TraversalSpec();
datacenterSpec.setName("dcTodf");
datacenterSpec.setType("Datacenter");
datacenterSpec.setPath("datastoreFolder");
datacenterSpec.setSkip(Boolean.FALSE);
datacenterSpec.getSelectSet().add(ssFolders);
TraversalSpec visitFolder = new TraversalSpec();
visitFolder.setType("Folder");
visitFolder.setName("visitFolders");
visitFolder.setPath("childEntity");
visitFolder.setSkip(Boolean.FALSE);
List<SelectionSpec> ssSpecList = new ArrayList<SelectionSpec>();
ssSpecList.add(datacenterSpec);
ssSpecList.add(ssFolders);
visitFolder.getSelectSet().addAll(ssSpecList);
return (new SelectionSpec[] { visitFolder });
}
use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class VmwareClient method getDecendentMoRef.
/**
* Get the ManagedObjectReference for an item under the
* specified root folder that has the type and name specified.
*
* @param root a root folder if available, or null for default
* @param type type of the managed object
* @param name name to match
*
* @return First ManagedObjectReference of the type / name pair found
*/
public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, String type, String name) throws Exception {
if (name == null || name.length() == 0) {
return null;
}
try {
// Create PropertySpecs
PropertySpec pSpec = new PropertySpec();
pSpec.setType(type);
pSpec.setAll(false);
pSpec.getPathSet().add("name");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(root);
oSpec.setSkip(false);
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
PropertyFilterSpec spec = new PropertyFilterSpec();
spec.getPropSet().add(pSpec);
spec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
specArr.add(spec);
ManagedObjectReference propCollector = getPropCol();
List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr);
if (ocary == null || ocary.size() == 0) {
return null;
}
// filter through retrieved objects to get the first match.
for (ObjectContent oc : ocary) {
ManagedObjectReference mor = oc.getObj();
List<DynamicProperty> propary = oc.getPropSet();
if (type == null || type.equals(mor.getType())) {
if (propary.size() > 0) {
String propval = (String) propary.get(0).getVal();
if (propval != null && name.equalsIgnoreCase(propval))
return mor;
}
}
}
} catch (InvalidPropertyFaultMsg invalidPropertyException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage());
throw invalidPropertyException;
} catch (RuntimeFaultFaultMsg runtimeFaultException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage());
throw runtimeFaultException;
}
return null;
}
use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class VmwareClient method constructCompleteTraversalSpec.
/*
* @return An array of SelectionSpec covering VM, Host, Resource pool,
* Cluster Compute Resource and Datastore.
*/
private List<SelectionSpec> constructCompleteTraversalSpec() {
// ResourcePools to VM: RP -> VM
TraversalSpec rpToVm = new TraversalSpec();
rpToVm.setName("rpToVm");
rpToVm.setType("ResourcePool");
rpToVm.setPath("vm");
rpToVm.setSkip(Boolean.FALSE);
// VirtualApp to VM: vApp -> VM
TraversalSpec vAppToVM = new TraversalSpec();
vAppToVM.setName("vAppToVM");
vAppToVM.setType("VirtualApp");
vAppToVM.setPath("vm");
// Host to VM: HostSystem -> VM
TraversalSpec hToVm = new TraversalSpec();
hToVm.setType("HostSystem");
hToVm.setPath("vm");
hToVm.setName("hToVm");
hToVm.getSelectSet().add(getSelectionSpec("VisitFolders"));
hToVm.setSkip(Boolean.FALSE);
// DataCenter to DataStore: DC -> DS
TraversalSpec dcToDs = new TraversalSpec();
dcToDs.setType("Datacenter");
dcToDs.setPath("datastore");
dcToDs.setName("dcToDs");
dcToDs.setSkip(Boolean.FALSE);
// Recurse through all ResourcePools
TraversalSpec rpToRp = new TraversalSpec();
rpToRp.setType("ResourcePool");
rpToRp.setPath("resourcePool");
rpToRp.setSkip(Boolean.FALSE);
rpToRp.setName("rpToRp");
rpToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToRp = new TraversalSpec();
crToRp.setType("ComputeResource");
crToRp.setPath("resourcePool");
crToRp.setSkip(Boolean.FALSE);
crToRp.setName("crToRp");
crToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToH = new TraversalSpec();
crToH.setSkip(Boolean.FALSE);
crToH.setType("ComputeResource");
crToH.setPath("host");
crToH.setName("crToH");
TraversalSpec dcToHf = new TraversalSpec();
dcToHf.setSkip(Boolean.FALSE);
dcToHf.setType("Datacenter");
dcToHf.setPath("hostFolder");
dcToHf.setName("dcToHf");
dcToHf.getSelectSet().add(getSelectionSpec("VisitFolders"));
TraversalSpec vAppToRp = new TraversalSpec();
vAppToRp.setName("vAppToRp");
vAppToRp.setType("VirtualApp");
vAppToRp.setPath("resourcePool");
vAppToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec dcToVmf = new TraversalSpec();
dcToVmf.setType("Datacenter");
dcToVmf.setSkip(Boolean.FALSE);
dcToVmf.setPath("vmFolder");
dcToVmf.setName("dcToVmf");
dcToVmf.getSelectSet().add(getSelectionSpec("VisitFolders"));
// For Folder -> Folder recursion
TraversalSpec visitFolders = new TraversalSpec();
visitFolders.setType("Folder");
visitFolders.setPath("childEntity");
visitFolders.setSkip(Boolean.FALSE);
visitFolders.setName("VisitFolders");
List<SelectionSpec> sspecarrvf = new ArrayList<SelectionSpec>();
sspecarrvf.add(getSelectionSpec("crToRp"));
sspecarrvf.add(getSelectionSpec("crToH"));
sspecarrvf.add(getSelectionSpec("dcToVmf"));
sspecarrvf.add(getSelectionSpec("dcToHf"));
sspecarrvf.add(getSelectionSpec("vAppToRp"));
sspecarrvf.add(getSelectionSpec("vAppToVM"));
sspecarrvf.add(getSelectionSpec("dcToDs"));
sspecarrvf.add(getSelectionSpec("hToVm"));
sspecarrvf.add(getSelectionSpec("rpToVm"));
sspecarrvf.add(getSelectionSpec("VisitFolders"));
visitFolders.getSelectSet().addAll(sspecarrvf);
List<SelectionSpec> resultspec = new ArrayList<SelectionSpec>();
resultspec.add(visitFolders);
resultspec.add(crToRp);
resultspec.add(crToH);
resultspec.add(dcToVmf);
resultspec.add(dcToHf);
resultspec.add(vAppToRp);
resultspec.add(vAppToVM);
resultspec.add(dcToDs);
resultspec.add(hToVm);
resultspec.add(rpToVm);
resultspec.add(rpToRp);
return resultspec;
}
use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class VmwareResource method deleteUnregisteredVmFiles.
private void deleteUnregisteredVmFiles(VirtualMachineFileLayoutEx vmFileLayout, DatacenterMO dcMo, boolean deleteDisks, List<String> skipDatastores) throws Exception {
s_logger.debug("Deleting files associated with an existing VM that was unregistered");
DatastoreFile vmFolder = null;
try {
List<VirtualMachineFileLayoutExFileInfo> fileInfo = vmFileLayout.getFile();
for (VirtualMachineFileLayoutExFileInfo file : fileInfo) {
DatastoreFile fileInDatastore = new DatastoreFile(file.getName());
// In case of linked clones, VM file layout includes the base disk so don't delete all disk files.
if (file.getType().startsWith("disk") || file.getType().startsWith("digest"))
continue;
else if (file.getType().equals("config"))
vmFolder = new DatastoreFile(fileInDatastore.getDatastoreName(), fileInDatastore.getDir());
DatastoreMO dsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName()));
checkAndDeleteDatastoreFile(file.getName(), skipDatastores, dsMo, dcMo);
}
// Delete files that are present in the VM folder - this will take care of the VM disks as well.
DatastoreMO vmFolderDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(vmFolder.getDatastoreName()));
String[] files = vmFolderDsMo.listDirContent(vmFolder.getPath());
if (deleteDisks) {
for (String file : files) {
String vmDiskFileFullPath = String.format("%s/%s", vmFolder.getPath(), file);
checkAndDeleteDatastoreFile(vmDiskFileFullPath, skipDatastores, vmFolderDsMo, dcMo);
}
}
// Delete VM folder
if (deleteDisks || files.length == 0) {
checkAndDeleteDatastoreFile(vmFolder.getPath(), skipDatastores, vmFolderDsMo, dcMo);
}
} catch (Exception e) {
String message = "Failed to delete files associated with an existing VM that was unregistered due to " + VmwareHelper.getExceptionMessage(e);
s_logger.warn(message, e);
}
}
use of com.vmware.vim25.mo.Folder in project CloudStack-archive by CloudStack-extras.
the class DatacenterMO method getHostPropertiesOnDatacenterHostFolder.
public ObjectContent[] getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("HostSystem");
pSpec.setPathSet(propertyPaths);
TraversalSpec computeResource2HostTraversal = new TraversalSpec();
computeResource2HostTraversal.setType("ComputeResource");
computeResource2HostTraversal.setPath("host");
computeResource2HostTraversal.setName("computeResource2HostTraversal");
SelectionSpec recurseFolders = new SelectionSpec();
recurseFolders.setName("folder2childEntity");
TraversalSpec folder2childEntity = new TraversalSpec();
folder2childEntity.setType("Folder");
folder2childEntity.setPath("childEntity");
folder2childEntity.setName(recurseFolders.getName());
folder2childEntity.setSelectSet(new SelectionSpec[] { recurseFolders, computeResource2HostTraversal });
TraversalSpec dc2HostFolderTraversal = new TraversalSpec();
dc2HostFolderTraversal.setType("Datacenter");
dc2HostFolderTraversal.setPath("hostFolder");
dc2HostFolderTraversal.setName("dc2HostFolderTraversal");
dc2HostFolderTraversal.setSelectSet(new SelectionSpec[] { folder2childEntity });
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { dc2HostFolderTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
return _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
}
Aggregations