com.vmware.vim25.InvalidPropertyFaultMsg Java Examples

The following examples show how to use com.vmware.vim25.InvalidPropertyFaultMsg. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WaitForValues.java    From vsphere-automation-sdk-java with MIT License 6 votes vote down vote up
/**
 * This method returns a boolean value specifying whether the Task is
 * succeeded or failed.
 *
 * @param task
 *            ManagedObjectReference representing the Task.
 * @return boolean value representing the Task result.
 * @throws InvalidCollectorVersionFaultMsg
 *
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public boolean getTaskResultAfterDone(ManagedObjectReference task)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg,
        InvalidCollectorVersionFaultMsg {

    boolean retVal = false;

    // info has a property - state for state of the task
    Object[] result = wait(task,
            new String[] { "info.state", "info.error" },
            new String[] { "state" }, new Object[][] { new Object[] {
                TaskInfoState.SUCCESS, TaskInfoState.ERROR } });

    if (result[0].equals(TaskInfoState.SUCCESS)) {
        retVal = true;
    }
    if (result[1] instanceof LocalizedMethodFault) {
        throw new RuntimeException(
                ((LocalizedMethodFault) result[1]).getLocalizedMessage());
    }
    return retVal;
}
 
Example #2
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
/**
 * Method to retrieve properties of a {@link ManagedObjectReference}
 *
 * @param entityMor {@link ManagedObjectReference} of the entity
 * @param props     Array of properties to be looked up
 * @return Map of the property name and its corresponding value
 * @throws InvalidPropertyFaultMsg If a property does not exist
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, Object> entityProps(ManagedObjectReference entityMor, String[] props)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    final HashMap<String, Object> retVal = new HashMap<>();
    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec[] propertyFilterSpecs = {new PropertyFilterSpecBuilder().propSet(
            // Create Property Spec
            new PropertySpecBuilder().all(false).type(entityMor.getType()).pathSet(props))
            .objectSet(
            // Now create Object Spec
            new ObjectSpecBuilder().obj(entityMor))};

    List<ObjectContent> objCont = vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(),
            Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();

    if (objCont != null) {
        for (ObjectContent oc : objCont) {
            List<DynamicProperty> dps = oc.getPropSet();
            for (DynamicProperty dp : dps) {
                retVal.put(dp.getName(), dp.getVal());
            }
        }
    }

    return retVal;
}
 
Example #3
Source File: VmUtils.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
public ManagedObjectReference getMorHost(String hostname, ConnectionResources connectionResources,
                                         ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference host = null;
    if (isNotBlank(hostname)) {
        host = getManagedObjectReference(hostname, connectionResources,
                ManagedObjectType.HOST_SYSTEM.getValue(), ErrorMessages.HOST_NOT_FOUND);
    } else if (StringUtils.isBlank(hostname) && vmMor != null) {
        ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor,
                new String[]{ManagedObjectType.SUMMARY.getValue()});

        for (ObjectContent objectItem : objectContents) {
            List<DynamicProperty> vmProperties = objectItem.getPropSet();
            for (DynamicProperty propertyItem : vmProperties) {
                VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal();
                host = virtualMachineSummary.getRuntime().getHost();
                break;
            }
            break;
        }
    } else {
        host = connectionResources.getHostMor();
    }
    return host;
}
 
Example #4
Source File: ManagedObjectAccessor.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param collector
 *            Property collector registered with service
 * @param mobj
 *            Managed Object Reference to get contents for
 * @param properties
 *            names of properties of object to retrieve
 *
 * @return retrieved object contents
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
private ObjectContent[] getObjectProperties(ManagedObjectReference mobj,
        String[] properties)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (mobj == null) {
        return null;
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());
    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(Boolean.TRUE);
    } else {
        spec.getPropSet().get(0).setAll(Boolean.FALSE);
    }
    spec.getPropSet().get(0).setType(mobj.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mobj);
    spec.getObjectSet().get(0).setSkip(Boolean.FALSE);
    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(spec);
    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);
    return listobjcont.toArray(new ObjectContent[listobjcont.size()]);
}
 
Example #5
Source File: VmUtils.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
public ManagedObjectReference getMorResourcePool(String resourcePoolName, ConnectionResources connectionResources)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference resourcePool;
    if (isNotBlank(resourcePoolName)) {
        resourcePool = getManagedObjectReference(resourcePoolName, connectionResources,
                ManagedObjectType.RESOURCE_POOL.getValue(), ErrorMessages.RESOURCE_POOL_NOT_FOUND);
    } else {
        resourcePool = connectionResources.getResourcePoolMor();
        if (resourcePool == null) {
            ManagedObjectReference reference = connectionResources.getMorRootFolder();
            resourcePool = new MorObjectHandler().getSpecificMor(connectionResources, reference,
                    ManagedObjectType.RESOURCE_POOL.getValue(), ManagedObjectType.RESOURCES.getValue());
        }
    }
    return resourcePool;
}
 
Example #6
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the helper object on the current connection at invocation time. Do not initialize on construction
 * since the connection may not be ready yet.
 */

private RetrieveResult containerViewByType(final ManagedObjectReference container,
                                           final String morefType,
                                           final RetrieveOptions retrieveOptions
) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    return this.containerViewByType(container, morefType, retrieveOptions, ManagedObjectType.NAME.getValue());
}
 
Example #7
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getDataStore(String dataStoreName, ConnectionResources connectionResources,
                                            ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ArrayOfManagedObjectReference dataStoresArray = (ArrayOfManagedObjectReference) new MorObjectHandler()
            .getObjectProperties(connectionResources, vmMor, ManagedObjectType.DATA_STORE.getValue());
    List<ManagedObjectReference> dataStores = dataStoresArray.getManagedObjectReference();
    for (ManagedObjectReference dataStore : dataStores) {
        DatastoreSummary datastoreSummary = (DatastoreSummary) new MorObjectHandler()
                .getObjectProperties(connectionResources, dataStore, ManagedObjectType.SUMMARY.getValue());
        if (dataStoreName.equalsIgnoreCase(datastoreSummary.getName())) {
            return dataStore;
        }
    }
    return null;
}
 
Example #8
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
ConfigTarget getHostConfigTarget(ConnectionResources connectionResources, ManagedObjectReference hostMor)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference environmentBrowserMor = new MorObjectHandler()
            .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue());
    ConfigTarget configTarget = connectionResources.getVimPortType().queryConfigTarget(environmentBrowserMor, hostMor);
    if (configTarget == null) {
        throw new RuntimeException(ErrorMessages.CONFIG_TARGET_NOT_FOUND_IN_COMPUTE_RESOURCE);
    }

    return configTarget;
}
 
Example #9
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getMorDataStore(String dataStoreName, ConnectionResources connectionResources,
                                              ManagedObjectReference vmMor, VmInputs vmInputs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference dataStore = null;
    if (isNotBlank(dataStoreName)) {
        ManagedObjectReference cloneHostMor = getMorHost(vmInputs.getCloneHost(), connectionResources, vmMor);
        ConfigTarget configTarget = getHostConfigTarget(connectionResources, cloneHostMor);
        List<VirtualMachineDatastoreInfo> dataStoreInfoList = configTarget.getDatastore();
        for (VirtualMachineDatastoreInfo dataStoreInfo : dataStoreInfoList) {
            if (vmInputs.getCloneDataStore().equals(dataStoreInfo.getDatastore().getName())) {
                dataStore = getDataStoreRef(vmInputs.getCloneDataStore(), dataStoreInfoList);
                break;
            }
        }

        if (dataStore == null) {
            throw new RuntimeException(ErrorMessages.DATA_STORE_NOT_FOUND);
        }
    } else {
        ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor,
                new String[]{ManagedObjectType.SUMMARY.getValue()});

        for (ObjectContent objectItem : objectContents) {
            List<DynamicProperty> vmProperties = objectItem.getPropSet();
            for (DynamicProperty propertyItem : vmProperties) {
                VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal();
                String vmPathName = virtualMachineSummary.getConfig().getVmPathName();
                dataStoreName = vmPathName.substring(1, vmPathName.indexOf(Constants.RIGHT_SQUARE_BRACKET));
                dataStore = getDataStore(dataStoreName, connectionResources, vmMor);
                break;
            }
            break;
        }
    }
    return dataStore;
}
 
Example #10
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
private ManagedObjectReference getManagedObjectReference(String resourceName, ConnectionResources connectionResources,
                                                         String filter, String errorMessage) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference reference = connectionResources.getMorRootFolder();
    ManagedObjectReference managedObjectReference = new MorObjectHandler().getSpecificMor(connectionResources, reference,
            filter, resourceName);
    if (managedObjectReference == null) {
        throw new RuntimeException(errorMessage);
    }
    return managedObjectReference;
}
 
Example #11
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getMorResourcePoolFromCluster(final ConnectionResources connectionResources, final ManagedObjectReference clusterMor,
                                                            final String resourcePoolName) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (isNotBlank(resourcePoolName)) {
        return new MorObjectHandler().getSpecificMor(connectionResources, clusterMor,
                ManagedObjectType.RESOURCE_POOL.getValue(), resourcePoolName);
    } else {
        return new MorObjectHandler().getSpecificMor(connectionResources, clusterMor,
                ManagedObjectType.RESOURCE_POOL.getValue(), ManagedObjectType.RESOURCES.getValue());
    }
}
 
Example #12
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private Map<String, ManagedObjectReference> toMap(RetrieveResult result)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    final Map<String, ManagedObjectReference> tgtMoref = new HashMap<>();

    String token = populate(result, tgtMoref);
    while (token != null && !token.isEmpty()) {
        // fetch results based on new token
        result = vimPort.continueRetrievePropertiesEx(serviceContent.getPropertyCollector(), token);
        token = populate(result, tgtMoref);
    }

    return tgtMoref;
}
 
Example #13
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setComputeResourceMor() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference computeResourceMor = null;
    if (hostMor != null) {
        computeResourceMor = getComputeResourceMor(moRefHandler, hostMor);
    }
    this.setComputeResourceMor(computeResourceMor);
}
 
Example #14
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setDataCenterMor(VmInputs vmInputs) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference dataCenterMor = null;
    if (StringUtils.isNotBlank(vmInputs.getDataCenterName())) {
        dataCenterMor = getDataCenterMor(vmInputs.getDataCenterName(), morRootFolder, moRefHandler);
    }
    this.setDataCenterMor(dataCenterMor);
}
 
Example #15
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getDataCenterMor(String dataCenterName, ManagedObjectReference mor, MoRefHandler moRefHandler)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference dataCenterMor = moRefHandler.inContainerByType(mor, ManagedObjectType.DATA_CENTER.getValue())
            .get(dataCenterName);
    if (dataCenterMor == null) {
        throw new RuntimeException("Datacenter [" + dataCenterName + "] not found.");
    }

    return dataCenterMor;
}
 
Example #16
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setHostMor(VmInputs vmInputs) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference hostMor = null;
    if (dataCenterMor != null) {
        hostMor = getHostMor(vmInputs.getHostname(), moRefHandler, dataCenterMor);
    }
    this.setHostMor(hostMor);
}
 
Example #17
Source File: ResponseHelper.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
protected boolean getTaskResultAfterDone(ConnectionResources connectionResources, ManagedObjectReference task)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
    WaitForValues waitForValues = new WaitForValues(connectionResources.getConnection());
    Object[] result = waitForValues.wait(task, new String[]{ManagedObjectType.INFO_STATE.getValue(),
                    ManagedObjectType.INFO_ERROR.getValue()}, new String[]{ManagedObjectType.STATE.getValue()},
            new Object[][]{new Object[]{TaskInfoState.SUCCESS, TaskInfoState.ERROR}});

    if (result[1] instanceof LocalizedMethodFault) {
        throw new RuntimeException(((LocalizedMethodFault) result[1]).getLocalizedMessage());
    }

    return result[0].equals(TaskInfoState.SUCCESS);
}
 
Example #18
Source File: ResponseHelper.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getResultsMap(String successMessage, String failureMessage)
        throws InvalidCollectorVersionFaultMsg, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    return (getTaskResultAfterDone(connectionResources, task)) ?
            ResponseUtils.getResultsMap(successMessage, Outputs.RETURN_CODE_SUCCESS) :
            ResponseUtils.getResultsMap(failureMessage, Outputs.RETURN_CODE_FAILURE);
}
 
Example #19
Source File: GetObjectProperties.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param propertyFilterSpecList
 * @return list of object content
 * @throws Exception
 */
private static List<ObjectContent> retrievePropertiesAllObjects(ConnectionResources connectionResources,
                                                               List<PropertyFilterSpec> propertyFilterSpecList)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {

    VimPortType vimPort = connectionResources.getVimPortType();
    ManagedObjectReference serviceInstance = connectionResources.getServiceInstance();
    ServiceContent serviceContent = vimPort.retrieveServiceContent(serviceInstance);
    ManagedObjectReference propertyCollectorReference = serviceContent.getPropertyCollector();
    RetrieveOptions propertyObjectRetrieveOptions = new RetrieveOptions();
    List<ObjectContent> objectContentList = new ArrayList<>();

    RetrieveResult results = vimPort.retrievePropertiesEx(propertyCollectorReference,
            propertyFilterSpecList,
            propertyObjectRetrieveOptions);

    if (results != null && results.getObjects() != null && !results.getObjects().isEmpty()) {
        objectContentList.addAll(results.getObjects());
    }

    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }

    while (token != null && !token.isEmpty()) {
        results = vimPort.continueRetrievePropertiesEx(propertyCollectorReference, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null && !results.getObjects().isEmpty()) {
                objectContentList.addAll(results.getObjects());
            }
        }
    }

    return objectContentList;
}
 
Example #20
Source File: GetObjectProperties.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param mor        Managed Object Reference to get contents for
 * @param properties names of properties of object to retrieve
 * @return retrieved object contents
 */
@NotNull
public static ObjectContent[] getObjectProperties(ConnectionResources connectionResources,
                                                  ManagedObjectReference mor,
                                                  String[] properties)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    if (mor == null) {
        return new ObjectContent[0];
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());

    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(true);
    } else {
        spec.getPropSet().get(0).setAll(false);
    }

    spec.getPropSet().get(0).setType(mor.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mor);
    spec.getObjectSet().get(0).setSkip(false);

    List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<>(1);
    propertyFilterSpecs.add(spec);
    List<ObjectContent> objectContentList = retrievePropertiesAllObjects(connectionResources, propertyFilterSpecs);

    return objectContentList.toArray(new ObjectContent[objectContentList.size()]);
}
 
Example #21
Source File: Utils.java    From GraphiteReceiver with Apache License 2.0 5 votes vote down vote up
private static RetrieveResult getRetrieveResult(String clusterName, VimConnection connection, ManagedObjectReference rootFolder) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    List<String> clusterList = new ArrayList<String>();
    clusterList.add("ComputeResource");
    clusterList.add("HostSystem");
    clusterList.add("VirtualMachine");

    ManagedObjectReference rootFolderAux = (clusterName == null)? connection.getRootFolder():rootFolder;
    ManagedObjectReference viewManager = connection.getVimPort().createContainerView(connection.getViewManager(), rootFolderAux, clusterList, true);

    if(viewManager == null) {
        logger.debug("cViewRef is null: " + clusterName);
        return null;
    }
    logger.debug("cViewRef is not null: " + clusterName);

    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(viewManager);
    objectSpec.setSkip(true);
    objectSpec.getSelectSet().add(getTraversalSpec(clusterName));

    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getObjectSet().add(objectSpec);

    if(clusterName == null){
        propertyFilterSpec.getPropSet().add(getPropertySpec("ComputeResource"));
    }else{
        propertyFilterSpec.getPropSet().add(getPropertySpec("HostSystem"));
        propertyFilterSpec.getPropSet().add(getPropertySpec("VirtualMachine"));
    }
    List<PropertyFilterSpec> propertyFilterSpecs = new LinkedList<PropertyFilterSpec>();
    propertyFilterSpecs.add(propertyFilterSpec);
    return connection.getVimPort().retrievePropertiesEx(connection.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions());
}
 
Example #22
Source File: VMwareClient.java    From development with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getVirtualMachine(String vmName)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference vm = getServiceUtil().getDecendentMoRef(null,
            MO_TYPE_VIRTUAL_MACHINE, vmName);
    return vm;
}
 
Example #23
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getHostMor(String hostname, MoRefHandler moRefHandler, ManagedObjectReference dataCenterMor)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference hostMor = moRefHandler.inContainerByType(dataCenterMor, ManagedObjectType.HOST_SYSTEM.getValue())
            .get(hostname);
    if (hostMor == null) {
        throw new RuntimeException("Host [" + hostname + "] not found.");
    }

    return hostMor;
}
 
Example #24
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getComputeResourceMor(MoRefHandler moRefHandler, ManagedObjectReference hostMor)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference computeResourceMor = (ManagedObjectReference) moRefHandler
            .entityProps(hostMor, new String[]{ManagedObjectType.PARENT.getValue()}).get(ManagedObjectType.PARENT.getValue());

    if (computeResourceMor == null) {
        throw new RuntimeException(ErrorMessages.COMPUTE_RESOURCE_NOT_FOUND_ON_HOST);
    }

    return computeResourceMor;
}
 
Example #25
Source File: ManagedObjectAccessor.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param filterSpecs
 * @return list of object content
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 * @throws Exception
 */
private List<ObjectContent> retrievePropertiesAllObjects(
        List<PropertyFilterSpec> filterSpecs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    RetrieveOptions retrieveOptions = new RetrieveOptions();
    ManagedObjectReference collector = serviceContent
            .getPropertyCollector();

    List<ObjectContent> contents = new ArrayList<ObjectContent>();

    RetrieveResult results = vimPort.retrievePropertiesEx(collector,
            filterSpecs, retrieveOptions);
    if (results != null && results.getObjects() != null
            && !results.getObjects().isEmpty()) {
        contents.addAll(results.getObjects());
    }
    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }
    while (token != null && token.length() > 0) {
        results = vimPort.continueRetrievePropertiesEx(collector, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null
                    && !results.getObjects().isEmpty()) {
                contents.addAll(results.getObjects());
            }
        }
    }

    return contents;
}
 
Example #26
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * Get the required properties of the specified object.
 *
 * @param vimPort
 * @param serviceContent
 * @param moRef
 * @param type
 * @param properties
 * @return
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public static List<DynamicProperty> getProperties(VimPortType vimPort,
        ServiceContent serviceContent, ManagedObjectReference moRef,
        String type, List<String> properties)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    // Create Property Spec
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setAll(false);
    propertySpec.setType(type);
    propertySpec.getPathSet().addAll(properties);

    // Now create Object Spec
    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(moRef);
    objectSpec.setSkip(false);

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    // created above.
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);

    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(propertyFilterSpec);
    List<ObjectContent> listobjcontent = VimUtil
            .retrievePropertiesAllObjects(vimPort,
                    serviceContent.getPropertyCollector(), listpfs);
    assert listobjcontent != null && listobjcontent.size() > 0;
    ObjectContent contentObj = listobjcontent.get(0);
    List<DynamicProperty> objList = contentObj.getPropSet();
    return objList;
}
 
Example #27
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method.
 *
 * @param listpfs
 * @return list of object content
 * @throws Exception
 */
public static List<ObjectContent> retrievePropertiesAllObjects(
        VimPortType vimPort, ManagedObjectReference propCollectorRef,
        List<PropertyFilterSpec> listpfs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    RetrieveOptions propObjectRetrieveOpts = new RetrieveOptions();
    List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();

    RetrieveResult rslts = vimPort.retrievePropertiesEx(propCollectorRef,
            listpfs, propObjectRetrieveOpts);
    if (rslts != null && rslts.getObjects() != null
            && !rslts.getObjects().isEmpty()) {
        listobjcontent.addAll(rslts.getObjects());
    }
    String token = null;
    if (rslts != null && rslts.getToken() != null) {
        token = rslts.getToken();
    }
    while (token != null && !token.isEmpty()) {
        rslts = vimPort.continueRetrievePropertiesEx(propCollectorRef,
                token);
        token = null;
        if (rslts != null) {
            token = rslts.getToken();
            if (rslts.getObjects() != null
                    && !rslts.getObjects().isEmpty()) {
                listobjcontent.addAll(rslts.getObjects());
            }
        }
    }

    return listobjcontent;
}
 
Example #28
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void commonVerifications() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    verify(connectionResourcesMock, times(1)).getConnection();
    verify(connectionResourcesMock, times(1)).getVimPortType();
    verify(morObjectHandlerMock, times(1)).getSpecificMor(any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class), any(String.class));
    verify(vimPortMock, times(1)).reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class));
    verify(taskMock, times(1)).getValue();
    verify(connectionMock, times(1)).disconnect();
}
 
Example #29
Source File: VmwareClient.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
private RetrieveResult containerViewByType(final RetrieveOptions retrieveOptions,
                                           final PropertyFilterSpec... propertyFilterSpecs)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    return vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(), Arrays.asList(propertyFilterSpecs),
            retrieveOptions);
}