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

项目:primecloud-controller    文件:VmwareCustomizeProcess.java   
protected List<CustomizationAdapterMapping> createCustomizationAdapterMappings(
        VmwareProcessClient vmwareProcessClient, VirtualMachine machine) {

    List<CustomizationAdapterMapping> nicSettingMap = new ArrayList<CustomizationAdapterMapping>();

    // VirtualEthernetCardを取得
    VirtualMachineConfigInfo configInfo = machine.getConfig();
    for (VirtualDevice device : configInfo.getHardware().getDevice()) {
        if (device instanceof VirtualEthernetCard) {
            VirtualEthernetCard virtualEthernetCard = VirtualEthernetCard.class.cast(device);
            CustomizationAdapterMapping mapping = new CustomizationAdapterMapping();
            CustomizationIPSettings settings = new CustomizationIPSettings();

            // すべてのNICをDHCPにする
            CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator();
            settings.setIp(dhcpIp);

            mapping.setMacAddress(virtualEthernetCard.getMacAddress());
            mapping.setAdapter(settings);
            nicSettingMap.add(mapping);
        }
    }

    return nicSettingMap;
}
项目: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);
}
项目:oscm    文件:DiskManager.java   
/**
 * Reconfigures VMware system disks and data disks.
 */
public void reconfigureDisks(VirtualMachineConfigSpec vmConfigSpec,
        ManagedObjectReference vmwInstance) throws Exception {

    logger.debug("");

    long systemDiskMB = (long) paramHandler.getConfigDiskSpaceMB();
    VirtualMachineConfigInfo configSpec = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    VirtualDisk vdSystemDisk = getVMSystemDisk(devices,
            configSpec.getName());

    configureSystemDisk(vmConfigSpec, systemDiskMB, vdSystemDisk);
    configureDataDisks(vmConfigSpec, devices, vdSystemDisk);
}
项目:oscm    文件:VM.java   
private int getDataDiskKey() throws Exception {
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    int countDisks = 0;
    int key = -1;
    for (VirtualDevice vdInfo : devices) {
        if (vdInfo instanceof VirtualDisk) {
            countDisks++;
            if (countDisks == 2) {
                key = ((VirtualDisk) vdInfo).getKey();
                break;
            }
        }
    }

    return key;
}
项目:oscm    文件:VM.java   
private String getDiskSizeInGB(int disk) throws Exception {
    String size = "";
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    int countDisks = 0;
    for (VirtualDevice vdInfo : devices) {
        if (vdInfo instanceof VirtualDisk) {
            countDisks++;
            if (countDisks == disk) {
                long gigabyte = ((VirtualDisk) vdInfo).getCapacityInKB()
                        / 1024 / 1024;
                size = Long.toString(gigabyte);
                break;
            }
        }
    }

    return size;
}
项目: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    文件:ClientUtils.java   
/**
 * Capture virtual cdrom attributes in the disk state for reference.
 */
public static void updateDiskStateFromVirtualDevice(VirtualDevice vd, DiskService.DiskState
        disk, VirtualDeviceBackingInfo backing) {
    fillInControllerUnitNumber(disk, vd.getUnitNumber());
    if (backing != null && backing instanceof VirtualDeviceFileBackingInfo) {
        disk.sourceImageReference = VimUtils
                .datastorePathToUri(((VirtualDeviceFileBackingInfo) backing).getFileName());
    }
    disk.status = DiskService.DiskStatus.ATTACHED;
    CustomProperties.of(disk)
            .put(PROVIDER_DISK_UNIQUE_ID, vd.getDeviceInfo().getLabel());
    if (vd.getConnectable() != null) {
        CustomProperties.of(disk)
                .put(DEVICE_CONNECTED, vd.getConnectable().isConnected())
                .put(DEVICE_STATUS, vd.getConnectable().getStatus());
    }
}
项目:photon-model    文件:VSphereAdapterInstanceService.java   
/**
 * Update the details of the disk into compute state after the provisioning is successful
 */
private void updateDiskLinksAfterProvisionSuccess(ComputeState state, List<VirtualDevice> disks,
        ProvisionContext ctx) {
    ArrayList<String> diskLinks = new ArrayList<>(disks.size());
    // Fill in the disk links from the input to the ComputeState, as it may contain non hdd
    // disk as well. For ex, Floppy or CD-Rom
    ctx.disks.stream().forEach(ds -> diskLinks.add(ds.documentSelfLink));

    // Handle all the HDD disk
    for (VirtualDevice disk : disks) {
        DiskStateExpanded matchedDs = findMatchingDiskState(disk, ctx.disks);

        if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
            handleVirtualDiskUpdate(matchedDs, (VirtualDisk) disk, diskLinks, ctx);
        } else if (disk instanceof VirtualCdrom) {
            handleVirtualDeviceUpdate(matchedDs, DiskType.CDROM, disk, diskLinks, ctx);
        } else if (disk instanceof VirtualFloppy) {
            handleVirtualDeviceUpdate(matchedDs, DiskType.FLOPPY, disk, diskLinks, ctx);
        } else {
            continue;
        }
    }
    state.diskLinks = diskLinks;
}
项目: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);
}
项目:development    文件:VM.java   
private int getDataDiskKey() throws Exception {
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    int countDisks = 0;
    int key = -1;
    for (VirtualDevice vdInfo : devices) {
        if (vdInfo instanceof VirtualDisk) {
            countDisks++;
            if (countDisks == 2) {
                key = ((VirtualDisk) vdInfo).getKey();
                break;
            }
        }
    }

    return key;
}
项目:development    文件:VM.java   
private String getDiskSizeInGB(int disk) throws Exception {
    String size = "";
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    int countDisks = 0;
    for (VirtualDevice vdInfo : devices) {
        if (vdInfo instanceof VirtualDisk) {
            countDisks++;
            if (countDisks == disk) {
                long gigabyte = ((VirtualDisk) vdInfo).getCapacityInKB()
                        / 1024 / 1024;
                size = Long.toString(gigabyte);
                break;
            }
        }
    }

    return size;
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
protected VirtualSCSIController getSCSIController(VirtualMachine machine) {
    // 仮想マシンにあるSCSIコントローラのうち、BusNumberが0のものを取得する
    VirtualSCSIController scsiController = null;
    for (VirtualDevice device : machine.getConfig().getHardware().getDevice()) {
        if (device instanceof VirtualSCSIController) {
            VirtualSCSIController scsiController2 = VirtualSCSIController.class.cast(device);
            if (scsiController2.getBusNumber() == 0) {
                scsiController = scsiController2;
                break;
            }
        }
    }

    if (scsiController == null) {
        // SCSIコントローラが見つからない場合
        // TODO: SCSIコントローラを作る?
        throw new AutoException("EPROCESS-000517", 0);
    }

    return scsiController;
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
protected VirtualDisk getVirtualDisk(VirtualMachine machine, Integer scsiId) {
    // SCSIコントローラを取得
    VirtualSCSIController scsiController = getSCSIController(machine);

    // SCSIコントローラとSCSI IDが一致するディスクを取得
    VirtualDisk disk = null;
    for (VirtualDevice device : machine.getConfig().getHardware().getDevice()) {
        if (device instanceof VirtualDisk) {
            VirtualDisk tmpDisk = VirtualDisk.class.cast(device);
            if (tmpDisk.getControllerKey() != null && tmpDisk.getControllerKey().equals(scsiController.getKey())) {
                if (tmpDisk.getUnitNumber() != null && tmpDisk.getUnitNumber().equals(scsiId)) {
                    disk = tmpDisk;
                    break;
                }
            }
        }
    }

    if (disk == null) {
        // VirtualDiskが見つからない場合
        throw new AutoException("EPROCESS-000518", scsiId);
    }

    return disk;
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
public VirtualDisk findHardDisk(String diskName) 
{
  VirtualDevice[] devices = getAllVirtualDevices();

  for(int i=0; i<devices.length; i++) 
  {
    if(devices[i] instanceof VirtualDisk) 
    {
      VirtualDisk vDisk = (VirtualDisk)devices[i];
      if(diskName.equalsIgnoreCase(vDisk.getDeviceInfo().getLabel())) 
      {
        return vDisk;
      }
    }
  }
  return null;
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
@SuppressWarnings("unchecked")
public <T extends VirtualDevice> List<T> getVirtualDevicesOfType(Class<T> clazz) 
{
  List<T> result = new ArrayList<T>();

  VirtualDevice[] devices = getAllVirtualDevices();

  for(VirtualDevice dev : devices)
  {
    if(clazz.isInstance(dev)) // dynamic equivalent of instanceof operator
    {
      result.add((T)dev);
    }
  }
  return result;
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
public VirtualDevice getDeviceByBackingFileName(String name)
{
  if(name==null)
  {
    throw new IllegalArgumentException("name must not be null!");
  }

  VirtualDevice[] devices = this.getAllVirtualDevices(); 

  for(VirtualDevice device : devices)
  {
    VirtualDeviceBackingInfo bi = device.getBacking();
    if(bi instanceof VirtualDeviceFileBackingInfo)
    {
      String fileName = ((VirtualDeviceFileBackingInfo)bi).getFileName();
      if(name.equals(fileName))
        return device;
    }
   }
   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 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    文件: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 int getScsiDiskControllerKey(String diskController) throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if ((DiskControllerType.getType(diskController) == DiskControllerType.lsilogic || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualLsiLogicController) {
                return ((VirtualLsiLogicController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.lsisas1068 || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualLsiLogicSASController) {
                return ((VirtualLsiLogicSASController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.pvscsi || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof ParaVirtualSCSIController) {
                return ((ParaVirtualSCSIController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.buslogic || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualBusLogicController) {
                return ((VirtualBusLogicController)device).getKey();
            }
        }
    }

    assert (false);
    throw new IllegalStateException("Scsi disk controller of type " + diskController + " not found among configured devices.");
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getScsiDiskControllerKeyNoException(String diskController) throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if ((DiskControllerType.getType(diskController) == DiskControllerType.lsilogic || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualLsiLogicController) {
                return ((VirtualLsiLogicController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.lsisas1068 || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualLsiLogicSASController) {
                return ((VirtualLsiLogicSASController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.pvscsi || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof ParaVirtualSCSIController) {
                return ((ParaVirtualSCSIController)device).getKey();
            } else if ((DiskControllerType.getType(diskController) == DiskControllerType.buslogic || DiskControllerType.getType(diskController) == DiskControllerType.scsi)
                    && device instanceof VirtualBusLogicController) {
                return ((VirtualBusLogicController)device).getKey();
            }
        }
    }
    return -1;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public String getDiskCurrentTopBackingFileInChain(String deviceBusName) throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                s_logger.info("Test against disk device, controller key: " + device.getControllerKey() + ", unit number: " + device.getUnitNumber());

                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;

                    String deviceNumbering = getDeviceBusName(devices, device);
                    if (deviceNumbering.equals(deviceBusName))
                        return diskBackingInfo.getFileName();
                }
            }
        }
    }

    return null;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public VirtualMachineDiskInfoBuilder getDiskInfoBuilder() throws Exception {
    VirtualMachineDiskInfoBuilder builder = new VirtualMachineDiskInfoBuilder();

    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;

                    while (diskBackingInfo != null) {
                        String deviceBusName = getDeviceBusName(devices, device);
                        builder.addDisk(deviceBusName, diskBackingInfo.getFileName());
                        diskBackingInfo = diskBackingInfo.getParent();
                    }
                }
            }
        }
    }

    return builder;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public List<Pair<Integer, ManagedObjectReference>> getAllDiskDatastores() throws Exception {
    List<Pair<Integer, ManagedObjectReference>> disks = new ArrayList<Pair<Integer, ManagedObjectReference>>();

    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
                    disks.add(new Pair<Integer, ManagedObjectReference>(new Integer(device.getKey()), diskBackingInfo.getDatastore()));
                }
            }
        }
    }

    return disks;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getIDEControllerKey(int ideUnitNumber) throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
        getDynamicProperty(_mor, "config.hardware.device");

    int requiredIdeController = ideUnitNumber / VmwareHelper.MAX_IDE_CONTROLLER_COUNT;

    int ideControllerCount = 0;
    if(devices != null && devices.size() > 0) {
        for(VirtualDevice device : devices) {
            if(device instanceof VirtualIDEController) {
                if (ideControllerCount == requiredIdeController) {
                    return ((VirtualIDEController)device).getKey();
                }
                ideControllerCount++;
            }
        }
    }

    assert(false);
    throw new Exception("IDE Controller Not Found");
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getFreeUnitNumberOnIDEController(int controllerKey) throws Exception {
    int freeUnitNumber = 0;
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    int deviceCount = 0;
    int ideDeviceUnitNumber = -1;
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk && (controllerKey == device.getControllerKey())) {
                deviceCount++;
                ideDeviceUnitNumber = device.getUnitNumber();
            }
        }
    }
    if (deviceCount == 1) {
        if (ideDeviceUnitNumber == 0) {
            freeUnitNumber = 1;
        } // else freeUnitNumber is already initialized to 0
    } else if (deviceCount == 2) {
        throw new Exception("IDE controller with key [" + controllerKey + "] already has 2 device attached. Cannot attach more than the limit of 2.");
    }
    return freeUnitNumber;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getNextDeviceNumber(int controllerKey) throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

    List<Integer> existingUnitNumbers = new ArrayList<Integer>();
    int deviceNumber = 0;
    int scsiControllerKey = getGenericScsiDeviceControllerKeyNoException();
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device.getControllerKey() != null && device.getControllerKey().intValue() == controllerKey) {
                existingUnitNumbers.add(device.getUnitNumber());
            }
        }
    }
    while (true) {
        // Next device number should be the lowest device number on the key that is not in use and is not reserved.
        if (!existingUnitNumbers.contains(Integer.valueOf(deviceNumber))) {
            if (controllerKey != scsiControllerKey || !VmwareHelper.isReservedScsiDeviceNumber(deviceNumber))
                break;
        }
        ++deviceNumber;
    }
    return deviceNumber;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public Pair<Integer, VirtualDevice> getNicDeviceIndex(String networkNamePrefix) throws Exception {
    List<VirtualDevice> nics = getNicDevices(true);

    int index = 0;
    String attachedNetworkSummary;
    String dvPortGroupName;
    for (VirtualDevice nic : nics) {
        attachedNetworkSummary = ((VirtualEthernetCard)nic).getDeviceInfo().getSummary();
        if (attachedNetworkSummary.startsWith(networkNamePrefix)) {
            return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
        } else if (attachedNetworkSummary.endsWith("DistributedVirtualPortBackingInfo.summary") || attachedNetworkSummary.startsWith("DVSwitch")) {
            dvPortGroupName = getDvPortGroupName((VirtualEthernetCard)nic);
            if (dvPortGroupName != null && dvPortGroupName.startsWith(networkNamePrefix)) {
                s_logger.debug("Found a dvPortGroup already associated with public NIC.");
                return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
            }
        }
        index++;
    }
    return new Pair<Integer, VirtualDevice>(new Integer(-1), null);
}
项目:cloudstack    文件:VirtualMachineMO.java   
public VirtualDevice[] getMatchedDevices(Class<?>[] deviceClasses) throws Exception {
    assert (deviceClasses != null);

    List<VirtualDevice> returnList = new ArrayList<VirtualDevice>();

    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null) {
        for (VirtualDevice device : devices) {
            for (Class<?> clz : deviceClasses) {
                if (clz.isInstance(device)) {
                    returnList.add(device);
                    break;
                }
            }
        }
    }

    return returnList.toArray(new VirtualDevice[0]);
}
项目:cloudstack    文件:VmwareHelper.java   
public static VirtualDevice prepareNicOpaque(VirtualMachineMO vmMo, VirtualEthernetCardType deviceType, String portGroupName,
        String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    assert(vmMo.getRunningHost().hasOpaqueNSXNetwork());

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    VirtualEthernetCardOpaqueNetworkBackingInfo nicBacking = new VirtualEthernetCardOpaqueNetworkBackingInfo();
    nicBacking.setOpaqueNetworkId("br-int");
    nicBacking.setOpaqueNetworkType("nsx.network");

    nic.setBacking(nicBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
项目:cloudstack    文件:VmwareHelper.java   
public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String portGroupName,
        String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(portGroupName);
    nicBacking.setNetwork(morNetwork);
    nic.setBacking(nicBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
项目:cloudstack    文件:VmwareHelper.java   
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String dvPortGroupName,
        String dvSwitchUuid, String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
    final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();

    dvPortConnection.setSwitchUuid(dvSwitchUuid);
    dvPortConnection.setPortgroupKey(morNetwork.getValue());
    dvPortBacking.setPort(dvPortConnection);
    nic.setBacking(dvPortBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
项目:cloudstack    文件:VirtualMachineMOTest.java   
private List<VirtualDevice> getVirtualScSiDeviceList(Class<?> cls) {

        List<VirtualDevice> deviceList = new ArrayList<>();
        try {

            VirtualSCSIController scsiController = (VirtualSCSIController)cls.newInstance();
            scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
            scsiController.setBusNumber(0);
            scsiController.setKey(1);
            deviceList.add(scsiController);
        }
        catch (Exception ex) {

        }
        return deviceList;
    }
项目:cloudstack    文件:VmwareResource.java   
private int allocPublicNicIndex(VirtualMachineMO vmMo) throws Exception {
    String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
    if (nicMasksStr == null || nicMasksStr.isEmpty()) {
        throw new Exception("Could not find NIC allocation info");
    }

    int nicMasks = Integer.parseInt(nicMasksStr);
    VirtualDevice[] nicDevices = vmMo.getNicDevices();
    for (int i = 3; i < nicDevices.length; i++) {
        if ((nicMasks & (1 << i)) == 0) {
            nicMasks |= (1 << i);
            vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMasks));
            return i;
        }
    }

    throw new Exception("Could not allocate a free public NIC");
}
项目:cloudstack    文件:VMwareUtil.java   
public static VirtualMachineDiskInfoBuilder getDiskInfoBuilder(List<VirtualDevice> devices) throws Exception {
    VirtualMachineDiskInfoBuilder builder = new VirtualMachineDiskInfoBuilder();

    if (devices != null) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                VirtualDisk virtualDisk = (VirtualDisk)device;
                VirtualDeviceBackingInfo backingInfo = virtualDisk.getBacking();

                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;

                    String deviceBusName = VMwareUtil.getDeviceBusName(devices, virtualDisk);

                    while (diskBackingInfo != null) {
                        builder.addDisk(deviceBusName, diskBackingInfo.getFileName());

                        diskBackingInfo = diskBackingInfo.getParent();
                    }
                }
            }
        }
    }

    return builder;
}
项目:oscm    文件:NetworkManager.java   
public static List<VirtualEthernetCard> getNetworkAdapter(
        VirtualMachineConfigInfo configInfo) {
    List<VirtualEthernetCard> nics = new ArrayList<VirtualEthernetCard>();
    List<VirtualDevice> devices = configInfo.getHardware().getDevice();
    for (VirtualDevice vd : devices) {
        if (vd instanceof VirtualEthernetCard) {
            nics.add((VirtualEthernetCard) vd);
        }
    }

    return nics;
}
项目: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");
        }
    }
}