use of com.vmware.vim25.OptionValue 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.OptionValue in project cloudstack by apache.
the class VirtualMachineMO method getVncPort.
public Pair<String, Integer> getVncPort(String hostNetworkName) throws Exception {
HostMO hostMo = getRunningHost();
VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);
VirtualMachineConfigInfo configInfo = getConfigInfo();
List<OptionValue> values = configInfo.getExtraConfig();
if (values != null) {
for (OptionValue option : values) {
if (option.getKey().equals("RemoteDisplay.vnc.port")) {
String value = (String) option.getValue();
if (value != null) {
return new Pair<String, Integer>(summary.getHostIp(), Integer.parseInt(value));
}
}
}
}
return new Pair<String, Integer>(summary.getHostIp(), 0);
}
use of com.vmware.vim25.OptionValue in project cloudstack by apache.
the class VirtualMachineMO method setVncConfigInfo.
public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, int vncPort, String keyboard) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, enableVnc, vncPassword, vncPort, keyboard);
vmConfigSpec.getExtraConfig().addAll(Arrays.asList(vncOptions));
ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, vmConfigSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.OptionValue in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method setVncConfigInfo.
public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, int vncPort, String keyboard) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, enableVnc, vncPassword, vncPort, keyboard);
vmConfigSpec.setExtraConfig(vncOptions);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, vmConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.OptionValue 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