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


Java VirtualMachineConfigSpec.setDeviceChange方法代码示例

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


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

示例1: addHardDisk

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public void addHardDisk(String diskFilePath, VirtualDiskMode diskMode) throws Exception
{
  VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();

  VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();
  VirtualDeviceConfigSpec[] vdiskSpecArray = {diskSpec};
  vmConfigSpec.setDeviceChange(vdiskSpecArray);
  
  VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();
  diskfileBacking.setFileName(diskFilePath);
  diskfileBacking.setDiskMode(diskMode.toString());

  
  VirtualSCSIController scsiController = getFirstAvailableController(VirtualSCSIController.class);
  int unitNumber = getFirstFreeUnitNumberForController(scsiController);

  VirtualDisk disk = new VirtualDisk();
  disk.setControllerKey(scsiController.key);
  disk.setUnitNumber(unitNumber);
  disk.setBacking(diskfileBacking);
  //Unlike required by API ref, the capacityKB is optional. So skip setCapacityInKB() method.
  disk.setKey(-100);

  diskSpec.setOperation(VirtualDeviceConfigSpecOperation.add);           
  diskSpec.setDevice(disk);                 
  
  Task task = vm.reconfigVM_Task(vmConfigSpec);

  task.waitForTask(200, 100);
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:31,代码来源:VirtualMachineDeviceManager.java

示例2: createHardDisk

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public void createHardDisk(int diskSizeMB, VirtualDiskType type, VirtualDiskMode mode) throws Exception
{
  VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
  VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();      
  
  VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();
  diskfileBacking.setFileName("");
  diskfileBacking.setDiskMode(mode.toString());
  diskfileBacking.setThinProvisioned(type==VirtualDiskType.thin);

  VirtualSCSIController scsiController = getFirstAvailableController(VirtualSCSIController.class);
  int unitNumber = getFirstFreeUnitNumberForController(scsiController);
  VirtualDisk disk = new VirtualDisk();
  disk.setControllerKey(scsiController.key);
  disk.setUnitNumber(unitNumber);
  disk.setBacking(diskfileBacking);
  disk.setCapacityInKB(1024 * diskSizeMB);
  disk.setKey(-1);
  
  diskSpec.setOperation(VirtualDeviceConfigSpecOperation.add);           
  diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);           
  diskSpec.setDevice(disk);
  VirtualDeviceConfigSpec vdiskSpec = diskSpec;
  VirtualDeviceConfigSpec [] vdiskSpecArray = {vdiskSpec};         

  vmConfigSpec.setDeviceChange(vdiskSpecArray);
  Task task = vm.reconfigVM_Task(vmConfigSpec);

  task.waitForTask(200, 100);
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:31,代码来源:VirtualMachineDeviceManager.java

示例3: createNetworkAdapter

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
/** 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);
 }
 
开发者ID:Juniper,项目名称:vijava,代码行数:32,代码来源:VirtualMachineDeviceManager.java

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

示例5: main

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception 
{     
  if(args.length!=6)
  {
    System.out.println("Usage: java VmNicOp <url> " +
          "<username> <password> <vmname> <op> <name>");
    System.out.println("op - add|remove");
    System.out.println("name - NIC name when remove; " +
    		"Network name when add");
    System.exit(0);
  }
  String vmname = args[3];
  String op = args[4];
  String name = args[5];
 
  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  Folder rootFolder = si.getRootFolder();
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
    rootFolder).searchManagedEntity("VirtualMachine", vmname);

  if(vm==null)
  {
    System.out.println("No VM " + vmname + " found");
    si.getServerConnection().logout();
    return;
  }
  
  VirtualMachineConfigSpec vmConfigSpec = 
    new VirtualMachineConfigSpec();
  
  
  VirtualDeviceConfigSpec nicSpec = 
    getNICDeviceConfigSpec(vm, op, name);
  
  String result = null;
  if(nicSpec!=null)
  {
    vmConfigSpec.setDeviceChange(
        new VirtualDeviceConfigSpec []{nicSpec});
    Task task = vm.reconfigVM_Task(vmConfigSpec);
    result = task.waitForMe();
  }

  if(result==Task.SUCCESS)
  {
    System.out.println("Done with NIC for VM:" + vmname);
  }
  else
  {
    System.out.println("Failed with NIC for VM:" + vmname);
  }
  
  si.getServerConnection().logout();
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:57,代码来源:VmNicOp.java

示例6: main

import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception 
{     
  if(args.length!=5)
  {
    System.out.println("Usage: java RemoveVmDisk <url> " +
          "<username> <password> <vmname> <diskname>");
    System.exit(0);
  }
  String vmname = args[3];
  String diskName = args[4];
 
  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  Folder rootFolder = si.getRootFolder();
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
    rootFolder).searchManagedEntity("VirtualMachine", vmname);

  if(vm==null)
  {
    System.out.println("No VM " + vmname + " found");
    si.getServerConnection().logout();
    return;
  }
  
  VirtualMachineConfigSpec vmConfigSpec = 
      new VirtualMachineConfigSpec();

  VirtualDeviceConfigSpec vdiskSpec = 
      createRemoveDiskConfigSpec(vm.getConfig(), diskName);
  vmConfigSpec.setDeviceChange(
      new VirtualDeviceConfigSpec[]{vdiskSpec} );
  Task task = vm.reconfigVM_Task(vmConfigSpec);
  
  if(task.waitForMe()==Task.SUCCESS)
  {
    System.out.println("Disk removed.");
  }
  else
  {
    System.out.println("Error while removing disk");
  }
  
  si.getServerConnection().logout();
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:46,代码来源:RemoveVmDisk.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


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