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

项目:vijava    文件:VmCdOp.java   
static VirtualDevice[] getDefaultDevices(VirtualMachine vm) 
throws Exception 
{
  VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime();
  EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); 
  ManagedObjectReference hmor = vmRuntimeInfo.getHost();
  VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor));
  VirtualDevice[] defaultDevs = null;
  if (cfgOpt != null) 
  {
    defaultDevs = cfgOpt.getDefaultDevice();
    if (defaultDevs == null) 
    {
      throw new Exception("No Datastore found in ComputeResource");
    }
  }
  else
  {
    throw new Exception("No VirtualHardwareInfo found in ComputeResource");
  }
  return defaultDevs;
}
项目:cs-actions    文件:VmService.java   
/**
 * Method used to connect to data center to retrieve a list with all the guest operating system descriptors
 * supported by the host system.
 *
 * @param httpInputs Object that has all the inputs necessary to made a connection to data center
 * @param vmInputs   Object that has all the specific inputs necessary to identify the targeted host system
 * @param delimiter  String that represents the delimiter needed in the result list
 * @return Map with String as key and value that contains returnCode of the operation, a list that contains all the
 *         guest operating system descriptors supported by the host system or failure message and the exception if there is one
 * @throws Exception
 */
public Map<String, String> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        ManagedObjectReference environmentBrowserMor = new MorObjectHandler()
                .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue());
        VirtualMachineConfigOption configOptions = connectionResources.getVimPortType()
                .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor());

        List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor();

        return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter),
                Outputs.RETURN_CODE_SUCCESS);
    } catch (Exception ex) {
        return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public GuestOsDescriptor getGuestOsDescriptor(String guestOsId) throws Exception {
    GuestOsDescriptor guestOsDescriptor = null;
    String guestId = guestOsId;
    if (guestId == null) {
        guestId = getGuestId();
    }
    ManagedObjectReference vmEnvironmentBrowser = _context.getVimClient().getMoRefProp(_mor, "environmentBrowser");
    VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(vmEnvironmentBrowser, null, null);
    List<GuestOsDescriptor> guestDescriptors = vmConfigOption.getGuestOSDescriptor();
    for (GuestOsDescriptor descriptor : guestDescriptors) {
        if (guestId != null && guestId.equalsIgnoreCase(descriptor.getId())) {
            guestOsDescriptor = descriptor;
            break;
        }
    }
    return guestOsDescriptor;
}
项目:cloudstack    文件:ClusterMO.java   
@Override
public String getRecommendedDiskController(String guestOsId) throws Exception {
    VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null);
    GuestOsDescriptor guestOsDescriptor = null;
    String diskController = null;
    List<GuestOsDescriptor> guestDescriptors = vmConfigOption.getGuestOSDescriptor();
    for (GuestOsDescriptor descriptor : guestDescriptors) {
        if (guestOsId != null && guestOsId.equalsIgnoreCase(descriptor.getId())) {
            guestOsDescriptor = descriptor;
            break;
        }
    }
    if (guestOsDescriptor != null) {
        diskController = VmwareHelper.getRecommendedDiskControllerFromDescriptor(guestOsDescriptor);
        s_logger.debug("Retrieved recommended disk controller for guest OS : " + guestOsId + " in cluster " + getHyperHostName() + " : " + diskController);
        return diskController;
    } else {
        String msg = "Unable to retrieve recommended disk controller for guest OS : " + guestOsId + " in cluster " + getHyperHostName();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
/** Create a new virtual network adapter on the VM
* Your MAC address should start with 00:50:56
  */
 public void createNetworkAdapter(VirtualNetworkAdapterType type, String networkName, String macAddress, boolean wakeOnLan, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException
 {
   VirtualMachinePowerState powerState = vm.getRuntime().getPowerState();
   String vmVerStr = vm.getConfig().getVersion();
   int vmVer = Integer.parseInt(vmVerStr.substring(vmVerStr.length()-2));

   if((powerState == VirtualMachinePowerState.suspended) ||
     (powerState == VirtualMachinePowerState.suspended && vmVer < 7))
   {
     throw new InvalidPowerState();
   }

   HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost());
   ComputeResource cr = (ComputeResource) host.getParent();
   EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();
   ConfigTarget configTarget = envBrowser.queryConfigTarget(host);
   VirtualMachineConfigOption vmCfgOpt = envBrowser.queryConfigOption(null, host);

   type = validateNicType(vmCfgOpt.getGuestOSDescriptor(), vm.getConfig().getGuestId(), type);

   VirtualDeviceConfigSpec nicSpec = createNicSpec(type, networkName, macAddress, wakeOnLan, startConnected, configTarget);

   VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
   vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec []{nicSpec});
   Task task = vm.reconfigVM_Task(vmConfigSpec);

   task.waitForTask(200, 100);
 }
项目:vijava    文件:EnvironmentBrowser.java   
public VirtualMachineConfigOption queryConfigOption(String key, HostSystem host) throws RuntimeFault, RemoteException 
{
    return getVimService().queryConfigOption(getMOR(), key, host==null? null : host.getMOR());
}
项目:cloudstack    文件:VirtualMachineMO.java   
public VirtualHardwareOption getVirtualHardwareOption() throws Exception {
    VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null);
    return vmConfigOption.getHardwareOptions();
}