/** * Retrieve contents for a single object based on the property collector * registered with the service. * * @param collector * Property collector registered with service * @param mobj * Managed Object Reference to get contents for * @param properties * names of properties of object to retrieve * * @return retrieved object contents * @throws RuntimeFaultFaultMsg * @throws InvalidPropertyFaultMsg */ private ObjectContent[] getObjectProperties(ManagedObjectReference mobj, String[] properties) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { if (mobj == null) { return null; } PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getPropSet().add(new PropertySpec()); if ((properties == null || properties.length == 0)) { spec.getPropSet().get(0).setAll(Boolean.TRUE); } else { spec.getPropSet().get(0).setAll(Boolean.FALSE); } spec.getPropSet().get(0).setType(mobj.getType()); spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties)); spec.getObjectSet().add(new ObjectSpec()); spec.getObjectSet().get(0).setObj(mobj); spec.getObjectSet().get(0).setSkip(Boolean.FALSE); List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1); listpfs.add(spec); List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs); return listobjcont.toArray(new ObjectContent[listobjcont.size()]); }
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps, String[] propsToMatch) { PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(objmor); oSpec.setSkip(Boolean.FALSE); spec.getObjectSet().add(oSpec); Set<String> uniqPropSet = new HashSet<>(Arrays.asList(filterProps)); uniqPropSet.addAll(Arrays.asList(propsToMatch)); PropertySpec pSpec = new PropertySpec(); pSpec.getPathSet().addAll(new ArrayList<>(uniqPropSet)); pSpec.setType(objmor.getType()); spec.getPropSet().add(pSpec); return spec; }
private static void watchManagedObject(ManagedObject mos, String[] propNames) { PropertyFilterSpec pfs = new PropertyFilterSpec(); ObjectSpec[] oss = new ObjectSpec[1]; oss[0] = new ObjectSpec(); oss[0].setObj(mos.getMOR()); pfs.setObjectSet(oss); PropertySpec ps = new PropertySpec(); ps.setType(mos.getMOR().getType()); ps.setPathSet(propNames); pfs.setPropSet(new PropertySpec[] { ps }); try { PropertyFilter pf = propColl.createFilter(pfs, true); //report only nesting properties, not enclosing ones. if (pf != null) { watchedFilters.put(mos, pf); } } catch(RemoteException re) { throw new RuntimeException(re); } }
public void watch(ManagedObject[] mos, String[] propNames) { PropertyFilterSpec pfs = new PropertyFilterSpec(); ObjectSpec[] oss = new ObjectSpec[mos.length]; for(int i=0; i<oss.length; i++) { oss[i] = new ObjectSpec(); oss[i].setObj(mos[i].getMOR()); } pfs.setObjectSet(oss); PropertySpec ps = new PropertySpec(); ps.setType(mos[0].getMOR().getType()); ps.setPathSet(propNames); pfs.setPropSet(new PropertySpec[] { ps }); watch(pfs); }
public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec(); hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem"); hostDsSys2DatastoreTraversal.setPath("datastore"); hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); }
public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec dc2DatastoreTraversal = new TraversalSpec(); dc2DatastoreTraversal.setType("Datacenter"); dc2DatastoreTraversal.setPath("datastore"); dc2DatastoreTraversal.setName("dc2DatastoreTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(dc2DatastoreTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); }
private List<ObjectContent> retrieveMoRefProperties(ManagedObjectReference mObj, List<String> props) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setAll(false); pSpec.setType(mObj.getType()); pSpec.getPathSet().addAll(props); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(mObj); oSpec.setSkip(false); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getPropSet().add(pSpec); spec.getObjectSet().add(oSpec); List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>(); specArr.add(spec); return vimPort.retrieveProperties(getPropCol(), specArr); }
public PropertyFilterSpec createVmFilterSpec(ManagedObjectReference dc) { ObjectSpec ospec = new ObjectSpec(); ospec.setObj(dc); ospec.setSkip(false); ospec.getSelectSet().addAll(buildFullTraversal()); PropertySpec vmSpec = new PropertySpec(); vmSpec.setType(VimNames.TYPE_VM); vmSpec.getPathSet().addAll(Arrays.asList( VimPath.vm_config_name, VimPath.vm_config_instanceUuid, VimPath.vm_config_changeVersion, VimPath.vm_config_hardware_device, VimPath.vm_config_hardware_memoryMB, VimPath.vm_summary_config_numCpu, VimPath.vm_config_template, VimPath.vm_runtime_host, VimPath.vm_guest_net, VimPath.vm_guest_hostName, VimPath.vm_runtime_powerState, VimPath.vm_runtime_maxCpuUsage, VimPath.vm_runtime_maxMemoryUsage, VimPath.vm_summary_guest_ipAddress, VimPath.vm_summary_guest_hostName, VimPath.vm_snapshot_rootSnapshotList )); PropertyFilterSpec filterSpec = new PropertyFilterSpec(); filterSpec.getObjectSet().add(ospec); filterSpec.getPropSet().add(vmSpec); return filterSpec; }
private List<ObjectContent> ancestrySet(ManagedObjectReference ref) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { ObjectSpec ospec = new ObjectSpec(); ospec.setObj(ref); ospec.setSkip(false); TraversalSpec tspec = new TraversalSpec(); tspec.setSkip(false); tspec.setPath("parent"); tspec.setType("ManagedEntity"); tspec.setName("traverseParent"); SelectionSpec selSpec = new SelectionSpec(); selSpec.setName("traverseParent"); tspec.getSelectSet().add(selSpec); ospec.getSelectSet().add(tspec); PropertySpec pspec = new PropertySpec(); pspec.setType("ManagedEntity"); pspec.getPathSet().add("name"); pspec.getPathSet().add("parent"); PropertyFilterSpec filter = new PropertyFilterSpec(); filter.getObjectSet().add(ospec); filter.getPropSet().add(pspec); return this.connection.getVimPort() .retrieveProperties(this.connection.getServiceContent().getPropertyCollector(), Collections.singletonList(filter)); }
private List<Element> listResourcePool() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { ObjectSpec ospec = new ObjectSpec(); ospec.setObj(this.start); ospec.setSkip(true); for (String f : new String[] { "resourcePool" }) { TraversalSpec tspec = new TraversalSpec(); tspec.setPath(f); tspec.setSkip(false); tspec.setType("ResourcePool"); ospec.getSelectSet().add(tspec); } List<PropertySpec> pspecs = new ArrayList<>(); for (String t : new String[] { "ResourcePool" }) { PropertySpec pspec = new PropertySpec(); pspec.setType(t); pspec.getPathSet().add("name"); pspecs.add(pspec); } PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getObjectSet().add(ospec); spec.getPropSet().addAll(pspecs); return callPropertyCollectorAndConvert(spec); }
private List<Element> listComputeResource() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { ObjectSpec ospec = new ObjectSpec(); ospec.setSkip(true); ospec.setObj(this.start); for (String f : new String[] { "host", "resourcePool" }) { TraversalSpec tspec = new TraversalSpec(); tspec.setPath(f); tspec.setType("ComputeResource"); tspec.setSkip(false); ospec.getSelectSet().add(tspec); } PropertyFilterSpec filter = new PropertyFilterSpec(); filter.getObjectSet().add(ospec); for (String t : new String[] { "HostSystem", "ResourcePool" }) { PropertySpec pspec = new PropertySpec(); pspec.setType(t); pspec.getPathSet().add("name"); filter.getPropSet().add(pspec); } return callPropertyCollectorAndConvert(filter); }
private List<Element> listDatacenter() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException { ObjectSpec ospec = new ObjectSpec(); ospec.setObj(this.start); ospec.setSkip(true); // Include every datastore folder in the select set String[] fields = { "vmFolder", "hostFolder", "datastoreFolder", "networkFolder" }; for (String f : fields) { TraversalSpec tspec = new TraversalSpec(); tspec.setPath(f); tspec.setSkip(false); tspec.setType("Datacenter"); ospec.getSelectSet().add(tspec); } PropertySpec pspec = new PropertySpec(); pspec.setType("Folder"); pspec.getPathSet().add("name"); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getObjectSet().add(ospec); spec.getPropSet().add(pspec); return callPropertyCollectorAndConvert(spec); }
private void init() { if (this.propSet == null) { this.propSet = new ArrayList<PropertySpec>(); } if (this.objectSet == null) { this.objectSet = new ArrayList<ObjectSpec>(); } }
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps) { PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(objmor); oSpec.setSkip(Boolean.FALSE); spec.getObjectSet().add(oSpec); PropertySpec pSpec = new PropertySpec(); pSpec.getPathSet().addAll(Arrays.asList(filterProps)); pSpec.setType(objmor.getType()); spec.getPropSet().add(pSpec); return spec; }
private void init() { if (propSet == null) { propSet = new ArrayList<PropertySpec>(); } if(objectSet == null) { objectSet = new ArrayList<ObjectSpec>(); } }
private PropertyFilterSpec createEventFilterSpec(EventHistoryCollector collector) throws Exception { // Set up a PropertySpec to use the latestPage attribute // of the EventHistoryCollector PropertySpec propSpec = new PropertySpec(); propSpec.setAll(new Boolean(false)); propSpec.setPathSet(new String[] { "latestPage" }); propSpec.setType(collector.getMOR().getType()); // PropertySpecs are wrapped in a PropertySpec array PropertySpec[] propSpecAry = new PropertySpec[] { propSpec }; // Set up an ObjectSpec with the above PropertySpec for the // EventHistoryCollector we just created // as the Root or Starting Object to get Attributes for. ObjectSpec objSpec = new ObjectSpec(); objSpec.setObj(collector.getMOR()); objSpec.setSkip(new Boolean(false)); // Get Event objects in "latestPage" from "EventHistoryCollector" // and no "traversal" further, so, no SelectionSpec is specified objSpec.setSelectSet(new SelectionSpec[] {}); // ObjectSpecs are wrapped in an ObjectSpec array ObjectSpec[] objSpecAry = new ObjectSpec[] { objSpec }; PropertyFilterSpec spec = new PropertyFilterSpec(); spec.setPropSet(propSpecAry); spec.setObjectSet(objSpecAry); return spec; }
private PropertyFilterSpec createEventFilterSpec() { // Set up a PropertySpec to use the latestPage attribute // of the EventHistoryCollector PropertySpec propSpec = new PropertySpec(); propSpec.setAll(new Boolean(false)); propSpec.setPathSet(new String[] { "latestPage" }); propSpec.setType(_eventHistoryCollector.getMOR().getType()); // PropertySpecs are wrapped in a PropertySpec array PropertySpec[] propSpecAry = new PropertySpec[] { propSpec }; // Set up an ObjectSpec with the above PropertySpec for the // EventHistoryCollector we just created // as the Root or Starting Object to get Attributes for. ObjectSpec objSpec = new ObjectSpec(); objSpec.setObj(_eventHistoryCollector.getMOR()); objSpec.setSkip(new Boolean(false)); // Get Event objects in "latestPage" from "EventHistoryCollector" // and no "traversl" further, so, no SelectionSpec is specified objSpec.setSelectSet(new SelectionSpec[] {}); // ObjectSpecs are wrapped in an ObjectSpec array ObjectSpec[] objSpecAry = new ObjectSpec[] { objSpec }; PropertyFilterSpec spec = new PropertyFilterSpec(); spec.setPropSet(propSpecAry); spec.setObjectSet(objSpecAry); return spec; }
protected ObjectContent retrieveObjectProperties(String[] properties) { ObjectSpec oSpec = PropertyCollectorUtil.creatObjectSpec( getMOR(), Boolean.FALSE, null); PropertySpec pSpec = PropertyCollectorUtil.createPropertySpec( getMOR().getType(), properties == null || properties.length == 0, //if true, all props of this obj are to be read regardless of propName properties); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.setObjectSet(new ObjectSpec[] { oSpec }); pfSpec.setPropSet(new PropertySpec[] { pSpec }); PropertyCollector pc = getServerConnection().getServiceInstance().getPropertyCollector(); ObjectContent[] objs; try { objs = pc.retrieveProperties(new PropertyFilterSpec[] { pfSpec }); } catch(Exception e) { throw new RuntimeException(e); } if (objs == null || objs[0]==null) return null; else return objs[0]; }
/** * Retrieve contents for a single object based on the property collector * registered with the service. * * @param mor Managed Object Reference to get contents for * @param properties names of properties of object to retrieve * @return retrieved object contents */ @NotNull public static ObjectContent[] getObjectProperties(ConnectionResources connectionResources, ManagedObjectReference mor, String[] properties) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg { if (mor == null) { return new ObjectContent[0]; } PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getPropSet().add(new PropertySpec()); if ((properties == null || properties.length == 0)) { spec.getPropSet().get(0).setAll(true); } else { spec.getPropSet().get(0).setAll(false); } spec.getPropSet().get(0).setType(mor.getType()); spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties)); spec.getObjectSet().add(new ObjectSpec()); spec.getObjectSet().get(0).setObj(mor); spec.getObjectSet().get(0).setSkip(false); List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<>(1); propertyFilterSpecs.add(spec); List<ObjectContent> objectContentList = retrievePropertiesAllObjects(connectionResources, propertyFilterSpecs); return objectContentList.toArray(new ObjectContent[objectContentList.size()]); }
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps) { ObjectSpec objSpec = new ObjectSpec(); objSpec.setObj(objmor); objSpec.setSkip(false); PropertySpec propSpec = new PropertySpec(); propSpec.getPathSet().addAll(Arrays.asList(filterProps)); propSpec.setType(objmor.getType()); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getObjectSet().add(objSpec); spec.getPropSet().add(propSpec); return spec; }
public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("Network"); pSpec.getPathSet().add("summary.name"); TraversalSpec host2NetworkTraversal = new TraversalSpec(); host2NetworkTraversal.setType("HostSystem"); host2NetworkTraversal.setPath("network"); host2NetworkTraversal.setName("host2NetworkTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(host2NetworkTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (ocs != null) { for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { for (DynamicProperty prop : props) { if (prop.getVal().equals(portGroupName)) return oc.getObj(); } } } } return null; }
@Override public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec host2VmTraversal = new TraversalSpec(); host2VmTraversal.setType("HostSystem"); host2VmTraversal.setPath("vm"); host2VmTraversal.setName("host2VmTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(host2VmTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() done"); return properties.toArray(new ObjectContent[properties.size()]); }
@Override public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec host2DatastoreTraversal = new TraversalSpec(); host2DatastoreTraversal.setType("HostSystem"); host2DatastoreTraversal.setPath("datastore"); host2DatastoreTraversal.setName("host2DatastoreTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(host2DatastoreTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() done"); return properties.toArray(new ObjectContent[properties.size()]); }
public List<ObjectContent> getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("HostSystem"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec computeResource2HostTraversal = new TraversalSpec(); computeResource2HostTraversal.setType("ComputeResource"); computeResource2HostTraversal.setPath("host"); computeResource2HostTraversal.setName("computeResource2HostTraversal"); SelectionSpec recurseFolders = new SelectionSpec(); recurseFolders.setName("folder2childEntity"); TraversalSpec folder2childEntity = new TraversalSpec(); folder2childEntity.setType("Folder"); folder2childEntity.setPath("childEntity"); folder2childEntity.setName(recurseFolders.getName()); folder2childEntity.getSelectSet().add(recurseFolders); folder2childEntity.getSelectSet().add(computeResource2HostTraversal); TraversalSpec dc2HostFolderTraversal = new TraversalSpec(); dc2HostFolderTraversal.setType("Datacenter"); dc2HostFolderTraversal.setPath("hostFolder"); dc2HostFolderTraversal.setName("dc2HostFolderTraversal"); dc2HostFolderTraversal.getSelectSet().add(folder2childEntity); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(dc2HostFolderTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); }
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec dc2VmFolderTraversal = new TraversalSpec(); dc2VmFolderTraversal.setType("Datacenter"); dc2VmFolderTraversal.setPath("vmFolder"); dc2VmFolderTraversal.setName("dc2VmFolderTraversal"); SelectionSpec recurseFolders = new SelectionSpec(); recurseFolders.setName("folder2childEntity"); TraversalSpec folder2childEntity = new TraversalSpec(); folder2childEntity.setType("Folder"); folder2childEntity.setPath("childEntity"); folder2childEntity.setName(recurseFolders.getName()); folder2childEntity.getSelectSet().add(recurseFolders); dc2VmFolderTraversal.getSelectSet().add(folder2childEntity); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(dc2VmFolderTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); }
public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context, ManagedObjectReference morEntity) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datacenter"); pSpec.getPathSet().add("name"); TraversalSpec entityParentTraversal = new TraversalSpec(); entityParentTraversal.setType("ManagedEntity"); entityParentTraversal.setPath("parent"); entityParentTraversal.setName("entityParentTraversal"); SelectionSpec selSpec = new SelectionSpec(); selSpec.setName("entityParentTraversal"); entityParentTraversal.getSelectSet().add(selSpec); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(morEntity); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(entityParentTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = context.getService().retrieveProperties(context.getPropertyCollector(), pfSpecArr); assert (ocs != null && ocs.size() > 0); assert (ocs.get(0).getObj() != null); assert (ocs.get(0).getPropSet().get(0) != null); assert (ocs.get(0).getPropSet().get(0).getVal() != null); String dcName = ocs.get(0).getPropSet().get(0).getVal().toString(); return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs.get(0).getObj()), dcName); }
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("DistributedVirtualPortgroup"); pSpec.getPathSet().add("name"); TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec(); datacenter2DvPortGroupTraversal.setType("Datacenter"); datacenter2DvPortGroupTraversal.setPath("network"); datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (ocs != null) { for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { for (DynamicProperty prop : props) { if (prop.getVal().equals(dvPortGroupName)) return oc.getObj(); } } } } return null; }
public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception { String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath); PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); pSpec.getPathSet().add("name"); TraversalSpec vmDatastoreTraversal = new TraversalSpec(); vmDatastoreTraversal.setType("VirtualMachine"); vmDatastoreTraversal.setPath("datastore"); vmDatastoreTraversal.setName("vmDatastoreTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(vmDatastoreTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (ocs != null) { for (ObjectContent oc : ocs) { DynamicProperty prop = oc.getPropSet().get(0); if (prop.getVal().toString().equals(dsName)) { return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName); } } } return null; }
public VirtualMachineFileLayoutEx getFileLayout() throws Exception { VirtualMachineFileLayoutEx fileLayout = null; PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); pSpec.getPathSet().add("layoutEx"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.FALSE); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (ocs != null) { for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { for (DynamicProperty prop : props) { if (prop.getName().equals("layoutEx")) { fileLayout = (VirtualMachineFileLayoutEx)prop.getVal(); break; } } } } } return fileLayout; }
public String[] getNetworks() throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("Network"); pSpec.getPathSet().add("name"); TraversalSpec vm2NetworkTraversal = new TraversalSpec(); vm2NetworkTraversal.setType("VirtualMachine"); vm2NetworkTraversal.setPath("network"); vm2NetworkTraversal.setName("vm2NetworkTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(vm2NetworkTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); List<String> networks = new ArrayList<String>(); if (ocs != null && ocs.size() > 0) { for (ObjectContent oc : ocs) { networks.add(oc.getPropSet().get(0).getVal().toString()); } } return networks.toArray(new String[0]); }
@Override public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec host2VmFolderTraversal = new TraversalSpec(); host2VmFolderTraversal.setType("HostSystem"); host2VmFolderTraversal.setPath("vm"); host2VmFolderTraversal.setName("host2VmFolderTraversal"); TraversalSpec cluster2HostFolderTraversal = new TraversalSpec(); cluster2HostFolderTraversal.setType("ClusterComputeResource"); cluster2HostFolderTraversal.setPath("host"); cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal"); cluster2HostFolderTraversal.getSelectSet().add(host2VmFolderTraversal); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(getMor()); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(cluster2HostFolderTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() done"); return properties.toArray(new ObjectContent[properties.size()]); }
@Override public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec cluster2DatastoreTraversal = new TraversalSpec(); cluster2DatastoreTraversal.setType("ClusterComputeResource"); cluster2DatastoreTraversal.setPath("datastore"); cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(cluster2DatastoreTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() done"); return properties.toArray(new ObjectContent[properties.size()]); }
public ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("HostSystem"); pSpec.getPathSet().addAll(Arrays.asList(propertyPaths)); TraversalSpec cluster2HostTraversal = new TraversalSpec(); cluster2HostTraversal.setType("ClusterComputeResource"); cluster2HostTraversal.setPath("host"); cluster2HostTraversal.setName("cluster2HostTraversal"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(_mor); oSpec.setSkip(Boolean.TRUE); oSpec.getSelectSet().add(cluster2HostTraversal); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.getPropSet().add(pSpec); pfSpec.getObjectSet().add(oSpec); List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>(); pfSpecArr.add(pfSpec); List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - retrieveProperties() done"); return properties.toArray(new ObjectContent[properties.size()]); }
public boolean validate() { // // There is no official API to validate an open vCenter API session. This is hacking way to tell if // an open vCenter API session is still valid for making calls. // // It will give false result if there really does not exist data-center in the inventory, however, I consider // this really is not possible in production deployment // // Create PropertySpecs PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datacenter"); pSpec.setAll(false); pSpec.getPathSet().add("name"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(getRootFolder()); oSpec.setSkip(false); oSpec.getSelectSet().addAll(constructCompleteTraversalSpec()); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getPropSet().add(pSpec); spec.getObjectSet().add(oSpec); List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>(); specArr.add(spec); try { List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr); if (ocary != null && ocary.size() > 0) return true; } catch (Exception e) { return false; } return false; }
/** * Assembles the property specification required to retrieve inventory * information. */ public List<PropertySpec> buildInventoryPropertySpec() { PropertySpec pSpecDatacenter = new PropertySpec(); pSpecDatacenter.setType("Datacenter"); pSpecDatacenter.getPathSet().add("hostFolder"); PropertySpec pSpecHost = new PropertySpec(); pSpecHost.setType("HostSystem"); pSpecHost.getPathSet().add("name"); // ManagedObjectReference[] to a Datastore[] // A collection of references to the subset of datastore objects in the // datacenter that are available in this HostSystem. pSpecHost.getPathSet().add("datastore"); pSpecHost.getPathSet().add("runtime.connectionState"); // connected, // disconnected, // notResponding pSpecHost.getPathSet().add("runtime.powerState"); // poweredOff, // poweredOn, standBy, // unknown pSpecHost.getPathSet().add("runtime.healthSystemRuntime"); pSpecHost.getPathSet().add("summary.hardware.cpuMhz"); pSpecHost.getPathSet().add("summary.hardware.memorySize"); pSpecHost.getPathSet().add("summary.hardware.numCpuCores"); pSpecHost.getPathSet().add("summary.quickStats.distributedCpuFairness"); pSpecHost.getPathSet() .add("summary.quickStats.distributedMemoryFairness"); pSpecHost.getPathSet().add("summary.quickStats.overallCpuUsage"); pSpecHost.getPathSet().add("summary.quickStats.overallMemoryUsage"); PropertySpec pSpecVM = new PropertySpec(); pSpecVM.setType("VirtualMachine"); pSpecVM.getPathSet().add("name"); pSpecVM.getPathSet().add("runtime.host"); pSpecVM.getPathSet().add("summary.config.template"); pSpecVM.getPathSet().add("summary.config.numCpu"); pSpecVM.getPathSet().add("summary.config.memorySizeMB"); PropertySpec pSpecDataStore = new PropertySpec(); pSpecDataStore.setType("Datastore"); // DatastoreHostMount[] Hosts attached to this datastore. pSpecDataStore.getPathSet().add("host"); pSpecDataStore.getPathSet().add("summary.name"); pSpecDataStore.getPathSet().add("summary.capacity"); pSpecDataStore.getPathSet().add("summary.freeSpace"); ArrayList<PropertySpec> result = new ArrayList<PropertySpec>(); result.add(pSpecDatacenter); result.add(pSpecHost); result.add(pSpecVM); result.add(pSpecDataStore); return result; }
private List<Element> listFolder() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException { PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec objSpec = new ObjectSpec(); objSpec.setObj(this.start); TraversalSpec selectionSpec = new TraversalSpec(); selectionSpec.setPath("childEntity"); selectionSpec.setType("Folder"); selectionSpec.setSkip(false); objSpec.getSelectSet().add(selectionSpec); spec.getObjectSet().add(objSpec); // Retrieve all objects that we can deal with String[] childTypes = { "Folder", "Datacenter", "VirtualMachine", "Network", "ComputeResource", "ClusterComputeResource", "Datastore"}; for (String t : childTypes) { PropertySpec pspec = new PropertySpec(); pspec.setType(t); pspec.getPathSet().add("name"); // Additional basic properties. if (t.equals("ComputeResource") || t.equals("ClusterComputeResource")) { // The ComputeResource and ClusterComputeResource are dereferenced in // the ResourcePoolFlag. Make sure they always have their resourcePool // field populated. pspec.getPathSet().add("resourcePool"); } spec.getPropSet().add(pspec); } return callPropertyCollectorAndConvert(spec); }
public List<Element> listAllDatacenters() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec ospec = new ObjectSpec(); ospec.setObj(connection.getServiceContent().getRootFolder()); ospec.setSkip(false); spec.getObjectSet().add(ospec); TraversalSpec traverseFolders = new TraversalSpec(); traverseFolders.setPath("childEntity"); traverseFolders.setSkip(false); String traversalName = "folder2child"; traverseFolders.setName(traversalName); traverseFolders.setType(VimNames.TYPE_FOLDER); SelectionSpec selSpec = new SelectionSpec(); selSpec.setName(traversalName); traverseFolders.getSelectSet().add(selSpec); ospec.getSelectSet().add(traverseFolders); for (String t : new String[] { VimNames.TYPE_FOLDER, VimNames.TYPE_DATACENTER }) { PropertySpec pspec = new PropertySpec(); pspec.setType(t); pspec.getPathSet().add(VimNames.PROPERTY_NAME); pspec.getPathSet().add(VimNames.PROPERTY_PARENT); spec.getPropSet().add(pspec); } List<ObjectContent> ocs = retrieveProperties(spec); List<Element> res = new ArrayList<>(); for (ObjectContent oc : ocs) { if (oc.getObj().getType().equals(VimNames.TYPE_FOLDER)) { continue; } String parentPath = buildPathToParent(prop(oc, VimNames.PROPERTY_PARENT), ocs); res.add(Element.make(oc.getObj(), parentPath + "/" + prop(oc, VimNames.PROPERTY_NAME))); } return res; }
/** * 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; }