com.vmware.vim25.PropertyFilterSpec Java Examples

The following examples show how to use com.vmware.vim25.PropertyFilterSpec. 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: VmwareClient.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
private List<ObjectContent> retrieveMoRefProperties(ManagedObjectReference mObj, List<String> props) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setAll(false);
    pSpec.setType(mObj.getType());
    pSpec.getPathSet().addAll(props);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(mObj);
    oSpec.setSkip(false);
    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(pSpec);
    spec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
    specArr.add(spec);

    return vimPort.retrieveProperties(getPropCol(), specArr);
}
 
Example #2
Source File: HostDatastoreSystemMO.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datastore");
        pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

        TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
        hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
        hostDsSys2DatastoreTraversal.setPath("datastore");
        hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(_mor);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal);

        PropertyFilterSpec pfSpec = new PropertyFilterSpec();
        pfSpec.getPropSet().add(pSpec);
        pfSpec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
        pfSpecArr.add(pfSpec);

        return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    }
 
Example #3
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
private PropertyFilterSpec[] propertyFilterSpecs(ManagedObjectReference container,
                                                 String morefType,
                                                 String... morefProperties
) throws RuntimeFaultFaultMsg {
    ManagedObjectReference viewManager = serviceContent.getViewManager();
    ManagedObjectReference containerView = vimPort.createContainerView(viewManager, container,
            Arrays.asList(morefType), true);

    return new PropertyFilterSpec[]{
            new PropertyFilterSpecBuilder().propSet(new PropertySpecBuilder().all(false)
                    .type(morefType).pathSet(morefProperties)).objectSet(new ObjectSpecBuilder()
                    .obj(containerView).skip(true).selectSet(new TraversalSpecBuilder()
                            .name(ManagedObjectType.VIEW.getValue())
                            .path(ManagedObjectType.VIEW.getValue())
                            .skip(false)
                            .type(ManagedObjectType.CONTAINER_VIEW.getValue())))};
}
 
Example #4
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 #5
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datastore");
        pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

        TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
        dc2DatastoreTraversal.setType("Datacenter");
        dc2DatastoreTraversal.setPath("datastore");
        dc2DatastoreTraversal.setName("dc2DatastoreTraversal");

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(_mor);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(dc2DatastoreTraversal);

        PropertyFilterSpec pfSpec = new PropertyFilterSpec();
        pfSpec.getPropSet().add(pSpec);
        pfSpec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
        pfSpecArr.add(pfSpec);

        return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    }
 
Example #6
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 #7
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public List<DatastoreMO> getAllDatastores() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().add("name");

    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
    vmDatastoreTraversal.setType("VirtualMachine");
    vmDatastoreTraversal.setPath("datastore");
    vmDatastoreTraversal.setName("vmDatastoreTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(vmDatastoreTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    List<DatastoreMO> datastores = new ArrayList<DatastoreMO>();
    if (CollectionUtils.isNotEmpty(ocs)) {
        for (ObjectContent oc : ocs) {
            datastores.add(new DatastoreMO(_context, oc.getObj()));
        }
    }
    return datastores;
}
 
Example #8
Source File: ClusterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec host2VmFolderTraversal = new TraversalSpec();
    host2VmFolderTraversal.setType("HostSystem");
    host2VmFolderTraversal.setPath("vm");
    host2VmFolderTraversal.setName("host2VmFolderTraversal");

    TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
    cluster2HostFolderTraversal.setType("ClusterComputeResource");
    cluster2HostFolderTraversal.setPath("host");
    cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
    cluster2HostFolderTraversal.getSelectSet().add(host2VmFolderTraversal);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2HostFolderTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
 
Example #9
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public String[] getNetworks() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("name");

    TraversalSpec vm2NetworkTraversal = new TraversalSpec();
    vm2NetworkTraversal.setType("VirtualMachine");
    vm2NetworkTraversal.setPath("network");
    vm2NetworkTraversal.setName("vm2NetworkTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(vm2NetworkTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    List<String> networks = new ArrayList<String>();
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            networks.add(oc.getPropSet().get(0).getVal().toString());
        }
    }
    return networks.toArray(new String[0]);
}
 
Example #10
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public VirtualMachineFileLayoutEx getFileLayout() throws Exception {
    VirtualMachineFileLayoutEx fileLayout = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().add("layoutEx");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.FALSE);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("layoutEx")) {
                        fileLayout = (VirtualMachineFileLayoutEx)prop.getVal();
                        break;
                    }
                }
            }
        }
    }

    return fileLayout;
}
 
Example #11
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
    String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().add("name");

    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
    vmDatastoreTraversal.setType("VirtualMachine");
    vmDatastoreTraversal.setPath("datastore");
    vmDatastoreTraversal.setName("vmDatastoreTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(vmDatastoreTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            DynamicProperty prop = oc.getPropSet().get(0);
            if (prop.getVal().toString().equals(dsName)) {
                return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
            }
        }
    }

    return null;
}
 
Example #12
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");

    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getVal().equals(dvPortGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    return null;
}
 
Example #13
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context, ManagedObjectReference morEntity) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datacenter");
        pSpec.getPathSet().add("name");

        TraversalSpec entityParentTraversal = new TraversalSpec();
        entityParentTraversal.setType("ManagedEntity");
        entityParentTraversal.setPath("parent");
        entityParentTraversal.setName("entityParentTraversal");
        SelectionSpec selSpec = new SelectionSpec();
        selSpec.setName("entityParentTraversal");
        entityParentTraversal.getSelectSet().add(selSpec);

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(morEntity);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(entityParentTraversal);

        PropertyFilterSpec pfSpec = new PropertyFilterSpec();
        pfSpec.getPropSet().add(pSpec);
        pfSpec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
        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().get(0) != null);
        assert (ocs.get(0).getPropSet().get(0).getVal() != null);

        String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
        return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs.get(0).getObj()), dcName);
    }
 
Example #14
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec dc2VmFolderTraversal = new TraversalSpec();
    dc2VmFolderTraversal.setType("Datacenter");
    dc2VmFolderTraversal.setPath("vmFolder");
    dc2VmFolderTraversal.setName("dc2VmFolderTraversal");

    SelectionSpec recurseFolders = new SelectionSpec();
    recurseFolders.setName("folder2childEntity");

    TraversalSpec folder2childEntity = new TraversalSpec();
    folder2childEntity.setType("Folder");
    folder2childEntity.setPath("childEntity");
    folder2childEntity.setName(recurseFolders.getName());
    folder2childEntity.getSelectSet().add(recurseFolders);
    dc2VmFolderTraversal.getSelectSet().add(folder2childEntity);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dc2VmFolderTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
}
 
Example #15
Source File: ClusterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec cluster2DatastoreTraversal = new TraversalSpec();
    cluster2DatastoreTraversal.setType("ClusterComputeResource");
    cluster2DatastoreTraversal.setPath("datastore");
    cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2DatastoreTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
 
Example #16
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public List<ObjectContent> getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("HostSystem");
    pSpec.getPathSet().addAll(Arrays.asList(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.getSelectSet().add(recurseFolders);
    folder2childEntity.getSelectSet().add(computeResource2HostTraversal);

    TraversalSpec dc2HostFolderTraversal = new TraversalSpec();
    dc2HostFolderTraversal.setType("Datacenter");
    dc2HostFolderTraversal.setPath("hostFolder");
    dc2HostFolderTraversal.setName("dc2HostFolderTraversal");
    dc2HostFolderTraversal.getSelectSet().add(folder2childEntity);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dc2HostFolderTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

}
 
Example #17
Source File: ClusterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("HostSystem");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec cluster2HostTraversal = new TraversalSpec();
    cluster2HostTraversal.setType("ClusterComputeResource");
    cluster2HostTraversal.setPath("host");
    cluster2HostTraversal.setName("cluster2HostTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2HostTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);

    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
 
Example #18
Source File: VmwareClient.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public boolean validate() {
    //
    // There is no official API to validate an open vCenter API session. This is hacking way to tell if
    // an open vCenter API session is still valid for making calls.
    //
    // It will give false result if there really does not exist data-center in the inventory, however, I consider
    // this really is not possible in production deployment
    //

    // Create PropertySpecs
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.setAll(false);
    pSpec.getPathSet().add("name");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getRootFolder());
    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);

    try {
        List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);
        if (ocary != null && ocary.size() > 0)
            return true;
    } catch (Exception e) {
        return false;
    }

    return false;
}
 
Example #19
Source File: HostMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " +
                new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec host2DatastoreTraversal = new TraversalSpec();
    host2DatastoreTraversal.setType("HostSystem");
    host2DatastoreTraversal.setPath("datastore");
    host2DatastoreTraversal.setName("host2DatastoreTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2DatastoreTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
 
Example #20
Source File: HostMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " +
                new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec host2VmTraversal = new TraversalSpec();
    host2VmTraversal.setType("HostSystem");
    host2VmTraversal.setPath("vm");
    host2VmTraversal.setName("host2VmTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2VmTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
 
Example #21
Source File: HostMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("summary.name");

    TraversalSpec host2NetworkTraversal = new TraversalSpec();
    host2NetworkTraversal.setType("HostSystem");
    host2NetworkTraversal.setPath("network");
    host2NetworkTraversal.setName("host2NetworkTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2NetworkTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);

    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getVal().equals(portGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    return null;
}
 
Example #22
Source File: WaitForValues.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor,
        String[] filterProps) {
    PropertyFilterSpec spec = new PropertyFilterSpec();
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(objmor);
    oSpec.setSkip(Boolean.FALSE);
    spec.getObjectSet().add(oSpec);

    PropertySpec pSpec = new PropertySpec();
    pSpec.getPathSet().addAll(Arrays.asList(filterProps));
    pSpec.setType(objmor.getType());
    spec.getPropSet().add(pSpec);
    return spec;
}
 
Example #23
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 #24
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 #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: 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 #27
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 #28
Source File: WaitForValues.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps) {
    ObjectSpec objSpec = new ObjectSpec();
    objSpec.setObj(objmor);
    objSpec.setSkip(false);

    PropertySpec propSpec = new PropertySpec();
    propSpec.getPathSet().addAll(Arrays.asList(filterProps));
    propSpec.setType(objmor.getType());

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(objSpec);
    spec.getPropSet().add(propSpec);

    return spec;
}
 
Example #29
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference findManagedObjectReferenceByTypeAndId(final ManagedObjectReference folder,
                                                                    final String morefType,
                                                                    final RetrieveOptions retrieveOptions, final String id) throws Exception {
    final PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(folder, morefType);
    final ManagedObjectReference searchedReference = findComponentReference(propertyFilterSpecs, retrieveOptions, id);
    if (searchedReference != null) {
        return searchedReference;
    }
    throw new RuntimeException(String.format(REFERENCE_TYPE_WITH_ID_NOT_FOUND, morefType, id));
}
 
Example #30
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private RetrieveResult retrievePropertiesEx(final List<PropertyFilterSpec> propertyFilterSpecs, final RetrieveOptions retrieveOptions,
                                            final String token) throws Exception {
    if (isEmpty(token)) {
        return vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(), propertyFilterSpecs, retrieveOptions);
    }
    return vimPort.continueRetrievePropertiesEx(serviceContent.getPropertyCollector(), token);
}