use of com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult 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);
}
}
use of com.vmware.vim.binding.vmodl.query.PropertyCollector.RetrieveResult 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;
}
Aggregations