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

项目: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   
private static int getMaxNodesPerControllerOfType(VirtualController controller) 
{
  int count = 0;

  if ( VirtualSCSIController.class.isInstance(controller) )
  {
    // The actual device nodes of SCSI controller are 16
    // but one of them is reserved for the controller itself
    // so this means that the maximum free nodes are 15.
    count = 16;
  }
  else if (VirtualIDEController.class.isInstance(controller)) 
  {
    count = 2;
  }
  else 
  {
    throw new RuntimeException("Unknown controller type - " + controller.getDeviceInfo().getLabel());
  }
  return count;
}
项目: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;
    }
项目:photon-model    文件:ClientUtils.java   
/**
 * Find available free unit number for scsi controller.
 */
public static Integer[] findFreeScsiUnit(VirtualSCSIController controller, List<VirtualDevice>
        devices) {
    // Max scsi controller number is 16, but supported runtime value could be fetched from
    // VirtualHardwareOption
    int[] slots = new int[16];
    // Unit 7 is reserved
    slots[7] = 1;

    Map<Integer, VirtualDevice> deviceMap = new HashMap<>();
    devices.stream().forEach(device -> deviceMap.put(device.getKey(), device));
    controller.getDevice().stream().forEach(deviceKey -> {
        if (deviceMap.get(deviceKey).getUnitNumber() != null) {
            slots[deviceMap.get(deviceKey).getUnitNumber()] = 1;
        }
    });

    List<Integer> freeUnitNumbers = new ArrayList<>();
    for (int i = 0; i < slots.length; i++) {
        if (slots[i] != 1) {
            freeUnitNumbers.add(i);
        }
    }
    // Default to start from 0
    if (freeUnitNumbers.isEmpty()) {
        freeUnitNumbers.add(0);
    }
    Integer[] unitNumbersArray = new Integer[freeUnitNumbers.size()];
    return freeUnitNumbers.toArray(unitNumbersArray);
}
项目:photon-model    文件:ClientUtils.java   
public static VirtualSCSIController getFirstScsiController(ArrayOfVirtualDevice devices) {
    for (VirtualDevice dev : devices.getVirtualDevice()) {
        if (dev instanceof VirtualSCSIController) {
            return (VirtualSCSIController) dev;
        }
    }

    throw new IllegalStateException("No SCSI controller found");
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
protected VirtualDisk reuseDisk(VirtualMachine machine, Integer scsiId, String fileName) {
    // SCSIコントローラを取得
    VirtualSCSIController scsiController = getSCSIController(machine);

    // 仮想マシン自体のディスクを取得
    VirtualDisk machineDisk = getVirtualDisk(machine, 0);
    VirtualDiskFlatVer2BackingInfo machieBackingInfo = VirtualDiskFlatVer2BackingInfo.class.cast(machineDisk
            .getBacking());

    // VirtualDisk
    VirtualDisk disk = new VirtualDisk();
    disk.setUnitNumber(scsiId);
    disk.setControllerKey(scsiController.getKey());

    // VirtualDiskFlatVer2BackingInfo
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setFileName(fileName);
    backingInfo.setDiskMode("persistent");
    backingInfo.setSplit(false);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setThinProvisioned(machieBackingInfo.getThinProvisioned());
    backingInfo.setWriteThrough(false);
    disk.setBacking(backingInfo);

    // VirtualDeviceConnectInfo
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(false);
    connectInfo.setStartConnected(true);
    connectInfo.setConnected(true);
    disk.setConnectable(connectInfo);

    return disk;
}
项目: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);
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getScsiDeviceControllerKey() 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 VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    assert (false);
    throw new Exception("SCSI Controller Not Found");
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getGenericScsiDeviceControllerKeyNoException() 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 VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public int getScsiDeviceControllerKeyNoException() 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(device instanceof VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
项目:cloudstack    文件:VirtualMachineMO.java   
private String getDeviceBusName(List<VirtualDevice> allDevices, VirtualDevice theDevice) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device.getKey() == theDevice.getControllerKey().intValue()) {
            if (device instanceof VirtualIDEController) {
                return String.format("ide%d:%d", ((VirtualIDEController)device).getBusNumber(), theDevice.getUnitNumber());
            } else if (device instanceof VirtualSCSIController) {
                return String.format("scsi%d:%d", ((VirtualSCSIController)device).getBusNumber(), theDevice.getUnitNumber());
            } else {
                throw new Exception("Device controller is not supported yet");
            }
        }
    }
    throw new Exception("Unable to find device controller");
}
项目:cloudstack    文件:VirtualMachineMO.java   
public Ternary<Integer, Integer, DiskControllerType> getScsiControllerInfo() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    int scsiControllerCount = 0;
    int busNum = -1;
    DiskControllerType controllerType = DiskControllerType.lsilogic;
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualSCSIController) {
                scsiControllerCount++;
                int deviceBus = ((VirtualSCSIController)device).getBusNumber();
                if (busNum < deviceBus) {
                    busNum = deviceBus;
                }
                if (device instanceof VirtualLsiLogicController) {
                    controllerType = DiskControllerType.lsilogic;
                } else if (device instanceof VirtualLsiLogicSASController) {
                    controllerType = DiskControllerType.lsisas1068;
                } else if (device instanceof VirtualBusLogicController) {
                    controllerType = DiskControllerType.buslogic;
                } else if (device instanceof ParaVirtualSCSIController) {
                    controllerType = DiskControllerType.pvscsi;
                }
            }
        }
    }

    return new Ternary<Integer, Integer, DiskControllerType>(scsiControllerCount, busNum, controllerType);
}
项目:cloudstack    文件:VMwareUtil.java   
public static String getDeviceBusName(List<VirtualDevice> allDevices, VirtualDisk disk) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device.getKey() == disk.getControllerKey()) {
            if (device instanceof VirtualIDEController) {
                return String.format("ide%d:%d", ((VirtualIDEController)device).getBusNumber(), disk.getUnitNumber());
            } else if (device instanceof VirtualSCSIController) {
                return String.format("scsi%d:%d", ((VirtualSCSIController)device).getBusNumber(), disk.getUnitNumber());
            } else {
                throw new Exception("The device controller is not supported.");
            }
        }
    }

    throw new Exception("The device controller could not be located.");
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
protected VirtualDisk newDisk(VirtualMachine machine, Integer scsiId, Integer size) {
    // SCSIコントローラを取得
    VirtualSCSIController scsiController = getSCSIController(machine);

    // 仮想マシン自体のディスクを取得
    VirtualDisk machineDisk = getVirtualDisk(machine, 0);
    VirtualDiskFlatVer2BackingInfo machieBackingInfo = VirtualDiskFlatVer2BackingInfo.class.cast(machineDisk
            .getBacking());

    // VirtualDisk
    VirtualDisk disk = new VirtualDisk();
    disk.setUnitNumber(scsiId);
    disk.setCapacityInKB(size * 1024L * 1024L);
    disk.setControllerKey(scsiController.getKey());

    // VirtualDiskFlatVer2BackingInfo
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setDatastore(null);
    backingInfo.setFileName("");
    backingInfo.setDiskMode("persistent");
    backingInfo.setSplit(false);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setThinProvisioned(machieBackingInfo.getThinProvisioned());
    backingInfo.setWriteThrough(false);
    disk.setBacking(backingInfo);

    // VirtualDeviceConnectInfo
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(false);
    connectInfo.setStartConnected(true);
    connectInfo.setConnected(true);
    disk.setConnectable(connectInfo);

    return disk;
}