本文整理汇总了Java中com.vmware.vim25.ObjectContent类的典型用法代码示例。如果您正苦于以下问题:Java ObjectContent类的具体用法?Java ObjectContent怎么用?Java ObjectContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectContent类属于com.vmware.vim25包,在下文中一共展示了ObjectContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectProperties
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
/**
* 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()]);
}
示例2: resultsToTgtMorefMap
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
private void resultsToTgtMorefMap(RetrieveResult results,
Map<String, ManagedObjectReference> tgtMoref) {
List<ObjectContent> oCont = (results != null) ? results.getObjects() : null;
if (oCont != null) {
for (ObjectContent oc : oCont) {
ManagedObjectReference mr = oc.getObj();
String entityNm = null;
List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) {
for (DynamicProperty dp : dps) {
entityNm = (String) dp.getVal();
}
}
tgtMoref.put(entityNm, mr);
}
}
}
示例3: inContainerByType
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
/**
* Returns all the MOREFs of the specified type that are present under the
* container
*
* @param container {@link ManagedObjectReference} of the container to begin the
* search from
* @param morefType Type of the managed entity that needs to be searched
* @param morefProperties Array of properties to be fetched for the moref
* @return Map of MOREF and Map of name value pair of properties requested of
* the managed objects present. If none exist then empty Map is
* returned
* @throws InvalidPropertyFaultMsg
* @throws RuntimeFaultFaultMsg
*/
public Map<ManagedObjectReference, Map<String, Object>> inContainerByType(
ManagedObjectReference container, String morefType,
String[] morefProperties, RetrieveOptions retrieveOptions)
throws InvalidPropertyFaultMsg,
RuntimeFaultFaultMsg {
List<ObjectContent> oCont = containerViewByType(container, morefType, retrieveOptions,
morefProperties).getObjects();
Map<ManagedObjectReference, Map<String, Object>> tgtMoref =
new HashMap<ManagedObjectReference, Map<String, Object>>();
if (oCont != null) {
for (ObjectContent oc : oCont) {
Map<String, Object> propMap = new HashMap<String, Object>();
List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) {
for (DynamicProperty dp : dps) {
propMap.put(dp.getName(), dp.getVal());
}
}
tgtMoref.put(oc.getObj(), propMap);
}
}
return tgtMoref;
}
示例4: populate
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
public static String populate(final RetrieveResult rslts,
final Map<String, ManagedObjectReference> tgtMoref) {
String token = null;
if (rslts != null) {
token = rslts.getToken();
for (ObjectContent oc : rslts.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;
}
示例5: getCurrentProperty
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
/**
* @param propertyName The property name of current managed object
* @return it will return either an array of related data objects, or an data object itself.
* ManagedObjectReference objects are data objects!!!
* @throws RemoteException
* @throws RuntimeFault
* @throws InvalidProperty
* @
*/
protected Object getCurrentProperty(String propertyName)
{
ObjectContent objContent = retrieveObjectProperties(new String[] { propertyName });
Object propertyValue = null;
if (objContent != null)
{
DynamicProperty[] dynaProps = objContent.getPropSet();
if ((dynaProps != null) && (dynaProps[0]!= null))
{
propertyValue = PropertyCollectorUtil.convertProperty(dynaProps[0].getVal());
}
}
return propertyValue;
}
示例6: getMorHost
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例7: entityProps
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
/**
* 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;
}
示例8: populate
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例9: findDatastore
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例10: getDatastorePropertiesOnHostDatastoreSystem
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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);
}
示例11: getLocalDatastoreOnHost
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例12: findVmFromObjectContent
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例13: getDatastorePropertiesOnDatacenter
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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);
}
示例14: getFileLayout
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
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;
}
示例15: getHyperHostDefaultGateway
import com.vmware.vim25.ObjectContent; //导入依赖的package包/类
@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?");
}