当前位置: 首页>>代码示例>>Java>>正文


Java VirtualMachineConfigSpec.setMemoryMB方法代码示例

本文整理汇总了Java中com.vmware.vim25.VirtualMachineConfigSpec.setMemoryMB方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachineConfigSpec.setMemoryMB方法的具体用法?Java VirtualMachineConfigSpec.setMemoryMB怎么用?Java VirtualMachineConfigSpec.setMemoryMB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vmware.vim25.VirtualMachineConfigSpec的用法示例。


在下文中一共展示了VirtualMachineConfigSpec.setMemoryMB方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPopulatedVmConfigSpec

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
VirtualMachineConfigSpec getPopulatedVmConfigSpec(VirtualMachineConfigSpec vmConfigSpec, VmInputs vmInputs, String name) {
    vmConfigSpec.setName(name);
    vmConfigSpec.setNumCPUs(vmInputs.getIntNumCPUs());
    vmConfigSpec.setMemoryMB(vmInputs.getLongVmMemorySize());
    vmConfigSpec.setAnnotation(vmInputs.getDescription());

    if (vmInputs.getCoresPerSocket() != null) {
        vmConfigSpec.setNumCoresPerSocket(InputUtils.getIntInput(vmInputs.getCoresPerSocket(), DEFAULT_CORES_PER_SOCKET));
    }

    if (vmInputs.getGuestOsId() != null) {
        vmConfigSpec.setGuestId(vmInputs.getGuestOsId());
    }

    return vmConfigSpec;
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:17,代码来源:VmUtils.java

示例2: setVmScaleUpConfig

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void setVmScaleUpConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB,
        boolean limitCpuUse) {

    // VM config for scaling up
    vmConfig.setMemoryMB((long)memoryMB);
    vmConfig.setNumCPUs(cpuCount);

    ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
    if (limitCpuUse) {
        cpuInfo.setLimit((long)(cpuSpeedMHz * cpuCount));
    } else {
        cpuInfo.setLimit(-1L);
    }

    cpuInfo.setReservation((long)cpuReservedMhz);
    vmConfig.setCpuAllocation(cpuInfo);

    ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
    memInfo.setLimit((long)memoryMB);
    memInfo.setReservation((long)memoryReserveMB);
    vmConfig.setMemoryAllocation(memInfo);

}
 
开发者ID:apache,项目名称:cloudstack,代码行数:24,代码来源:VmwareHelper.java

示例3: reconfigureVirtualMachine

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
/**
 * Reconfigures VMware instance. Memory, CPU, disk space and network
 * adapter. The VM has been created and must be stopped to reconfigure the
 * hardware.
 */
public TaskInfo reconfigureVirtualMachine(VMPropertyHandler paramHandler)
        throws Exception {
    LOG.debug("instanceName: " + instanceName);

    VimPortType service = vmw.getConnection().getService();
    VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();

    vmConfigSpec
            .setMemoryMB(Long.valueOf(paramHandler.getConfigMemoryMB()));
    vmConfigSpec.setNumCPUs(Integer.valueOf(paramHandler.getConfigCPUs()));

    String reqUser = paramHandler
            .getServiceSetting(VMPropertyHandler.REQUESTING_USER);

    String comment = Messages.get(paramHandler.getLocale(), "vm_comment",
            new Object[] { paramHandler.getSettings().getOrganizationName(),
                    paramHandler.getSettings().getSubscriptionId(),
                    reqUser });
    String annotation = vmConfigSpec.getAnnotation();
    comment = updateComment(comment, annotation);
    vmConfigSpec.setAnnotation(comment);

    DiskManager diskManager = new DiskManager(vmw, paramHandler);
    diskManager.reconfigureDisks(vmConfigSpec, vmInstance);

    NetworkManager.configureNetworkAdapter(vmw, vmConfigSpec, paramHandler,
            vmInstance);

    LOG.debug("Call vSphere API: reconfigVMTask()");
    ManagedObjectReference reconfigureTask = service
            .reconfigVMTask(vmInstance, vmConfigSpec);

    return (TaskInfo) vmw.getServiceUtil()
            .getDynamicProperty(reconfigureTask, "info");
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:41,代码来源:VM.java

示例4: buildVirtualMachineConfigSpec

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
/**
 * Creates a spec used to create the VM.
 *
 * @param datastoreName
 * @return
 * @throws InvalidPropertyFaultMsg
 * @throws FinderException
 * @throws RuntimeFaultFaultMsg
 */
private VirtualMachineConfigSpec buildVirtualMachineConfigSpec(String datastoreName)
        throws InvalidPropertyFaultMsg, FinderException, RuntimeFaultFaultMsg {
    String displayName = this.ctx.child.name;

    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    spec.setName(displayName);
    spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
    spec.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST_64.value());
    spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));

    VirtualMachineFileInfo files = new VirtualMachineFileInfo();
    // Use a full path to the config file to avoid creating a VM with the same name
    String path = String.format("[%s] %s/%s.vmx", datastoreName, displayName, displayName);
    files.setVmPathName(path);
    spec.setFiles(files);

    for (NetworkInterfaceStateWithDetails ni : this.ctx.nics) {
        VirtualDevice nic = createNic(ni, null);
        addDeviceToVm(spec, nic);
    }

    VirtualDevice scsi = createScsiController();
    addDeviceToVm(spec, scsi);

    return spec;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:36,代码来源:InstanceClient.java

示例5: setBasicVmConfig

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB,
        String guestOsIdentifier, boolean limitCpuUse) {

    // VM config basics
    vmConfig.setMemoryMB((long)memoryMB);
    vmConfig.setNumCPUs(cpuCount);

    ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
    if (limitCpuUse) {
        cpuInfo.setLimit(((long)cpuSpeedMHz * cpuCount));
    } else {
        cpuInfo.setLimit(-1L);
    }

    cpuInfo.setReservation((long)cpuReservedMhz);
    vmConfig.setCpuAllocation(cpuInfo);
    if (cpuSpeedMHz != cpuReservedMhz) {
        vmConfig.setCpuHotAddEnabled(true);
    }
    if (memoryMB != memoryReserveMB) {
        vmConfig.setMemoryHotAddEnabled(true);
    }
    ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
    memInfo.setLimit((long)memoryMB);
    memInfo.setReservation((long)memoryReserveMB);
    vmConfig.setMemoryAllocation(memInfo);

    vmConfig.setGuestId(guestOsIdentifier);
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:30,代码来源:VmwareHelper.java

示例6: createNodeWithGroupEncodedIntoName

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
@Override
public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(String tag, String name, Template template) {

   VSphereTemplateOptions vOptions = VSphereTemplateOptions.class.cast(template.getOptions());

   String datacenterName = vOptions.datacenterName();
   try (VSphereServiceInstance instance = this.serviceInstance.get();
        VSphereHost sphereHost = hostFunction.apply(datacenterName);
        /*VSphereHost sphereHost = vSphereHost.get();*/) {
      Folder rootFolder = instance.getInstance().getRootFolder();

      ComputerNameValidator.INSTANCE.validate(name);

      VirtualMachine master = getVMwareTemplate(template.getImage().getId(), rootFolder);
      ResourcePool resourcePool = checkNotNull(tryFindResourcePool(rootFolder, sphereHost.getHost().getName()).orNull(), "resourcePool");

      logger.trace("<< trying to use ResourcePool: " + resourcePool.getName());
     // VSphereTemplateOptions vOptions = VSphereTemplateOptions.class.cast(template.getOptions());


      VirtualMachineCloneSpec cloneSpec = new MasterToVirtualMachineCloneSpec(resourcePool, sphereHost.getDatastore(),
              VSphereApiMetadata.defaultProperties().getProperty(CLONING), name, vOptions.postConfiguration()).apply(master);


      Set<String> networks = vOptions.getNetworks();

      VirtualMachineConfigSpec virtualMachineConfigSpec = new VirtualMachineConfigSpec();
      virtualMachineConfigSpec.setMemoryMB((long) template.getHardware().getRam());
      if (template.getHardware().getProcessors().size() > 0)
         virtualMachineConfigSpec.setNumCPUs((int) template.getHardware().getProcessors().get(0).getCores());
      else
         virtualMachineConfigSpec.setNumCPUs(1);


      Set<NetworkConfig> networkConfigs = Sets.newHashSet();
      for (String network : networks) {
         NetworkConfig config = networkConfigurationForNetworkAndOptions.apply(network, vOptions);
         networkConfigs.add(config);
      }


      List<VirtualDeviceConfigSpec> updates = configureVmHardware(name, template, master, vOptions, networkConfigs);
      virtualMachineConfigSpec.setDeviceChange(updates.toArray(new VirtualDeviceConfigSpec[updates.size()]));

      cloneSpec.setConfig(virtualMachineConfigSpec);

      vOptions.getPublicKey();

      VirtualMachine cloned = null;
      try {
         cloned = cloneMaster(master, tag, name, cloneSpec, vOptions.vmFolder());
         Set<String> tagsFromOption = vOptions.getTags();
         if (tagsFromOption.size() > 0) {
            String tags = Joiner.on(",").join(vOptions.getTags());
            cloned.getServerConnection().getServiceInstance().getCustomFieldsManager().setField(cloned, customFields.get().get(VSphereConstants.JCLOUDS_TAGS).getKey(), tags);
            cloned.getServerConnection().getServiceInstance().getCustomFieldsManager().setField(cloned, customFields.get().get(VSphereConstants.JCLOUDS_GROUP).getKey(), tag);
            if (vOptions.postConfiguration())
               postConfiguration(cloned, name, tag, networkConfigs);
            else {
               VSpherePredicate.WAIT_FOR_VMTOOLS(1000 * 60 * 60 * 2, TimeUnit.MILLISECONDS).apply(cloned);
            }
         }
      } catch (Exception e) {
         logger.error("Can't clone vm " + master.getName() + ", Error message: " + e.toString(), e);
         propagate(e);
      }

      checkAndRecoverNicConfiguration(serviceInstance.get(), cloned);

      NodeAndInitialCredentials<VirtualMachine> nodeAndInitialCredentials = new NodeAndInitialCredentials<VirtualMachine>(cloned, cloned.getName(),
              LoginCredentials.builder().user("root")
                      .password(vmInitPassword)
                      .build());
      return nodeAndInitialCredentials;
   } catch (Throwable t) {
      logger.error("Got ERROR while create new VM : " + t.toString());
      Throwables.propagateIfPossible(t);
   }
   return null;
}
 
开发者ID:igreenfield,项目名称:jcloud-vsphere,代码行数:81,代码来源:VSphereComputeServiceAdapter.java

示例7: main

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception 
{  
  if(args.length!=3)
  {
    System.out.println("Usage: java CreateVM <url> " +
          "<username> <password>");
    System.exit(0);
  }

  String dcName = "ha-datacenter";
  String vmName = "vimasterVM";
  long memorySizeMB = 500;
  int cupCount = 1;
  String guestOsId = "sles10Guest";
  long diskSizeKB = 1000000;
  // mode: persistent|independent_persistent,
  // independent_nonpersistent
  String diskMode = "persistent";
  String datastoreName = "storage1 (2)";
  String netName = "VM Network";
  String nicName = "Network Adapter 1";
  
  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  Folder rootFolder = si.getRootFolder();
  
  Datacenter dc = (Datacenter) new InventoryNavigator(
      rootFolder).searchManagedEntity("Datacenter", dcName);
  ResourcePool rp = (ResourcePool) new InventoryNavigator(
      dc).searchManagedEntities("ResourcePool")[0];
  
  Folder vmFolder = dc.getVmFolder();

  // create vm config spec
  VirtualMachineConfigSpec vmSpec = 
    new VirtualMachineConfigSpec();
  vmSpec.setName(vmName);
  vmSpec.setAnnotation("VirtualMachine Annotation");
  vmSpec.setMemoryMB(memorySizeMB);
  vmSpec.setNumCPUs(cupCount);
  vmSpec.setGuestId(guestOsId);

  // create virtual devices
  int cKey = 1000;
  VirtualDeviceConfigSpec scsiSpec = createScsiSpec(cKey);
  VirtualDeviceConfigSpec diskSpec = createDiskSpec(
      datastoreName, cKey, diskSizeKB, diskMode);
  VirtualDeviceConfigSpec nicSpec = createNicSpec(
      netName, nicName);

  vmSpec.setDeviceChange(new VirtualDeviceConfigSpec[] 
      {scsiSpec, diskSpec, nicSpec});
  
  // create vm file info for the vmx file
  VirtualMachineFileInfo vmfi = new VirtualMachineFileInfo();
  vmfi.setVmPathName("["+ datastoreName +"]");
  vmSpec.setFiles(vmfi);

  // call the createVM_Task method on the vm folder
  Task task = vmFolder.createVM_Task(vmSpec, rp, null);
  String result = task.waitForMe();       
  if(result == Task.SUCCESS) 
  {
    System.out.println("VM Created Sucessfully");
  }
  else 
  {
    System.out.println("VM could not be created. ");
  }
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:72,代码来源:CreateVM.java

示例8: createWorkerVM

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName) throws Exception {

        // Allow worker VM to float within cluster so that we will have better chance to
        // create it successfully
        ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
        if (morCluster != null)
            hyperHost = new ClusterMO(hyperHost.getContext(), morCluster);

        VirtualMachineMO workingVM = null;
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
        vmConfig.setName(vmName);
        vmConfig.setMemoryMB((long)4);
        vmConfig.setNumCPUs(1);
        vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
        VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
        fileInfo.setVmPathName(dsMo.getDatastoreRootPath());
        vmConfig.setFiles(fileInfo);

        VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
        scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
        scsiController.setBusNumber(0);
        scsiController.setKey(1);
        VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
        scsiControllerSpec.setDevice(scsiController);
        scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

        vmConfig.getDeviceChange().add(scsiControllerSpec);
        if (hyperHost.createVm(vmConfig)) {
            // Ugly work-around, it takes time for newly created VM to appear
            for (int i = 0; i < 10 && workingVM == null; i++) {
                workingVM = hyperHost.findVmOnHyperHost(vmName);

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    s_logger.debug("[ignored] interupted while waiting to config vm.");
                }
            }
        }

        if (workingVM != null) {
            workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
            String workerTag = String.format("%d-%s", System.currentTimeMillis(), hyperHost.getContext().getStockObject("noderuninfo"));
            workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
        }
        return workingVM;
    }
 
开发者ID:apache,项目名称:cloudstack,代码行数:48,代码来源:HypervisorHostHelper.java


注:本文中的com.vmware.vim25.VirtualMachineConfigSpec.setMemoryMB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。