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


Java VirtualMachineConfigSpec.setFiles方法代码示例

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


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

示例1: 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

示例2: 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

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