use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.
the class HostMO method getVmVncPortsOnHost.
public HashMap<String, Integer> getVmVncPortsOnHost() 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 ?!");
}
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]", "value[" + key + "]" });
HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> objProps = oc.getPropSet();
if (objProps != null) {
String vmName = null;
String value = null;
String vmInternalCSName = null;
for (DynamicProperty objProp : objProps) {
if (objProp.getName().equals("name")) {
vmName = (String) objProp.getVal();
} else if (objProp.getName().startsWith("value[")) {
if (objProp.getVal() != null)
vmInternalCSName = ((CustomFieldStringValue) objProp.getVal()).getValue();
} else {
OptionValue optValue = (OptionValue) objProp.getVal();
value = (String) optValue.getValue();
}
}
if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName))
vmName = vmInternalCSName;
if (vmName != null && value != null) {
portInfo.put(vmName, Integer.parseInt(value));
}
}
}
}
return portInfo;
}
use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.
the class HypervisorHostHelper method findVmFromObjectContent.
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;
}
use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.
the class VirtualMachineMO method getFileLayout.
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;
}
use of com.vmware.vim25.DynamicProperty in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getOwnerDatastore.
public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.setPathSet(new String[] { "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.setSelectSet(new SelectionSpec[] { vmDatastoreTraversal });
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) {
for (ObjectContent oc : ocs) {
DynamicProperty prop = oc.getPropSet(0);
if (prop.getVal().toString().equals(dsName)) {
return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
}
}
}
return null;
}
use of com.vmware.vim25.DynamicProperty in project CloudStack-archive by CloudStack-extras.
the class ClusterMO method getVmVncPortsOnCluster.
public HashMap<String, Integer> getVmVncPortsOnCluster() throws Exception {
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]" });
HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
DynamicProperty[] objProps = oc.getPropSet();
if (objProps != null) {
String name = null;
String value = null;
for (DynamicProperty objProp : objProps) {
if (objProp.getName().equals("name")) {
name = (String) objProp.getVal();
} else {
OptionValue optValue = (OptionValue) objProp.getVal();
value = (String) optValue.getValue();
}
}
if (name != null && value != null) {
portInfo.put(name, Integer.parseInt(value));
}
}
}
}
return portInfo;
}
Aggregations