Search in sources :

Example 6 with OptionValue

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;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) HashMap(java.util.HashMap) OptionValue(com.vmware.vim25.OptionValue)

Example 7 with OptionValue

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);
}
Also used : OptionValue(com.vmware.vim25.OptionValue) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo) Pair(com.cloud.utils.Pair)

Example 8 with OptionValue

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;
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) OptionValue(com.vmware.vim25.OptionValue) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 9 with OptionValue

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;
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) OptionValue(com.vmware.vim25.OptionValue) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 10 with OptionValue

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;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) HashMap(java.util.HashMap) OptionValue(com.vmware.vim25.OptionValue)

Aggregations

OptionValue (com.vmware.vim25.OptionValue)15 HashMap (java.util.HashMap)6 DynamicProperty (com.vmware.vim25.DynamicProperty)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 ObjectContent (com.vmware.vim25.ObjectContent)4 Pair (com.cloud.utils.Pair)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 NicTO (com.cloud.agent.api.to.NicTO)2 CloudException (com.cloud.exception.CloudException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)2 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 VirtualMachineConfigInfo (com.vmware.vim25.VirtualMachineConfigInfo)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 ConfigurationException (javax.naming.ConfigurationException)2