use of com.vmware.vim25.ObjectContent in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getNetworksWithDetails.
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.setPathSet(new String[] { "name", "vm", 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.setSelectSet(new SelectionSpec[] { vm2NetworkTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
if (ocs != null && ocs.length > 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() : null), gcTagValue);
networks.add(details);
}
s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey);
}
return networks;
}
use of com.vmware.vim25.ObjectContent in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getSnapshotDescriptorDatastorePath.
public String getSnapshotDescriptorDatastorePath() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.setPathSet(new String[] { "name", "config.files" });
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.FALSE);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
assert (ocs != null);
String vmName = null;
VirtualMachineFileInfo fileInfo = null;
assert (ocs.length == 1);
for (ObjectContent oc : ocs) {
DynamicProperty[] props = oc.getPropSet();
if (props != null) {
assert (props.length == 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");
}
use of com.vmware.vim25.ObjectContent in project CloudStack-archive by CloudStack-extras.
the class HostMO method getLocalDatastoreOnHost.
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.getMultipleHostAccess() == false && dsSummary.isAccessible() && dsSummary.getType().equalsIgnoreCase("vmfs")) {
ManagedObjectReference morDs = oc.getObj();
String name = (String) VmwareHelper.getPropValue(oc, "name");
dsList.add(new Pair<ManagedObjectReference, String>(morDs, name));
}
}
}
return dsList;
}
use of com.vmware.vim25.ObjectContent in project CloudStack-archive by CloudStack-extras.
the class HostMO method getDatastoreMountsOnHost.
public List<Pair<ManagedObjectReference, String>> getDatastoreMountsOnHost() throws Exception {
List<Pair<ManagedObjectReference, String>> mounts = new ArrayList<Pair<ManagedObjectReference, String>>();
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { String.format("host[\"%s\"].mountInfo.path", _mor.get_value()) });
if (ocs != null) {
for (ObjectContent oc : ocs) {
Pair<ManagedObjectReference, String> mount = new Pair<ManagedObjectReference, String>(oc.getObj(), oc.getPropSet(0).getVal().toString());
mounts.add(mount);
}
}
return mounts;
}
use of com.vmware.vim25.ObjectContent in project CloudStack-archive by CloudStack-extras.
the class HostMO method getDatastorePropertiesOnHyperHost.
@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.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.setPathSet(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.setSelectSet(new SelectionSpec[] { host2DatastoreTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() done");
return properties;
}
Aggregations