Search in sources :

Example 16 with Folder

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;
}
Also used : ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 17 with Folder

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);
}
Also used : AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) Operation(com.vmware.xenon.common.Operation) QueryTask(com.vmware.xenon.services.common.QueryTask) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VsphereEnumerationHelper.getSelfLinkFromOperation(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.getSelfLinkFromOperation) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 18 with Folder

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);
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) Folder(com.vmware.vim25.mo.Folder) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 19 with Folder

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;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 20 with Folder

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;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)30 TraversalSpec (com.vmware.vim25.TraversalSpec)15 ArrayList (java.util.ArrayList)15 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)13 SelectionSpec (com.vmware.vim25.SelectionSpec)12 ObjectSpec (com.vmware.vim25.ObjectSpec)11 PropertySpec (com.vmware.vim25.PropertySpec)11 TaskInfo (com.vmware.vim25.TaskInfo)10 RemoteException (java.rmi.RemoteException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)8 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)8 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)6 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)6 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)6 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)6 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)6