Search in sources :

Example 11 with ManagedObjectReference

use of com.vmware.vim.binding.vmodl.ManagedObjectReference in project flowgate by vmware.

the class InventoryService method listByType.

public List<ManagedObjectReference> listByType(PropertyCollector propertyCollector, ManagedObjectReference containerView, String typeName) {
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setType(new TypeNameImpl(typeName));
    propertySpec.setAll(true);
    // PropertySpec networkPropertySpec = new PropertySpec();
    // networkPropertySpec.setType(new TypeNameImpl("Network"));
    // networkPropertySpec.setAll(true);
    // TraversalSpec traversalSpec = new TraversalSpec();
    // traversalSpec.setType(new TypeNameImpl("HostSystem"));
    // traversalSpec.setPath("network");
    // traversalSpec.setSkip(false);
    // traversalSpec.setSelectSet(null);
    TraversalSpec traversalSpec = new TraversalSpec();
    traversalSpec.setName(TRAVERSE_ENTITIES);
    traversalSpec.setPath(VIEW);
    traversalSpec.setSkip(false);
    traversalSpec.setType(new TypeNameImpl(CONTAINER_VIEW));
    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(containerView);
    objectSpec.setSelectSet(new SelectionSpec[] { traversalSpec });
    FilterSpec filterSpec = new FilterSpec();
    filterSpec.setObjectSet(new ObjectSpec[] { objectSpec });
    filterSpec.setPropSet(new PropertySpec[] { propertySpec });
    RetrieveOptions retrieveOptions = new RetrieveOptions();
    RetrieveResult retrieveResult = null;
    try {
        retrieveResult = propertyCollector.retrievePropertiesEx(new FilterSpec[] { filterSpec }, retrieveOptions);
    } catch (InvalidProperty invalidProperty) {
        logger.error("Invalid property", invalidProperty);
    }
    ObjectContent[] objects = null;
    if (null != retrieveResult) {
        objects = retrieveResult.getObjects();
    }
    List<ManagedObjectReference> targets = new ArrayList<ManagedObjectReference>();
    if (null != objects) {
        for (ObjectContent object : objects) {
            targets.add(object.getObj());
            DynamicProperty[] properties = object.getPropSet();
            if (null != properties) {
                for (DynamicProperty property : properties) {
                    switch(property.getName()) {
                        case NAME:
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
    // logger.debug("RetrieveResult \n{}", retrieveResult);
    return targets;
}
Also used : DynamicProperty(com.vmware.vim.binding.vmodl.DynamicProperty) ArrayList(java.util.ArrayList) RetrieveOptions(com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveOptions) TypeNameImpl(com.vmware.vim.binding.impl.vmodl.TypeNameImpl) FilterSpec(com.vmware.vim.binding.vmodl.query.PropertyCollector.FilterSpec) ObjectContent(com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectContent) ObjectSpec(com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectSpec) PropertySpec(com.vmware.vim.binding.vmodl.query.PropertyCollector.PropertySpec) TraversalSpec(com.vmware.vim.binding.vmodl.query.PropertyCollector.TraversalSpec) RetrieveResult(com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult) InvalidProperty(com.vmware.vim.binding.vmodl.query.InvalidProperty) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference)

Example 12 with ManagedObjectReference

use of com.vmware.vim.binding.vmodl.ManagedObjectReference in project flowgate by vmware.

the class VsphereClient method getResourcesByType.

private <T extends ManagedObject> Collection<T> getResourcesByType(Class<T> clazz, String type) {
    ManagedObjectReference[] crRef = InventoryService.getInstance().findAll(getPropertyCollector(), getContainerView(type), type);
    ArrayList<T> res = new ArrayList<T>();
    for (ManagedObjectReference ref : crRef) {
        res.add(client.createStub(clazz, ref));
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)12 Test (org.junit.Test)8 HostSystem (com.vmware.vim.binding.vim.HostSystem)7 ArrayList (java.util.ArrayList)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Asset (com.vmware.flowgate.common.model.Asset)4 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)4 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)4 HostInfo (com.vmware.flowgate.vcworker.model.HostInfo)4 ClusterComputeResource (com.vmware.vim.binding.vim.ClusterComputeResource)4 ConfigInfoEx (com.vmware.vim.binding.vim.cluster.ConfigInfoEx)3 DpmHostConfigInfo (com.vmware.vim.binding.vim.cluster.DpmHostConfigInfo)3 HashMap (java.util.HashMap)3 EsxiMetadata (com.vmware.flowgate.vcworker.model.EsxiMetadata)2 DpmConfigInfo (com.vmware.vim.binding.vim.cluster.DpmConfigInfo)2 DrsConfigInfo (com.vmware.vim.binding.vim.cluster.DrsConfigInfo)2 Capability (com.vmware.vim.binding.vim.host.Capability)2 ConfigInfo (com.vmware.vim.binding.vim.host.ConfigInfo)2 WormholeException (com.vmware.flowgate.common.exception.WormholeException)1 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)1