use of com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder in project photon-model by vmware.
the class GetMoRef method entityProps.
/**
* Method to retrieve properties of list of {@link ManagedObjectReference}
*
* @param entityMors List of {@link ManagedObjectReference} for which the properties
* needs to be retrieved
* @param props Common properties that need to be retrieved for all the
* {@link ManagedObjectReference} passed
* @return Map of {@link ManagedObjectReference} and their corresponding name
* value pair of properties
* @throws InvalidPropertyFaultMsg
* @throws RuntimeFaultFaultMsg
*/
public Map<ManagedObjectReference, Map<String, Object>> entityProps(List<ManagedObjectReference> entityMors, String[] props) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
init();
Map<ManagedObjectReference, Map<String, Object>> retVal = new HashMap<ManagedObjectReference, Map<String, Object>>();
// Create PropertyFilterSpec
PropertyFilterSpecBuilder propertyFilterSpec = new PropertyFilterSpecBuilder();
Map<String, String> typesCovered = new HashMap<String, String>();
for (ManagedObjectReference mor : entityMors) {
if (!typesCovered.containsKey(mor.getType())) {
// Create & add new property Spec
propertyFilterSpec.propSet(new PropertySpecBuilder().all(Boolean.FALSE).type(mor.getType()).pathSet(props));
typesCovered.put(mor.getType(), "");
}
// Now create & add Object Spec
propertyFilterSpec.objectSet(new ObjectSpecBuilder().obj(mor));
}
List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<PropertyFilterSpec>();
propertyFilterSpecs.add(propertyFilterSpec);
RetrieveResult rslts = this.vimPort.retrievePropertiesEx(this.serviceContent.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions());
List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();
String token = populate(rslts, listobjcontent);
while (token != null && !token.isEmpty()) {
rslts = this.vimPort.continueRetrievePropertiesEx(this.serviceContent.getPropertyCollector(), token);
token = populate(rslts, listobjcontent);
}
for (ObjectContent oc : listobjcontent) {
List<DynamicProperty> dps = oc.getPropSet();
Map<String, Object> propMap = new HashMap<String, Object>();
if (dps != null) {
for (DynamicProperty dp : dps) {
propMap.put(dp.getName(), dp.getVal());
}
}
retVal.put(oc.getObj(), propMap);
}
return retVal;
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder in project photon-model by vmware.
the class GetMoRef method propertyFilterSpecs.
public PropertyFilterSpec[] propertyFilterSpecs(ManagedObjectReference container, String morefType, String... morefProperties) throws RuntimeFaultFaultMsg {
init();
ManagedObjectReference viewManager = this.serviceContent.getViewManager();
ManagedObjectReference containerView = this.vimPort.createContainerView(viewManager, container, Arrays.asList(morefType), true);
return new PropertyFilterSpec[] { new PropertyFilterSpecBuilder().propSet(new PropertySpecBuilder().all(Boolean.FALSE).type(morefType).pathSet(morefProperties)).objectSet(new ObjectSpecBuilder().obj(containerView).skip(Boolean.TRUE).selectSet(new TraversalSpecBuilder().name("view").path("view").skip(false).type("ContainerView"))) };
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder in project photon-model by vmware.
the class GetMoRef method vmByVMname.
/**
* Get the MOR of the Virtual Machine by its name.
*
* @param vmName The name of the Virtual Machine
* @param propCollectorRef
* @return The Managed Object reference for this VM
* @throws RuntimeFaultFaultMsg
* @throws InvalidPropertyFaultMsg
*/
public ManagedObjectReference vmByVMname(final String vmName, final ManagedObjectReference propCollectorRef) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
init();
ManagedObjectReference rootFolder = this.serviceContent.getRootFolder();
TraversalSpec tSpec = getVMTraversalSpec();
// Create Property Spec
PropertySpec propertySpec = new PropertySpecBuilder().all(Boolean.FALSE).pathSet("name").type("VirtualMachine");
// Now create Object Spec
ObjectSpec objectSpec = new ObjectSpecBuilder().obj(rootFolder).skip(Boolean.TRUE).selectSet(tSpec);
// Create PropertyFilterSpec using the PropertySpec and ObjectPec
// created above.
PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpecBuilder().propSet(propertySpec).objectSet(objectSpec);
List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
listpfs.add(propertyFilterSpec);
RetrieveOptions options = new RetrieveOptions();
// Query returns a fixed number of results
// if token is returned we can get more results
RetrieveResult retrieveResult = this.vimPort.retrievePropertiesEx(propCollectorRef, listpfs, options);
String token = null;
do {
token = (retrieveResult != null) ? retrieveResult.getToken() : null;
List<ObjectContent> listobcont = (retrieveResult != null) ? retrieveResult.getObjects() : null;
if (listobcont != null) {
for (ObjectContent oc : listobcont) {
ManagedObjectReference mr = oc.getObj();
String vmnm = null;
List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) {
for (DynamicProperty dp : dps) {
vmnm = (String) dp.getVal();
if (vmName.equals(vmnm)) {
return mr;
}
}
}
}
}
if (token != null) {
retrieveResult = this.vimPort.continueRetrievePropertiesEx(propCollectorRef, token);
}
} while (token != null);
return null;
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder in project photon-model by vmware.
the class GetMoRef method entityProps.
/**
* 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 {
init();
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(Boolean.FALSE).type(entityMor.getType()).pathSet(props)).objectSet(// Now create Object Spec
new ObjectSpecBuilder().obj(entityMor)) };
List<ObjectContent> oCont = this.vimPort.retrievePropertiesEx(this.serviceContent.getPropertyCollector(), Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();
if (oCont != null) {
for (ObjectContent oc : oCont) {
List<DynamicProperty> dps = oc.getPropSet();
for (DynamicProperty dp : dps) {
retVal.put(dp.getName(), dp.getVal());
}
}
}
return retVal;
}
Aggregations