use of com.vmware.vim25.mo.Folder in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method makeFolderFromChanges.
private static ResourceGroupState makeFolderFromChanges(FolderOverlay folder, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ResourceGroupState state = new ResourceGroupState();
// Folder name change
state.name = folder.getNameOrNull();
// Folder parent change
if (null != folder.getParentOrNull()) {
// retrieve parent folder Moref
ManagedObjectReference parent = folder.getParentOrNull();
// retrieve parent of parent folder
ManagedObjectReference parentOfParentFolder = client.getParentOfFolder(parent);
// if the parent of parent folder is DC, then the parent is root folder. Add parent of parent during this scenario.
if (parentOfParentFolder.getType().equals(VimNames.TYPE_DATACENTER)) {
CustomProperties.of(state).put(CustomProperties.PARENT_ID, VimUtils.convertMoRefToString(parentOfParentFolder));
} else {
CustomProperties.of(state).put(CustomProperties.PARENT_ID, VimUtils.convertMoRefToString(parent));
}
}
return state;
}
use of com.vmware.vim25.mo.Folder in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method updateFolder.
private static void updateFolder(VSphereIncrementalEnumerationService service, EnumerationProgress ctx, FolderOverlay folder, ResourceGroupState oldDocument, List<FolderOverlay> rootFolders, EnumerationClient client, boolean fullUpdate) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ResourceGroupState state;
if (fullUpdate) {
state = makeFolderFromResults(ctx, folder, rootFolders, client);
} else {
state = makeFolderFromChanges(folder, client);
}
state.documentSelfLink = oldDocument.documentSelfLink;
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), state.documentSelfLink)).setBody(state).setCompletion((o, e) -> {
trackFolder(ctx, folder).handle(o, e);
service.logInfo("updating document for folder: %s ", folder.getName());
}).sendWith(service);
}
use of com.vmware.vim25.mo.Folder in project vsphere-cloud-plugin by jenkinsci.
the class VSphere method getFolder.
public Folder getFolder(String folderPath) throws VSphereException {
try {
String[] folderHierarchy = folderPath.split("/");
ManagedEntity folder = null;
for (int i = 0; i < folderHierarchy.length; i++) {
if (i == 0) {
folder = new InventoryNavigator(getServiceInstance().getRootFolder()).searchManagedEntity("Folder", folderHierarchy[i]);
} else {
folder = new InventoryNavigator(folder).searchManagedEntity(null, folderHierarchy[i]);
}
}
return (Folder) folder;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Invalid folder");
throw new VSphereException(e);
}
}
use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class DatastoreMO method getOwnerDatacenter.
public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
if (_ownerDc != null)
return _ownerDc;
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datacenter");
pSpec.getPathSet().add("name");
TraversalSpec folderParentTraversal = new TraversalSpec();
folderParentTraversal.setType("Folder");
folderParentTraversal.setPath("parent");
folderParentTraversal.setName("folderParentTraversal");
SelectionSpec sSpec = new SelectionSpec();
sSpec.setName("folderParentTraversal");
folderParentTraversal.getSelectSet().add(sSpec);
TraversalSpec dsParentTraversal = new TraversalSpec();
dsParentTraversal.setType("Datastore");
dsParentTraversal.setPath("parent");
dsParentTraversal.setName("dsParentTraversal");
dsParentTraversal.getSelectSet().add(folderParentTraversal);
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(getMor());
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(dsParentTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
assert (ocs != null && ocs.size() > 0);
assert (ocs.get(0).getObj() != null);
assert (ocs.get(0).getPropSet() != null);
String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
_ownerDc = new Pair<>(new DatacenterMO(_context, ocs.get(0).getObj()), dcName);
return _ownerDc;
}
use of com.vmware.vim25.mo.Folder in project cloudstack by apache.
the class DatastoreMO method deleteFolder.
public boolean deleteFolder(String folder, ManagedObjectReference morDc) throws Exception {
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, folder, morDc);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
Aggregations