Java 类com.vmware.vim25.OptionValue 实例源码

项目:teamcity-vmware-plugin    文件:FakeModel.java   
public FakeVirtualMachine addVM(String name, boolean isRunning, VirtualMachineCloneSpec spec){
  final FakeVirtualMachine vm = new FakeVirtualMachine(name, name.contains("template"), isRunning);
  putVM(name, vm);
  if (spec != null && spec.getLocation()!= null
      && VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.name().equals(spec.getLocation().getDiskMoveType())){
    //((FakeVirtualMachine)vm).set
  }
  if (spec != null && spec.getConfig() != null) {
    final OptionValue[] extraConfig = spec.getConfig().getExtraConfig();
    if (extraConfig != null) {
      for (OptionValue optionValue : extraConfig) {
        vm.addCustomParam(optionValue.getKey(), String.valueOf(optionValue.getValue()));
      }
    }
  }

  return vm;
}
项目:cloudstack    文件:VirtualMachineMO.java   
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);
}
项目:photon-model    文件:InstanceClient.java   
/**
 * Stores a timestamp into a VM's extraConfig on provisioning.
 * Currently used for resource cleanup only.
 */
private void recordTimestamp(List<OptionValue> extraConfig) {
    if (extraConfig == null) {
        return;
    }

    OptionValue ov = new OptionValue();
    ov.setKey(EXTRA_CONFIG_CREATED);
    ov.setValue(Long.toString(System.currentTimeMillis()));
    extraConfig.add(ov);
}
项目:photon-model    文件:InstanceClient.java   
private void recordSnapshotLimit(List<OptionValue> extraConfig, String snapshotLimitValue) {
    if (snapshotLimitValue != null && !snapshotLimitValue.isEmpty()) {
        if (extraConfig == null) {
            extraConfig = new ArrayList<>();
        }
        extraConfig.add(populateSnapshotLimitValue(snapshotLimitValue));
    }
}
项目:cloudstack    文件:HypervisorHostHelper.java   
public static String getOVFParamValue(VirtualMachineConfigSpec config) {
    String paramVal = "";
    List<OptionValue> options = config.getExtraConfig();
    for (OptionValue option : options) {
        if (OVA_OPTION_KEY_BOOTDISK.equalsIgnoreCase(option.getKey())) {
            paramVal = (String)option.getValue();
            break;
        }
    }
    return paramVal;
}
项目:cloudstack    文件:VirtualMachineMO.java   
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;
}
项目:cloudstack    文件:ClusterMO.java   
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) {
            List<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;
}
项目:cloudstack    文件:VmwareHelper.java   
public static OptionValue[] composeVncOptions(OptionValue[] optionsToMerge, boolean enableVnc, String vncPassword, int vncPort, String keyboardLayout) {

        int numOptions = 3;
        boolean needKeyboardSetup = false;
        if (keyboardLayout != null && !keyboardLayout.isEmpty()) {
            numOptions++;
            needKeyboardSetup = true;
        }

        if (optionsToMerge != null)
            numOptions += optionsToMerge.length;

        OptionValue[] options = new OptionValue[numOptions];
        int i = 0;
        if (optionsToMerge != null) {
            for (int j = 0; j < optionsToMerge.length; j++)
                options[i++] = optionsToMerge[j];
        }

        options[i] = new OptionValue();
        options[i].setKey("RemoteDisplay.vnc.enabled");
        options[i++].setValue(enableVnc ? "true" : "false");

        options[i] = new OptionValue();
        options[i].setKey("RemoteDisplay.vnc.password");
        options[i++].setValue(vncPassword);

        options[i] = new OptionValue();
        options[i].setKey("RemoteDisplay.vnc.port");
        options[i++].setValue("" + vncPort);

        if (needKeyboardSetup) {
            options[i] = new OptionValue();
            options[i].setKey("RemoteDisplay.vnc.keymap");
            options[i++].setValue(keyboardLayout);
        }

        return options;
    }
项目:cloudstack    文件:VmwareResource.java   
private static void configCustomExtraOption(List<OptionValue> extraOptions, VirtualMachineTO vmSpec) {
    // we no longer to validation anymore
    for (Map.Entry<String, String> entry : vmSpec.getDetails().entrySet()) {
        OptionValue newVal = new OptionValue();
        newVal.setKey(entry.getKey());
        newVal.setValue(entry.getValue());
        extraOptions.add(newVal);
    }
}
项目:photon-model    文件:InstanceClient.java   
private OptionValue populateSnapshotLimitValue(String snapshotLimitValue) {
    OptionValue ov = new OptionValue();
    ov.setKey(SNAPSHOT_LIMIT_CONFIG_STRING);
    ov.setValue(snapshotLimitValue);
    return ov;
}
项目:cloudstack    文件:HostMO.java   
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;
    }
项目:cloudstack    文件:VmwareResource.java   
protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervisorHost hyperHost, String vmName, String vncPassword, String keyboardLayout) throws Exception {

        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);

        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        if (!mgr.beginExclusiveOperation(600))
            throw new Exception("Unable to begin exclusive operation, lock time out");

        try {
            int maxVncPorts = 64;
            int vncPort = 0;
            Random random = new Random();

            HostMO vmOwnerHost = vmMo.getRunningHost();

            ManagedObjectReference morParent = vmOwnerHost.getParentMor();
            HashMap<String, Integer> portInfo;
            if (morParent.getType().equalsIgnoreCase("ClusterComputeResource")) {
                ClusterMO clusterMo = new ClusterMO(vmOwnerHost.getContext(), morParent);
                portInfo = clusterMo.getVmVncPortsOnCluster();
            } else {
                portInfo = vmOwnerHost.getVmVncPortsOnHost();
            }

            // allocate first at 5900 - 5964 range
            Collection<Integer> existingPorts = portInfo.values();
            int val = random.nextInt(maxVncPorts);
            int startVal = val;
            do {
                if (!existingPorts.contains(5900 + val)) {
                    vncPort = 5900 + val;
                    break;
                }

                val = (++val) % maxVncPorts;
            } while (val != startVal);

            if (vncPort == 0) {
                s_logger.info("we've run out of range for ports between 5900-5964 for the cluster, we will try port range at 59000-60000");

                Pair<Integer, Integer> additionalRange = mgr.getAddiionalVncPortRange();
                maxVncPorts = additionalRange.second();
                val = random.nextInt(maxVncPorts);
                startVal = val;
                do {
                    if (!existingPorts.contains(additionalRange.first() + val)) {
                        vncPort = additionalRange.first() + val;
                        break;
                    }

                    val = (++val) % maxVncPorts;
                } while (val != startVal);
            }

            if (vncPort == 0) {
                throw new Exception("Unable to find an available VNC port on host");
            }

            if (s_logger.isInfoEnabled()) {
                s_logger.info("Configure VNC port for VM " + vmName + ", port: " + vncPort + ", host: " + vmOwnerHost.getHyperHostName());
            }

            return VmwareHelper.composeVncOptions(optionsToMerge, true, vncPassword, vncPort, keyboardLayout);
        } finally {
            try {
                mgr.endExclusiveOperation();
            } catch (Throwable e) {
                assert (false);
                s_logger.error("Unexpected exception ", e);
            }
        }
    }
项目:jcloud-vsphere    文件:OptionManagerApi.java   
List<OptionValue> getSetting();
项目:jcloud-vsphere    文件:OptionManagerApi.java   
List<OptionValue> queryOptions(String name) throws InvalidName, RuntimeFault, RemoteException;
项目:jcloud-vsphere    文件:OptionManagerApi.java   
void updateOptions(List<OptionValue> changedValue) throws InvalidName, RuntimeFault, RemoteException;