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

项目:oscm    文件:NetworkManager.java   
private static void replaceNetworkAdapter(
        VirtualMachineConfigSpec vmConfigSpec, VirtualDevice oldNIC,
        ManagedObjectReference newNetworkRef, String newNetworkName)
        throws Exception {
    logger.debug("new network: " + newNetworkName);
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(newNetworkName);
    nicBacking.setNetwork(newNetworkRef);
    nicBacking.setUseAutoDetect(true);
    oldNIC.setBacking(nicBacking);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    // oldNIC.getConnectable().setConnected(true);
    // oldNIC.getConnectable().setStartConnected(true);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
项目:photon-model    文件:ClientUtils.java   
public static VirtualDeviceConfigSpec createCdrom(VirtualDevice ideController, int unitNumber) {
    VirtualCdrom cdrom = new VirtualCdrom();

    cdrom.setControllerKey(ideController.getKey());
    cdrom.setUnitNumber(unitNumber);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setAllowGuestControl(true);
    info.setConnected(true);
    info.setStartConnected(true);
    cdrom.setConnectable(info);

    VirtualCdromAtapiBackingInfo backing = new VirtualCdromAtapiBackingInfo();
    backing.setDeviceName(String.format("cdrom-%d-%d", ideController.getKey(), unitNumber));
    backing.setUseAutoDetect(false);
    cdrom.setBacking(backing);

    VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();
    spec.setDevice(cdrom);
    spec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

    return spec;
}
项目:photon-model    文件:ClientUtils.java   
public static VirtualDeviceConfigSpec createFloppy(VirtualDevice sioController, int unitNumber) {
    VirtualFloppy floppy = new VirtualFloppy();

    floppy.setControllerKey(sioController.getKey());
    floppy.setUnitNumber(unitNumber);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setAllowGuestControl(true);
    info.setConnected(true);
    info.setStartConnected(true);
    floppy.setConnectable(info);

    VirtualFloppyDeviceBackingInfo backing = new VirtualFloppyDeviceBackingInfo();
    backing.setDeviceName(String.format("floppy-%d", unitNumber));
    floppy.setBacking(backing);

    VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();
    spec.setDevice(floppy);
    spec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    return spec;
}
项目:photon-model    文件:InstanceClient.java   
/**
 * Get customization config spec for all the image disks if any
 */
private List<VirtualDeviceConfigSpec> getCustomizationConfigSpecs(ArrayOfVirtualDevice devices,
        List<DiskStateExpanded> diskStates)
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    List<VirtualDeviceConfigSpec> specs = new ArrayList<>();
    List<VirtualDisk> virtualDisks = devices.getVirtualDevice().stream()
            .filter(d -> d instanceof VirtualDisk)
            .map(d -> (VirtualDisk) d)
            .collect(Collectors.toList());

    for (VirtualDisk vd : virtualDisks) {
        VirtualDeviceConfigSpec diskSpec = getBootDiskCustomizeConfigSpec(
                findMatchingImageDiskState(vd, diskStates), vd);
        if (diskSpec != null) {
            specs.add(diskSpec);
        }
    }
    return specs;
}
项目:photon-model    文件:InstanceClient.java   
private VirtualDeviceConfigSpec reconfigureCdrom(VirtualCdrom vcd) {
    VirtualCdrom cdrom = new VirtualCdrom();

    cdrom.setControllerKey(vcd.getControllerKey());
    cdrom.setKey(vcd.getKey());
    cdrom.setUnitNumber(vcd.getUnitNumber());

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setAllowGuestControl(true);
    info.setConnected(true);
    info.setStartConnected(true);
    cdrom.setConnectable(info);

    cdrom.setBacking(vcd.getBacking());

    VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();
    spec.setDevice(cdrom);
    spec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);

    return spec;
}
项目:photon-model    文件:InstanceDiskClient.java   
public void detachDiskFromVM() throws Exception {
    ArrayOfVirtualDevice devices = this.get
            .entityProp(this.vm, VimPath.vm_config_hardware_device);
    VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices));
    if (vd == null) {
        throw new IllegalStateException(
                String.format(
                        "Matching Virtual Disk is not for disk %s.",
                        this.diskState.documentSelfLink));
    }
    // Detach the disk from VM.
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
    deviceConfigSpec.setDevice(vd);

    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    spec.getDeviceChange().add(deviceConfigSpec);

    ManagedObjectReference reconfigureTask = getVimPort().reconfigVMTask(this.vm, spec);
    TaskInfo info = VimUtils.waitTaskEnd(this.connection, reconfigureTask);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
}
项目:development    文件:NetworkManager.java   
private static void replaceNetworkAdapter(
        VirtualMachineConfigSpec vmConfigSpec, VirtualDevice oldNIC,
        ManagedObjectReference newNetworkRef, String newNetworkName)
        throws Exception {
    logger.debug("new network: " + newNetworkName);
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(newNetworkName);
    nicBacking.setNetwork(newNetworkRef);
    nicBacking.setUseAutoDetect(true);
    oldNIC.setBacking(nicBacking);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    // oldNIC.getConnectable().setConnected(true);
    // oldNIC.getConnectable().setStartConnected(true);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
项目:vijava    文件:VmDiskOp.java   
static VirtualDeviceConfigSpec createRemoveDiskConfigSpec(
    VirtualMachine vm, String diskName) throws Exception
{
  VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();      
  VirtualDisk disk = (VirtualDisk) findVirtualDevice(vm.getConfig(), diskName);

  if(disk != null)
  {
    diskSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);           
    diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);           
    diskSpec.setDevice(disk);
    return diskSpec;
  }
  else 
  {
    System.out.println("No device found: " + diskName);
    return null;
  }
}
项目:vijava    文件:VmCdOp.java   
static VirtualDeviceConfigSpec createAddCdConfigSpec(VirtualMachine vm, String dsName, String isoName) throws Exception 
{
  VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec();

  cdSpec.setOperation(VirtualDeviceConfigSpecOperation.add);         

  VirtualCdrom cdrom =  new VirtualCdrom();
  VirtualCdromIsoBackingInfo cdDeviceBacking = new  VirtualCdromIsoBackingInfo();
  DatastoreSummary ds = findDatastoreSummary(vm, dsName);
  cdDeviceBacking.setDatastore(ds.getDatastore());
  cdDeviceBacking.setFileName("[" + dsName +"] "+ vm.getName() 
      + "/" + isoName + ".iso");
  VirtualDevice vd = getIDEController(vm);          
  cdrom.setBacking(cdDeviceBacking);                    
  cdrom.setControllerKey(vd.getKey());
  cdrom.setUnitNumber(vd.getUnitNumber());
  cdrom.setKey(-1);          

  cdSpec.setDevice(cdrom);

  return cdSpec;          
}
项目:vijava    文件:VmCdOp.java   
static VirtualDeviceConfigSpec createRemoveCdConfigSpec(VirtualMachine vm, String cdName) throws Exception 
{
  VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec();
  cdSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
  VirtualCdrom cdRemove = (VirtualCdrom)findVirtualDevice(vm.getConfig(), cdName);
  if(cdRemove != null) 
  {
    cdSpec.setDevice(cdRemove);
    return cdSpec;
  }
  else 
  {
    System.out.println("No device available " + cdName);
    return null;
  }
}
项目:vijava    文件:RemoveVmDisk.java   
static VirtualDeviceConfigSpec createRemoveDiskConfigSpec(
    VirtualMachineConfigInfo vmConfig, String diskName) 
        throws Exception
{
  VirtualDeviceConfigSpec diskSpec = 
      new VirtualDeviceConfigSpec();      
  VirtualDisk disk = (VirtualDisk) findVirtualDevice(
      vmConfig, diskName);

  if(disk != null)
  {
    diskSpec.setOperation(
        VirtualDeviceConfigSpecOperation.remove);    
    // remove the following line can keep the disk file
    diskSpec.setFileOperation(
        VirtualDeviceConfigSpecFileOperation.destroy);           
    diskSpec.setDevice(disk);
    return diskSpec;
  }
  else 
  {
    throw new Exception("No device found: " + diskName);
  }
}
项目:vijava    文件:CreateVM.java   
static VirtualDeviceConfigSpec createDiskSpec(String dsName, 
    int cKey, long diskSizeKB, String diskMode)
{
  VirtualDeviceConfigSpec diskSpec = 
      new VirtualDeviceConfigSpec();
  diskSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
  diskSpec.setFileOperation(
      VirtualDeviceConfigSpecFileOperation.create);

  VirtualDisk vd = new VirtualDisk();
  vd.setCapacityInKB(diskSizeKB);
  diskSpec.setDevice(vd);
  vd.setKey(0);
  vd.setUnitNumber(0);
  vd.setControllerKey(cKey);

  VirtualDiskFlatVer2BackingInfo diskfileBacking = 
      new VirtualDiskFlatVer2BackingInfo();
  String fileName = "["+ dsName +"]";
  diskfileBacking.setFileName(fileName);
  diskfileBacking.setDiskMode(diskMode);
  diskfileBacking.setThinProvisioned(true);
  vd.setBacking(diskfileBacking);
  return diskSpec;
}
项目:vijava    文件:CreateVM.java   
static VirtualDeviceConfigSpec createNicSpec(String netName, 
    String nicName) throws Exception
{
  VirtualDeviceConfigSpec nicSpec = 
      new VirtualDeviceConfigSpec();
  nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);

  VirtualEthernetCard nic =  new VirtualPCNet32();
  VirtualEthernetCardNetworkBackingInfo nicBacking = 
      new VirtualEthernetCardNetworkBackingInfo();
  nicBacking.setDeviceName(netName);

  Description info = new Description();
  info.setLabel(nicName);
  info.setSummary(netName);
  nic.setDeviceInfo(info);

  // type: "generated", "manual", "assigned" by VC
  nic.setAddressType("generated");
  nic.setBacking(nicBacking);
  nic.setKey(0);

  nicSpec.setDevice(nic);
  return nicSpec;
}
项目:cs-actions    文件:VmUtils.java   
VirtualDeviceConfigSpec getNicSpecs(String fileName, List<VirtualDevice> virtualDevicesList,
                                    VirtualDeviceConfigSpecOperation operation, String addressType,
                                    Integer key, String parameter, VmInputs vmInputs) {
    VirtualDeviceConfigSpec nicSpecs = new VirtualDeviceConfigSpec();
    VirtualEthernetCard nic;
    if (Operation.ADD.toString().equalsIgnoreCase(parameter)) {
        nic = getEth(fileName, addressType, key);
        return getNicOpSpec(nicSpecs, operation, nic);
    } else {
        nic = findVirtualDevice(VirtualEthernetCard.class, virtualDevicesList, vmInputs);
        if (nic != null) {
            return getNicOpSpec(nicSpecs, operation, nic);
        }
    }
    throw new RuntimeException("No nic named: [" + vmInputs.getUpdateValue() + "] can be found.");
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
    VirtualDevice[] devices = getMatchedDevices(deviceClasses);

    if (devices.length > 0) {
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];

        for (int i = 0; i < devices.length; i++) {
            deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
            deviceConfigSpecArray[i].setDevice(devices[i]);
            deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
            vmConfigSpec.getDeviceChange().add(deviceConfigSpecArray[i]);
        }

        if (!configureVm(vmConfigSpec)) {
            throw new Exception("Failed to detach devices");
        }
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void ensurePvScsiDeviceController(int requiredNumScsiControllers, int availableBusNum) throws Exception {
    VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();

    int busNum = availableBusNum;
    while (busNum < requiredNumScsiControllers) {
        ParaVirtualSCSIController scsiController = new ParaVirtualSCSIController();

        scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
        scsiController.setBusNumber(busNum);
        scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
        VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
        scsiControllerSpec.setDevice(scsiController);
        scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

        vmConfig.getDeviceChange().add(scsiControllerSpec);
        busNum++;
    }

    if (configureVm(vmConfig)) {
        throw new Exception("Unable to add Scsi controllers to the VM " + getName());
    } else {
        s_logger.info("Successfully added " + requiredNumScsiControllers + " SCSI controllers.");
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void ensureLsiLogicDeviceControllers(int count, int availableBusNum) throws Exception {
    int scsiControllerKey = getLsiLogicDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();

        int busNum = availableBusNum;
        while (busNum < count) {
            VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
            scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
            scsiController.setBusNumber(busNum);
            scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
            VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
            scsiControllerSpec.setDevice(scsiController);
            scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

            vmConfig.getDeviceChange().add(scsiControllerSpec);
            busNum++;
        }
        if (configureVm(vmConfig)) {
            throw new Exception("Unable to add Lsi Logic controllers to the VM " + getName());
        } else {
            s_logger.info("Successfully added " + count + " LsiLogic Parallel SCSI controllers.");
        }
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void ensureScsiDeviceController() throws Exception {
    int scsiControllerKey = getScsiDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();

        // Scsi controller
        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 (configureVm(vmConfig)) {
            throw new Exception("Unable to add Scsi controller");
        }
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void ensureScsiDeviceControllers(int count, int availableBusNum) throws Exception {
    int scsiControllerKey = getScsiDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();

        int busNum = availableBusNum;
        while (busNum < count) {
        VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
        scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
            scsiController.setBusNumber(busNum);
            scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
        VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
        scsiControllerSpec.setDevice(scsiController);
        scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

        vmConfig.getDeviceChange().add(scsiControllerSpec);
            busNum++;
        }
        if (configureVm(vmConfig)) {
            throw new Exception("Unable to add Scsi controllers to the VM " + getName());
        } else {
            s_logger.info("Successfully added " + count + " SCSI controllers.");
        }
    }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public void ensureLsiLogicSasDeviceControllers(int count, int availableBusNum) throws Exception {
    int scsiControllerKey = getLsiLogicSasDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();

        int busNum = availableBusNum;
        while (busNum < count) {
            VirtualLsiLogicSASController scsiController = new VirtualLsiLogicSASController();
            scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
            scsiController.setBusNumber(busNum);
            scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
            VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
            scsiControllerSpec.setDevice(scsiController);
            scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);

            vmConfig.getDeviceChange().add(scsiControllerSpec);
            busNum++;
        }
        if (configureVm(vmConfig)) {
            throw new Exception("Unable to add Scsi controller of type LsiLogic SAS.");
        }
    }

}
项目:oscm    文件:NetworkManager.java   
private static void connectNIC(VirtualMachineConfigSpec vmConfigSpec,
        VirtualDevice oldNIC, String vmNetworkName) throws Exception {

    logger.debug("networkName: " + vmNetworkName);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
项目:oscm    文件:DiskManager.java   
private void updateDiskConfiguration(VirtualMachineConfigSpec vmConfigSpec,
        List<VirtualDevice> devices, int vdKey, long newDiskSpace)
        throws Exception {
    VirtualDisk vdDataDisk = findDataDisk(devices, vdKey);
    if (vdDataDisk != null && newDiskSpace > vdDataDisk.getCapacityInKB()) {

        logger.info("reconfigureDisks() extend data disk #" + vdKey
                + " space to " + newDiskSpace + " ("
                + vdDataDisk.getDeviceInfo().getLabel() + ")");

        if (newDiskSpace < vdDataDisk.getCapacityInKB()) {
            logger.error("Cannot reduce size of data disk "
                    + vdDataDisk.getDeviceInfo().getLabel());
            logger.error("Current disk space: "
                    + vdDataDisk.getCapacityInKB() + " new disk space: "
                    + newDiskSpace);
            throw new Exception(Messages
                    .getAll("error_invalid_diskspacereduction").get(0)
                    .getText());
        } else if (newDiskSpace > vdDataDisk.getCapacityInKB()) {
            vdDataDisk.setCapacityInKB(newDiskSpace);
            VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
            vmDeviceSpec
                    .setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmDeviceSpec.setDevice(vdDataDisk);

            vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
        } else {
            logger.debug("Data disk size has not been changed. "
                    + newDiskSpace + " KB");
        }
    }
}
项目:oscm    文件:DiskManager.java   
private VirtualDeviceConfigSpec createNewDataDisk(VirtualDisk vdSystemDisk,
        long newDiskSpace, int deviceKey, int unitNumber) throws Exception {

    logger.info("reconfigureDisks() create data disk space with "
            + newDiskSpace + " KB");

    ManagedObjectReference vmDatastore = ((VirtualDeviceFileBackingInfo) vdSystemDisk
            .getBacking()).getDatastore();
    String vmDatastoreName = (String) vmw.getServiceUtil()
            .getDynamicProperty(vmDatastore, "summary.name");

    VirtualDisk vdDataDisk = new VirtualDisk();
    VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();
    diskfileBacking.setFileName("[" + vmDatastoreName + "]");
    diskfileBacking.setDiskMode("persistent");

    vdDataDisk.setKey(deviceKey);
    vdDataDisk.setControllerKey(vdSystemDisk.getControllerKey());
    vdDataDisk.setUnitNumber(new Integer(unitNumber));
    vdDataDisk.setBacking(diskfileBacking);
    vdDataDisk.setCapacityInKB(newDiskSpace);

    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    vmDeviceSpec
            .setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
    vmDeviceSpec.setDevice(vdDataDisk);

    return vmDeviceSpec;
}
项目:oscm    文件:DiskManager.java   
private void configureSystemDisk(VirtualMachineConfigSpec vmConfigSpec,
        long systemDiskMB, VirtualDisk vdSystemDisk) throws Exception {
    if (systemDiskMB > 0) {
        long newDiskSpace = systemDiskMB * 1024;
        if (newDiskSpace < vdSystemDisk.getCapacityInKB()) {
            logger.error("Cannot reduce size of system disk \""
                    + vdSystemDisk.getDeviceInfo().getLabel() + "\"");
            logger.error("Current disk size: "
                    + vdSystemDisk.getCapacityInKB() + " new disk space: "
                    + newDiskSpace);

            throw new Exception(Messages
                    .getAll("error_invalid_diskspacereduction").get(0)
                    .getText());
        } else if (newDiskSpace > vdSystemDisk.getCapacityInKB()) {
            logger.info("reconfigureDisks() extend system disk space to "
                    + newDiskSpace + " ("
                    + vdSystemDisk.getDeviceInfo().getLabel() + ")");
            vdSystemDisk.setCapacityInKB(newDiskSpace);
            VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
            vmDeviceSpec
                    .setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmDeviceSpec.setDevice(vdSystemDisk);
            vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
        } else {
            logger.debug("System disk size has not been changed. "
                    + newDiskSpace + " KB");
        }
    } else {
        logger.error("Reconfiguration of system disk not possible because system disk size is not defined.");
    }
}
项目:photon-model    文件:ClientUtils.java   
/**
 * Creates HDD virtual disk
 */
public static VirtualDeviceConfigSpec createHdd(Integer controllerKey, int unitNumber,
        DiskService.DiskStateExpanded ds, String diskName, ManagedObjectReference datastore,
        List<VirtualMachineDefinedProfileSpec> pbmSpec)
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    return createHdd(controllerKey, unitNumber, ds, diskName, datastore, pbmSpec, true);
}
项目:photon-model    文件:ClientUtils.java   
/**
 * Creates HDD virtual disk
 */
public static VirtualDeviceConfigSpec createHdd(Integer controllerKey, int unitNumber,
        DiskService.DiskStateExpanded ds, String diskName, ManagedObjectReference datastore,
        List<VirtualMachineDefinedProfileSpec> pbmSpec, boolean isCreateFile)
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    VirtualDiskFlatVer2BackingInfo backing = new VirtualDiskFlatVer2BackingInfo();
    backing.setDiskMode(getDiskMode(ds));
    VirtualDiskType provisionType = getDiskProvisioningType(ds);
    if (provisionType != null) {
        backing.setThinProvisioned(provisionType == VirtualDiskType.THIN);
        backing.setEagerlyScrub(provisionType == VirtualDiskType.EAGER_ZEROED_THICK);
    }
    backing.setFileName(diskName);
    backing.setDatastore(datastore);

    VirtualDisk disk = new VirtualDisk();
    disk.setCapacityInKB(toKb(ds.capacityMBytes));
    disk.setBacking(backing);
    disk.setStorageIOAllocation(getStorageIOAllocationInfo(ds));
    disk.setControllerKey(controllerKey);
    disk.setUnitNumber(unitNumber);
    fillInControllerUnitNumber(ds, unitNumber);
    disk.setKey(-1);

    VirtualDeviceConfigSpec change = new VirtualDeviceConfigSpec();
    change.setDevice(disk);
    if (pbmSpec != null) {
        // Add storage policy spec
        pbmSpec.stream().forEach(sp -> {
            change.getProfile().add(sp);
        });
    }
    change.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    if (isCreateFile) {
        change.setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
    }

    return change;
}
项目:photon-model    文件:InstanceClient.java   
/**
 * Reconfigure image disk with the customizations
 */
private void reconfigureBootDisk(ManagedObjectReference vmMoref,
        List<VirtualDeviceConfigSpec> deviceConfigSpecs) throws Exception {
    if (deviceConfigSpecs != null && !deviceConfigSpecs.isEmpty()) {
        VirtualMachineConfigSpec bootDiskSpec = new VirtualMachineConfigSpec();
        bootDiskSpec.getDeviceChange().addAll(deviceConfigSpecs);
        ManagedObjectReference task = getVimPort().reconfigVMTask(vmMoref, bootDiskSpec);
        TaskInfo info = waitTaskEnd(task);

        if (info.getState() == TaskInfoState.ERROR) {
            VimUtils.rethrow(info.getError());
        }
    }
}
项目:photon-model    文件:InstanceClient.java   
/**
 * Construct VM config spec for boot disk size customization, if the user defined value is
 * greater then the existing size of the disk
 */
private VirtualDeviceConfigSpec getBootDiskCustomizeConfigSpec(DiskStateExpanded disk, VirtualDisk virtualDisk)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
    if (disk != null && virtualDisk != null) {
        // Resize happens if the new size is more than the existing disk size, other storage
        // related attributes will be applied the disk.
        VirtualDeviceConfigSpec hdd = resizeHdd(virtualDisk, disk);
        return hdd;
    }
    return null;
}
项目:photon-model    文件:InstanceClient.java   
private VirtualDeviceConfigSpec resizeHdd(VirtualDisk sysdisk, DiskStateExpanded ds)
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    VirtualDiskFlatVer2BackingInfo oldbacking = (VirtualDiskFlatVer2BackingInfo) sysdisk
            .getBacking();
    VirtualDiskFlatVer2BackingInfo backing = new VirtualDiskFlatVer2BackingInfo();
    backing.setDiskMode(getDiskMode(ds));
    backing.setThinProvisioned(oldbacking.isThinProvisioned());
    backing.setEagerlyScrub(oldbacking.isEagerlyScrub());
    backing.setFileName(oldbacking.getFileName());

    VirtualDisk disk = new VirtualDisk();
    if (toKb(ds.capacityMBytes) > sysdisk.getCapacityInKB()) {
        disk.setCapacityInKB(toKb(ds.capacityMBytes));
    } else {
        disk.setCapacityInKB(sysdisk.getCapacityInKB());
    }
    disk.setBacking(backing);
    disk.setStorageIOAllocation(getStorageIOAllocationInfo(ds));
    disk.setControllerKey(sysdisk.getControllerKey());
    disk.setUnitNumber(sysdisk.getUnitNumber());
    fillInControllerUnitNumber(ds, sysdisk.getUnitNumber());
    disk.setKey(sysdisk.getKey());

    VirtualDeviceConfigSpec change = new VirtualDeviceConfigSpec();
    change.setDevice(disk);
    change.setOperation(VirtualDeviceConfigSpecOperation.EDIT);

    return change;
}
项目:development    文件:NetworkManager.java   
private static void connectNIC(VirtualMachineConfigSpec vmConfigSpec,
        VirtualDevice oldNIC, String vmNetworkName) throws Exception {

    logger.debug("networkName: " + vmNetworkName);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
项目:development    文件:DiskManager.java   
private void updateDiskConfiguration(VirtualMachineConfigSpec vmConfigSpec,
        List<VirtualDevice> devices, int vdKey, long newDiskSpace)
        throws Exception {
    VirtualDisk vdDataDisk = findDataDisk(devices, vdKey);
    if (vdDataDisk != null && newDiskSpace > vdDataDisk.getCapacityInKB()) {

        logger.info("reconfigureDisks() extend data disk #" + vdKey
                + " space to " + newDiskSpace + " ("
                + vdDataDisk.getDeviceInfo().getLabel() + ")");

        if (newDiskSpace < vdDataDisk.getCapacityInKB()) {
            logger.error("Cannot reduce size of data disk "
                    + vdDataDisk.getDeviceInfo().getLabel());
            logger.error("Current disk space: "
                    + vdDataDisk.getCapacityInKB() + " new disk space: "
                    + newDiskSpace);
            throw new Exception(Messages
                    .getAll("error_invalid_diskspacereduction").get(0)
                    .getText());
        } else if (newDiskSpace > vdDataDisk.getCapacityInKB()) {
            vdDataDisk.setCapacityInKB(newDiskSpace);
            VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
            vmDeviceSpec
                    .setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmDeviceSpec.setDevice(vdDataDisk);

            vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
        } else {
            logger.debug("Data disk size has not been changed. "
                    + newDiskSpace + " KB");
        }
    }
}
项目:development    文件:DiskManager.java   
private VirtualDeviceConfigSpec createNewDataDisk(VirtualDisk vdSystemDisk,
        long newDiskSpace, int deviceKey, int unitNumber) throws Exception {

    logger.info("reconfigureDisks() create data disk space with "
            + newDiskSpace + " KB");

    ManagedObjectReference vmDatastore = ((VirtualDeviceFileBackingInfo) vdSystemDisk
            .getBacking()).getDatastore();
    String vmDatastoreName = (String) vmw.getServiceUtil()
            .getDynamicProperty(vmDatastore, "summary.name");

    VirtualDisk vdDataDisk = new VirtualDisk();
    VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();
    diskfileBacking.setFileName("[" + vmDatastoreName + "]");
    diskfileBacking.setDiskMode("persistent");

    vdDataDisk.setKey(deviceKey);
    vdDataDisk.setControllerKey(vdSystemDisk.getControllerKey());
    vdDataDisk.setUnitNumber(new Integer(unitNumber));
    vdDataDisk.setBacking(diskfileBacking);
    vdDataDisk.setCapacityInKB(newDiskSpace);

    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    vmDeviceSpec
            .setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
    vmDeviceSpec.setDevice(vdDataDisk);

    return vmDeviceSpec;
}
项目:development    文件:DiskManager.java   
private void configureSystemDisk(VirtualMachineConfigSpec vmConfigSpec,
        long systemDiskMB, VirtualDisk vdSystemDisk) throws Exception {
    if (systemDiskMB > 0) {
        long newDiskSpace = systemDiskMB * 1024;
        if (newDiskSpace < vdSystemDisk.getCapacityInKB()) {
            logger.error("Cannot reduce size of system disk \""
                    + vdSystemDisk.getDeviceInfo().getLabel() + "\"");
            logger.error("Current disk size: "
                    + vdSystemDisk.getCapacityInKB() + " new disk space: "
                    + newDiskSpace);

            throw new Exception(Messages
                    .getAll("error_invalid_diskspacereduction").get(0)
                    .getText());
        } else if (newDiskSpace > vdSystemDisk.getCapacityInKB()) {
            logger.info("reconfigureDisks() extend system disk space to "
                    + newDiskSpace + " ("
                    + vdSystemDisk.getDeviceInfo().getLabel() + ")");
            vdSystemDisk.setCapacityInKB(newDiskSpace);
            VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
            vmDeviceSpec
                    .setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmDeviceSpec.setDevice(vdSystemDisk);
            vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
        } else {
            logger.debug("System disk size has not been changed. "
                    + newDiskSpace + " KB");
        }
    } else {
        logger.error("Reconfiguration of system disk not possible because system disk size is not defined.");
    }
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
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);
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
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);
}
项目: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    文件:CreateVM.java   
static VirtualDeviceConfigSpec createScsiSpec(int cKey)
{
  VirtualDeviceConfigSpec scsiSpec = 
    new VirtualDeviceConfigSpec();
  scsiSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
  VirtualLsiLogicController scsiCtrl = 
      new VirtualLsiLogicController();
  scsiCtrl.setKey(cKey);
  scsiCtrl.setBusNumber(0);
  scsiCtrl.setSharedBus(VirtualSCSISharing.noSharing);
  scsiSpec.setDevice(scsiCtrl);
  return scsiSpec;
}
项目:cs-actions    文件:VmUtils.java   
public VirtualMachineConfigSpec getAddOrRemoveSpecs(ConnectionResources connectionResources, ManagedObjectReference vmMor,
                                                    VmInputs vmInputs, VirtualMachineConfigSpec vmConfigSpec, String device)
        throws Exception {
    VmConfigSpecs vmConfigSpecs = new VmConfigSpecs();
    VirtualDeviceConfigSpec deviceConfigSpec;
    switch (device) {
        case DISK:
            InputUtils.checkValidOperation(vmInputs, device);
            InputUtils.validateDiskInputs(vmInputs);
            deviceConfigSpec = vmConfigSpecs.getDiskDeviceConfigSpec(connectionResources, vmMor, vmInputs);
            break;
        case CD:
            InputUtils.checkValidOperation(vmInputs, device);
            deviceConfigSpec = vmConfigSpecs.getCDDeviceConfigSpec(connectionResources, vmMor, vmInputs);
            break;
        case NIC:
            InputUtils.checkValidOperation(vmInputs, device);
            deviceConfigSpec = vmConfigSpecs.getNICDeviceConfigSpec(connectionResources, vmMor, vmInputs);
            break;
        default:
            throw new RuntimeException("Invalid operation specified for " + device + " device. " +
                    "The " + device + " device can be only added or removed.");
    }
    List<VirtualDeviceConfigSpec> specs = new ArrayList<>();
    specs.add(deviceConfigSpec);
    vmConfigSpec.getDeviceChange().addAll(specs);

    return vmConfigSpec;
}
项目:cs-actions    文件:VmUtils.java   
VirtualDeviceConfigSpec getPopulatedCDSpecs(String fileName, ManagedObjectReference dataStoreRef,
                                            List<VirtualDevice> virtualDevicesList,
                                            VirtualDeviceConfigSpecOperation operation,
                                            Integer controllerKey, Integer unitNumber, Integer key,
                                            String parameter, VmInputs vmInputs) {

    VirtualDeviceConfigSpec cdSpecs = new VirtualDeviceConfigSpec();
    if (Operation.ADD.toString().equalsIgnoreCase(parameter)) {
        VirtualCdromIsoBackingInfo cdIsoBacking = new VirtualCdromIsoBackingInfo();
        cdIsoBacking.setDatastore(dataStoreRef);
        cdIsoBacking.setFileName(fileName + TEST_CD_ISO);

        VirtualCdrom cdRom = new VirtualCdrom();
        cdRom.setBacking(cdIsoBacking);
        cdRom.setControllerKey(controllerKey);
        cdRom.setUnitNumber(unitNumber);
        cdRom.setKey(key);

        return getCDSpec(cdSpecs, operation, cdRom);
    } else {
        VirtualCdrom cdRemove = findVirtualDevice(VirtualCdrom.class, virtualDevicesList, vmInputs);
        if (cdRemove != null) {
            return getCDSpec(cdSpecs, operation, cdRemove);
        }
    }
    throw new RuntimeException("No optical device named: [" + vmInputs.getUpdateValue() + "] can be found.");
}
项目:cs-actions    文件:VmUtils.java   
private VirtualDeviceConfigSpec getDiskSpecs(VirtualDeviceConfigSpec diskSpecs, VirtualDeviceConfigSpecOperation operation,
                                             VirtualDeviceConfigSpecFileOperation fileOperation, VirtualDisk disk) {
    diskSpecs.setOperation(operation);
    diskSpecs.setFileOperation(fileOperation);
    diskSpecs.setDevice(disk);

    return diskSpecs;
}