Search in sources :

Example 1 with DynamicProperty

use of com.vmware.vim.binding.vmodl.DynamicProperty 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)

Aggregations

TypeNameImpl (com.vmware.vim.binding.impl.vmodl.TypeNameImpl)1 DynamicProperty (com.vmware.vim.binding.vmodl.DynamicProperty)1 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)1 InvalidProperty (com.vmware.vim.binding.vmodl.query.InvalidProperty)1 FilterSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.FilterSpec)1 ObjectContent (com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectContent)1 ObjectSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectSpec)1 PropertySpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.PropertySpec)1 RetrieveOptions (com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveOptions)1 RetrieveResult (com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult)1 TraversalSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.TraversalSpec)1 ArrayList (java.util.ArrayList)1