com.vmware.vim25.ObjectContent Java Examples
The following examples show how to use
com.vmware.vim25.ObjectContent.
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: 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 #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: 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 #4
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 6 votes |
public ManagedObjectReference getMorHost(String hostname, ConnectionResources connectionResources, ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { ManagedObjectReference host = null; if (isNotBlank(hostname)) { host = getManagedObjectReference(hostname, connectionResources, ManagedObjectType.HOST_SYSTEM.getValue(), ErrorMessages.HOST_NOT_FOUND); } else if (StringUtils.isBlank(hostname) && vmMor != null) { ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor, new String[]{ManagedObjectType.SUMMARY.getValue()}); for (ObjectContent objectItem : objectContents) { List<DynamicProperty> vmProperties = objectItem.getPropSet(); for (DynamicProperty propertyItem : vmProperties) { VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal(); host = virtualMachineSummary.getRuntime().getHost(); break; } break; } } else { host = connectionResources.getHostMor(); } return host; }
Example #5
Source File: MoRefHandler.java From cs-actions with Apache License 2.0 | 6 votes |
/** * 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 { 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(false).type(entityMor.getType()).pathSet(props)) .objectSet( // Now create Object Spec new ObjectSpecBuilder().obj(entityMor))}; List<ObjectContent> objCont = vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(), Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects(); if (objCont != null) { for (ObjectContent oc : objCont) { List<DynamicProperty> dps = oc.getPropSet(); for (DynamicProperty dp : dps) { retVal.put(dp.getName(), dp.getVal()); } } } return retVal; }
Example #6
Source File: MoRefHandler.java From cs-actions with Apache License 2.0 | 6 votes |
private static String populate(final RetrieveResult results, final Map<String, ManagedObjectReference> tgtMoref) { String token = null; if (results != null) { token = results.getToken(); for (ObjectContent oc : results.getObjects()) { 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); } } return token; }
Example #7
Source File: HostDatastoreSystemMO.java From cloudstack with Apache License 2.0 | 6 votes |
public ManagedObjectReference findDatastore(String name) throws Exception { // added Apache CloudStack specific name convention, we will use custom field "cloud.uuid" as datastore name as well CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager()); int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID); assert (key != 0); List<ObjectContent> ocs = getDatastorePropertiesOnHostDatastoreSystem(new String[] {"name", String.format("value[%d]", key)}); if (ocs != null) { for (ObjectContent oc : ocs) { if (oc.getPropSet().get(0).getVal().equals(name)) return oc.getObj(); if (oc.getPropSet().size() > 1) { DynamicProperty prop = oc.getPropSet().get(1); if (prop != null && prop.getVal() != null) { if (prop.getVal() instanceof CustomFieldStringValue) { String val = ((CustomFieldStringValue)prop.getVal()).getValue(); if (val.equalsIgnoreCase(name)) return oc.getObj(); } } } } } return null; }
Example #8
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 #9
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 6 votes |
@Override public String getHyperHostDefaultGateway() throws Exception { ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"config.network.routeTableInfo.ipRoute"}); if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { ArrayOfHostIpRouteEntry entries = (ArrayOfHostIpRouteEntry)oc.getPropSet().get(0).getVal(); if (entries != null) { for (HostIpRouteEntry entry : entries.getHostIpRouteEntry()) { if (entry.getNetwork().equalsIgnoreCase("0.0.0.0")) return entry.getGateway(); } } } } throw new Exception("Could not find host default gateway, host is not properly configured?"); }
Example #10
Source File: HostMO.java From cloudstack with Apache License 2.0 | 6 votes |
public List<Pair<ManagedObjectReference, String>> getLocalDatastoreOnHost() throws Exception { List<Pair<ManagedObjectReference, String>> dsList = new ArrayList<Pair<ManagedObjectReference, String>>(); ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"name", "summary"}); if (ocs != null) { for (ObjectContent oc : ocs) { DatastoreSummary dsSummary = (DatastoreSummary)VmwareHelper.getPropValue(oc, "summary"); if (dsSummary.isMultipleHostAccess() == false && dsSummary.isAccessible() && dsSummary.getType().equalsIgnoreCase("vmfs")) { ManagedObjectReference morDs = oc.getObj(); String name = (String)VmwareHelper.getPropValue(oc, "name"); if (!name.startsWith("-iqn.") && !name.startsWith("_iqn.")) { dsList.add(new Pair<ManagedObjectReference, String>(morDs, name)); } } } } return dsList; }
Example #11
Source File: HypervisorHostHelper.java From cloudstack with Apache License 2.0 | 6 votes |
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, ObjectContent[] ocs, String name, String instanceNameCustomField) { if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { String vmNameInvCenter = null; String vmInternalCSName = null; List<DynamicProperty> objProps = oc.getPropSet(); if (objProps != null) { for (DynamicProperty objProp : objProps) { if (objProp.getName().equals("name")) { vmNameInvCenter = (String)objProp.getVal(); } else if (objProp.getName().contains(instanceNameCustomField)) { if (objProp.getVal() != null) vmInternalCSName = ((CustomFieldStringValue)objProp.getVal()).getValue(); } if ((vmNameInvCenter != null && name.equalsIgnoreCase(vmNameInvCenter)) || (vmInternalCSName != null && name.equalsIgnoreCase(vmInternalCSName))) { VirtualMachineMO vmMo = new VirtualMachineMO(context, oc.getObj()); return vmMo; } } } } } return null; }
Example #12
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 #13
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 #14
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath); ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"info"}); if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { DatastoreInfo dsInfo = (DatastoreInfo)oc.getPropSet().get(0).getVal(); if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) { NasDatastoreInfo info = (NasDatastoreInfo)dsInfo; if (info != null) { String vmwareUrl = info.getUrl(); if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/') vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1); URI uri = new URI(vmwareUrl); if (uri.getPath().equals("/" + exportPath)) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)"); return oc.getObj(); } } } } } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)"); return null; }
Example #15
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 #16
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public ManagedObjectReference findDatastore(String poolUuid) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.getValue() + ", poolUuid: " + poolUuid); CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager()); int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID); assert (key != 0); ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"name", String.format("value[%d]", key)}); if (ocs != null) { for (ObjectContent oc : ocs) { if (oc.getPropSet().get(0).getVal().equals(poolUuid)) return oc.getObj(); if (oc.getPropSet().size() > 1) { DynamicProperty prop = oc.getPropSet().get(1); if (prop != null && prop.getVal() != null) { if (prop.getVal() instanceof CustomFieldStringValue) { String val = ((CustomFieldStringValue)prop.getVal()).getValue(); if (val.equalsIgnoreCase(poolUuid)) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastore() done(successfully)"); return oc.getObj(); } } } } } } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastore() done(failed)"); return null; }
Example #17
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 #18
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 #19
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public ManagedObjectReference findDatastore(String name) throws Exception { assert (name != null); List<ObjectContent> ocs = getDatastorePropertiesOnDatacenter(new String[] {"name"}); if (ocs != null) { for (ObjectContent oc : ocs) { if (oc.getPropSet().get(0).getVal().toString().equals(name)) { return oc.getObj(); } } } return null; }
Example #20
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public VirtualMachineMO findVmOnHyperHost(String name) throws Exception { int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] {"name", instanceNameCustomField}); return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name, instanceNameCustomField); }
Example #21
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public List<Pair<ManagedObjectReference, String>> getAllVmsOnDatacenter() throws Exception { List<Pair<ManagedObjectReference, String>> vms = new ArrayList<Pair<ManagedObjectReference, String>>(); List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name"}); if (ocs != null) { for (ObjectContent oc : ocs) { String vmName = oc.getPropSet().get(0).getVal().toString(); vms.add(new Pair<ManagedObjectReference, String>(oc.getObj(), vmName)); } } return vms; }
Example #22
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public VirtualMachineMO checkIfVmAlreadyExistsInVcenter(String vmNameOnVcenter, String vmNameInCS) throws Exception { int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name", String.format("value[%d]", key)}); if (ocs != null && ocs.size() > 0) { for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { String vmVcenterName = null; String vmInternalCSName = null; for (DynamicProperty prop : props) { if (prop.getName().equals("name")) { vmVcenterName = prop.getVal().toString(); } if (prop.getName().startsWith("value[") && prop.getVal() != null) { vmInternalCSName = ((CustomFieldStringValue)prop.getVal()).getValue(); } } if (vmNameOnVcenter.equals(vmVcenterName)) { if (vmInternalCSName != null && !vmInternalCSName.isEmpty() && !vmNameInCS.equals(vmInternalCSName)) { return (new VirtualMachineMO(_context, oc.getObj())); } } } } } return null; }
Example #23
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public List<VirtualMachineMO> findVmByNameAndLabel(String vmLabel) throws Exception { CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager()); int key = cfmMo.getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_UUID); assert (key != 0); List<VirtualMachineMO> list = new ArrayList<VirtualMachineMO>(); List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name", String.format("value[%d]", key)}); if (ocs != null && ocs.size() > 0) { for (ObjectContent oc : ocs) { List<DynamicProperty> props = oc.getPropSet(); if (props != null) { for (DynamicProperty prop : props) { if (prop.getVal() != null) { if (prop.getName().equalsIgnoreCase("name")) { if (prop.getVal().toString().equals(vmLabel)) { list.add(new VirtualMachineMO(_context, oc.getObj())); break; // break out inner loop } } else if (prop.getVal() instanceof CustomFieldStringValue) { String val = ((CustomFieldStringValue)prop.getVal()).getValue(); if (val.equals(vmLabel)) { list.add(new VirtualMachineMO(_context, oc.getObj())); break; // break out inner loop } } } } } } } return list; }
Example #24
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public VirtualMachineMO findVm(String vmName) throws Exception { int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name", instanceNameCustomField}); return HypervisorHostHelper.findVmFromObjectContent(_context, ocs.toArray(new ObjectContent[0]), vmName, instanceNameCustomField); }
Example #25
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public boolean isHyperHostConnected() throws Exception { ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"runtime"}); if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)oc.getPropSet().get(0).getVal(); // as long as we have one host connected, we assume the cluster is up if (runtimeInfo.getConnectionState() == HostSystemConnectionState.CONNECTED) return true; } } return false; }
Example #26
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public VirtualMachineMO findVmOnPeerHyperHost(String name) throws Exception { int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] {"name", instanceNameCustomField}); return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name, instanceNameCustomField); }
Example #27
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
public List<Pair<ManagedObjectReference, String>> getClusterHosts() throws Exception { List<Pair<ManagedObjectReference, String>> hosts = new ArrayList<Pair<ManagedObjectReference, String>>(); ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"name"}); if (ocs != null) { for (ObjectContent oc : ocs) { ManagedObjectReference morHost = oc.getObj(); String name = (String)oc.getPropSet().get(0).getVal(); hosts.add(new Pair<ManagedObjectReference, String>(morHost, name)); } } return hosts; }
Example #28
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 #29
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 #30
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; }