com.vmware.vim25.ObjectSpec Java Examples
The following examples show how to use
com.vmware.vim25.ObjectSpec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagedObjectAccessor.java From development with Apache License 2.0 | 6 votes |
/** * 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()]); }
Example #2
Source File: VmwareClient.java From cloudstack with Apache License 2.0 | 6 votes |
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); }
Example #3
Source File: HostDatastoreSystemMO.java From cloudstack with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 6 votes |
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); }
Example #5
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example #6
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public List<DatastoreMO> getAllDatastores() throws Exception { 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); List<DatastoreMO> datastores = new ArrayList<DatastoreMO>(); if (CollectionUtils.isNotEmpty(ocs)) { for (ObjectContent oc : ocs) { datastores.add(new DatastoreMO(_context, oc.getObj())); } } return datastores; }
Example #7
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
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]); }
Example #8
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example #9
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example #10
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example #11
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example #12
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example #13
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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); }
Example #14
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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); }
Example #15
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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); }
Example #16
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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()]); }
Example #17
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example #18
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example #19
Source File: VmwareClient.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example #20
Source File: WaitForValues.java From cs-actions with Apache License 2.0 | 5 votes |
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; }
Example #21
Source File: GetObjectProperties.java From cs-actions with Apache License 2.0 | 5 votes |
/** * 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()]); }
Example #22
Source File: Utils.java From GraphiteReceiver with Apache License 2.0 | 5 votes |
private static RetrieveResult getRetrieveResult(String clusterName, VimConnection connection, ManagedObjectReference rootFolder) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg { List<String> clusterList = new ArrayList<String>(); clusterList.add("ComputeResource"); clusterList.add("HostSystem"); clusterList.add("VirtualMachine"); ManagedObjectReference rootFolderAux = (clusterName == null)? connection.getRootFolder():rootFolder; ManagedObjectReference viewManager = connection.getVimPort().createContainerView(connection.getViewManager(), rootFolderAux, clusterList, true); if(viewManager == null) { logger.debug("cViewRef is null: " + clusterName); return null; } logger.debug("cViewRef is not null: " + clusterName); ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(viewManager); objectSpec.setSkip(true); objectSpec.getSelectSet().add(getTraversalSpec(clusterName)); PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getObjectSet().add(objectSpec); if(clusterName == null){ propertyFilterSpec.getPropSet().add(getPropertySpec("ComputeResource")); }else{ propertyFilterSpec.getPropSet().add(getPropertySpec("HostSystem")); propertyFilterSpec.getPropSet().add(getPropertySpec("VirtualMachine")); } List<PropertyFilterSpec> propertyFilterSpecs = new LinkedList<PropertyFilterSpec>(); propertyFilterSpecs.add(propertyFilterSpec); return connection.getVimPort().retrievePropertiesEx(connection.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions()); }
Example #23
Source File: WaitForValues.java From vsphere-automation-sdk-java with MIT License | 5 votes |
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; }
Example #24
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 4 votes |
private static Object[] waitForValues(VMwareConnection connection, ManagedObjectReference morObj, String[] filterProps, String[] endWaitProps, Object[][] expectedVals) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg { String version = ""; Object[] endVals = new Object[endWaitProps.length]; Object[] filterVals = new Object[filterProps.length]; PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(morObj); oSpec.setSkip(Boolean.FALSE); spec.getObjectSet().add(oSpec); PropertySpec pSpec = new PropertySpec(); pSpec.getPathSet().addAll(Arrays.asList(filterProps)); pSpec.setType(morObj.getType()); spec.getPropSet().add(pSpec); ManagedObjectReference propertyCollector = connection.getServiceContent().getPropertyCollector(); ManagedObjectReference filterSpecRef = connection.getVimPortType().createFilter(propertyCollector, spec, true); boolean reached = false; UpdateSet updateSet; List<PropertyFilterUpdate> lstPropertyFilterUpdates; List<ObjectUpdate> lstObjectUpdates; List<PropertyChange> lstPropertyChanges; while (!reached) { updateSet = connection.getVimPortType().waitForUpdates(propertyCollector, version); if (updateSet == null || updateSet.getFilterSet() == null) { continue; } version = updateSet.getVersion(); lstPropertyFilterUpdates = updateSet.getFilterSet(); for (PropertyFilterUpdate propertyFilterUpdate : lstPropertyFilterUpdates) { lstObjectUpdates = propertyFilterUpdate.getObjectSet(); for (ObjectUpdate objUpdate : lstObjectUpdates) { if (objUpdate.getKind() == ObjectUpdateKind.MODIFY || objUpdate.getKind() == ObjectUpdateKind.ENTER || objUpdate.getKind() == ObjectUpdateKind.LEAVE) { lstPropertyChanges = objUpdate.getChangeSet(); for (PropertyChange propchg : lstPropertyChanges) { updateValues(endWaitProps, endVals, propchg); updateValues(filterProps, filterVals, propchg); } } } } Object expectedValue; // Check if the expected values have been reached and exit the loop if done. // Also, exit the WaitForUpdates loop if this is the case. for (int chgi = 0; chgi < endVals.length && !reached; chgi++) { for (int vali = 0; vali < expectedVals[chgi].length && !reached; vali++) { expectedValue = expectedVals[chgi][vali]; reached = expectedValue.equals(endVals[chgi]) || reached; } } } // Destroy the filter when we are done. connection.getVimPortType().destroyPropertyFilter(filterSpecRef); return filterVals; }
Example #25
Source File: VmwareClient.java From cloudstack with Apache License 2.0 | 4 votes |
/** * Get the ManagedObjectReference for an item under the * specified root folder that has the type and name specified. * * @param root a root folder if available, or null for default * @param type type of the managed object * @param name name to match * * @return First ManagedObjectReference of the type / name pair found */ public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, String type, String name) throws Exception { if (name == null || name.length() == 0) { return null; } try { // Create PropertySpecs PropertySpec pSpec = new PropertySpec(); pSpec.setType(type); pSpec.setAll(false); pSpec.getPathSet().add("name"); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(root); 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); ManagedObjectReference propCollector = getPropCol(); List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr); if (ocary == null || ocary.size() == 0) { return null; } // filter through retrieved objects to get the first match. for (ObjectContent oc : ocary) { ManagedObjectReference mor = oc.getObj(); List<DynamicProperty> propary = oc.getPropSet(); if (type == null || type.equals(mor.getType())) { if (propary.size() > 0) { String propval = (String)propary.get(0).getVal(); if (propval != null && name.equalsIgnoreCase(propval)) return mor; } } } } catch (InvalidPropertyFaultMsg invalidPropertyException) { s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage()); throw invalidPropertyException; } catch (RuntimeFaultFaultMsg runtimeFaultException) { s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage()); throw runtimeFaultException; } return null; }
Example #26
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 4 votes |
public static Map<String, ManagedObjectReference> getVms(VMwareConnection connection) throws Exception { Map<String, ManagedObjectReference> nameToVm = new HashMap<>(); ManagedObjectReference rootFolder = connection.getServiceContent().getRootFolder(); TraversalSpec tSpec = getVMTraversalSpec(); PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.getPathSet().add("name"); propertySpec.setType("VirtualMachine"); ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(rootFolder); objectSpec.setSkip(Boolean.TRUE); objectSpec.getSelectSet().add(tSpec); PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec); List<PropertyFilterSpec> lstPfs = new ArrayList<>(1); lstPfs.add(propertyFilterSpec); VimPortType vimPortType = connection.getVimPortType(); ManagedObjectReference propertyCollector = connection.getServiceContent().getPropertyCollector(); List<ObjectContent> lstObjectContent = retrievePropertiesAllObjects(lstPfs, vimPortType, propertyCollector); if (lstObjectContent != null) { for (ObjectContent oc : lstObjectContent) { ManagedObjectReference mor = oc.getObj(); List<DynamicProperty> dps = oc.getPropSet(); String vmName = null; if (dps != null) { for (DynamicProperty dp : dps) { vmName = (String)dp.getVal(); } } if (vmName != null) { nameToVm.put(vmName, mor); } } } return nameToVm; }
Example #27
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 4 votes |
public static Map<String, Object> getEntityProps(VMwareConnection connection, ManagedObjectReference entityMor, String[] props) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { Map<String, Object> retVal = new HashMap<>(); PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.setType(entityMor.getType()); propertySpec.getPathSet().addAll(Arrays.asList(props)); ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(entityMor); // Create PropertyFilterSpec using the PropertySpec and ObjectPec created above. PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec); List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<>(); propertyFilterSpecs.add(propertyFilterSpec); RetrieveResult rslts = connection.getVimPortType().retrievePropertiesEx(connection.getServiceContent().getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions()); List<ObjectContent> listobjcontent = new ArrayList<>(); if (rslts != null && rslts.getObjects() != null && !rslts.getObjects().isEmpty()) { listobjcontent.addAll(rslts.getObjects()); } String token = null; if (rslts != null && rslts.getToken() != null) { token = rslts.getToken(); } while (token != null && !token.isEmpty()) { rslts = connection.getVimPortType().continueRetrievePropertiesEx(connection.getServiceContent().getPropertyCollector(), token); token = null; if (rslts != null) { token = rslts.getToken(); if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) { listobjcontent.addAll(rslts.getObjects()); } } } for (ObjectContent oc : listobjcontent) { List<DynamicProperty> dps = oc.getPropSet(); if (dps != null) { for (DynamicProperty dp : dps) { retVal.put(dp.getName(), dp.getVal()); } } } return retVal; }
Example #28
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 4 votes |
public List<NetworkDetails> getNetworksWithDetails() throws Exception { List<NetworkDetails> networks = new ArrayList<NetworkDetails>(); int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC); if (gcTagKey == 0) { gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey); } PropertySpec pSpec = new PropertySpec(); pSpec.setType("Network"); pSpec.getPathSet().add("name"); pSpec.getPathSet().add("vm"); pSpec.getPathSet().add(String.format("value[%d]", gcTagKey)); 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); if (ocs != null && ocs.size() > 0) { for (ObjectContent oc : ocs) { ArrayOfManagedObjectReference morVms = null; String gcTagValue = null; String name = null; for (DynamicProperty prop : oc.getPropSet()) { if (prop.getName().equals("name")) name = prop.getVal().toString(); else if (prop.getName().equals("vm")) morVms = (ArrayOfManagedObjectReference)prop.getVal(); else if (prop.getName().startsWith("value[")) { CustomFieldStringValue val = (CustomFieldStringValue)prop.getVal(); if (val != null) gcTagValue = val.getValue(); } } NetworkDetails details = new NetworkDetails(name, oc.getObj(), (morVms != null ? morVms.getManagedObjectReference().toArray( new ManagedObjectReference[morVms.getManagedObjectReference().size()]) : null), gcTagValue); networks.add(details); } s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey); } return networks; }
Example #29
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 4 votes |
public String getSnapshotDescriptorDatastorePath() throws Exception { PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); pSpec.getPathSet().add("name"); pSpec.getPathSet().add("config.files"); 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); assert (ocs != null); String vmName = null; VirtualMachineFileInfo fileInfo = null; assert (ocs.size() == 1); for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { assert (props.size() == 2); for (DynamicProperty prop : props) { if (prop.getName().equals("name")) { vmName = prop.getVal().toString(); } else { fileInfo = (VirtualMachineFileInfo)prop.getVal(); } } } } assert (vmName != null); assert (fileInfo != null); // .vmsd file exists at the same directory of .vmx file DatastoreFile vmxFile = new DatastoreFile(fileInfo.getVmPathName()); return vmxFile.getCompanionPath(vmName + ".vmsd"); }
Example #30
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 4 votes |
public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception { DVPortgroupConfigInfo configSpec = null; String nameProperty = null; PropertySpec pSpec = new PropertySpec(); pSpec.setType("DistributedVirtualPortgroup"); pSpec.getPathSet().add("name"); pSpec.getPathSet().add("config"); 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) { assert (props.size() == 2); for (DynamicProperty prop : props) { if (prop.getName().equals("config")) { configSpec = (DVPortgroupConfigInfo)prop.getVal(); } else { nameProperty = prop.getVal().toString(); } } if (nameProperty.equalsIgnoreCase(dvPortGroupName)) { return configSpec; } } } } return null; }