Search in sources :

Example 1 with PropertySpec

use of com.vmware.vim.binding.vmodl.query.PropertyCollector.PropertySpec in project flowgate by vmware.

the class InventoryService method handleObjectContent.

public void handleObjectContent(PropertyCollector propertyCollector, ManagedObjectReference containerView, String typeName, ObjectContentCallback action) {
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setType(new TypeNameImpl(typeName));
    propertySpec.setAll(true);
    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 });
    RetrieveResult retrieveResult = null;
    try {
        retrieveResult = propertyCollector.retrievePropertiesEx(new FilterSpec[] { filterSpec }, new RetrieveOptions());
    } catch (InvalidProperty ex) {
        logger.error("Invalid property", ex);
        return;
    }
    if (retrieveResult == null) {
        logger.info("No any result found for type {}", typeName);
        return;
    }
    // logger.debug("RetrieveResult \n{}", retrieveResult);
    ObjectContent[] objects = retrieveResult.getObjects();
    if ((objects == null) || (objects.length == 0)) {
        logger.info("No any object found for type {}", typeName);
        return;
    }
    for (ObjectContent object : objects) {
        action.handle(object);
    }
}
Also used : 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) 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) RetrieveResult(com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult) InvalidProperty(com.vmware.vim.binding.vmodl.query.InvalidProperty)

Example 2 with PropertySpec

use of com.vmware.vim.binding.vmodl.query.PropertyCollector.PropertySpec 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)2 InvalidProperty (com.vmware.vim.binding.vmodl.query.InvalidProperty)2 FilterSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.FilterSpec)2 ObjectContent (com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectContent)2 ObjectSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.ObjectSpec)2 PropertySpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.PropertySpec)2 RetrieveOptions (com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveOptions)2 RetrieveResult (com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult)2 TraversalSpec (com.vmware.vim.binding.vmodl.query.PropertyCollector.TraversalSpec)2 DynamicProperty (com.vmware.vim.binding.vmodl.DynamicProperty)1 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)1 ArrayList (java.util.ArrayList)1