use of com.vmware.vim25.RetrieveResult in project photon-model by vmware.
the class GetMoRef method inFolderByType.
/**
* Returns all the MOREFs of the specified type that are present under the
* folder
*
* @param folder {@link ManagedObjectReference} of the folder to begin the search
* from
* @param morefType Type of the managed entity that needs to be searched
* @return Map of name and MOREF of the managed objects present. If none
* exist then empty Map is returned
* @throws InvalidPropertyFaultMsg
*
* @throws RuntimeFaultFaultMsg
*/
public Map<String, ManagedObjectReference> inFolderByType(final ManagedObjectReference folder, final String morefType, final RetrieveOptions retrieveOptions) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
final PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(folder, morefType, "name");
// reuse this property collector again later to scroll through results
final ManagedObjectReference propertyCollector = this.serviceContent.getPropertyCollector();
RetrieveResult results = this.vimPort.retrievePropertiesEx(propertyCollector, Arrays.asList(propertyFilterSpecs), retrieveOptions);
final Map<String, ManagedObjectReference> tgtMoref = new HashMap<>();
while (results != null && !results.getObjects().isEmpty()) {
resultsToTgtMorefMap(results, tgtMoref);
final String token = results.getToken();
// if we have a token, we can scroll through additional results, else there's nothing to do.
results = (token != null) ? this.vimPort.continueRetrievePropertiesEx(propertyCollector, token) : null;
}
return tgtMoref;
}
use of com.vmware.vim25.RetrieveResult 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.vim25.RetrieveResult in project photon-model by vmware.
the class GetMoRef method resultsToTgtMorefMap.
private void resultsToTgtMorefMap(RetrieveResult results, Map<String, ManagedObjectReference> tgtMoref) {
List<ObjectContent> oCont = (results != null) ? results.getObjects() : null;
if (oCont != null) {
for (ObjectContent oc : oCont) {
ManagedObjectReference mr = oc.getObj();
String entityNm = null;
List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) {
for (DynamicProperty dp : dps) {
entityNm = (String) dp.getVal();
}
}
tgtMoref.put(entityNm, mr);
}
}
}
use of com.vmware.vim25.RetrieveResult in project photon-model by vmware.
the class GetMoRef method inContainerByType.
/**
* Returns all the MOREFs of the specified type that are present under the
* container
*
* @param folder {@link ManagedObjectReference} of the container to begin the
* search from
* @param morefType Type of the managed entity that needs to be searched
* @return Map of name and MOREF of the managed objects present. If none
* exist then empty Map is returned
* @throws InvalidPropertyFaultMsg
* @throws RuntimeFaultFaultMsg
*/
public Map<String, ManagedObjectReference> inContainerByType(ManagedObjectReference folder, String morefType, RetrieveOptions retrieveOptions) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
init();
RetrieveResult rslts = containerViewByType(folder, morefType, retrieveOptions);
return toMap(rslts);
}
use of com.vmware.vim25.RetrieveResult 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;
}
Aggregations