use of com.vmware.vim25.VirtualSCSIController in project vsphere-cloud-plugin by jenkinsci.
the class ReconfigureDisk method addSCSIController.
private VirtualLsiLogicController addSCSIController(VirtualMachine vm) throws Exception {
VirtualMachineConfigInfo vmConfig = vm.getConfig();
VirtualPCIController pci = null;
Set<Integer> scsiBuses = new HashSet<Integer>();
for (VirtualDevice vmDevice : vmConfig.getHardware().getDevice()) {
if (vmDevice instanceof VirtualPCIController) {
pci = (VirtualPCIController) vmDevice;
} else if (vmDevice instanceof VirtualSCSIController) {
VirtualSCSIController ctrl = (VirtualSCSIController) vmDevice;
scsiBuses.add(ctrl.getBusNumber());
}
}
if (pci == null) {
throw new VSphereException("No PCI controller found");
}
VirtualMachineConfigSpec vmSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec deviceSpec = new VirtualDeviceConfigSpec();
deviceSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
VirtualLsiLogicController scsiCtrl = new VirtualLsiLogicController();
scsiCtrl.setControllerKey(pci.getKey());
scsiCtrl.setSharedBus(VirtualSCSISharing.noSharing);
for (int i = 0; ; ++i) {
if (!scsiBuses.contains(Integer.valueOf(i))) {
scsiCtrl.setBusNumber(i);
break;
}
}
deviceSpec.setDevice(scsiCtrl);
vmSpec.setDeviceChange(new VirtualDeviceConfigSpec[] { deviceSpec });
Task task = vm.reconfigVM_Task(vmSpec);
task.waitForTask();
return scsiCtrl;
}
use of com.vmware.vim25.VirtualSCSIController in project cloudstack by apache.
the class VmwareResource method getUnmanageInstanceDisks.
private List<UnmanagedInstanceTO.Disk> getUnmanageInstanceDisks(VirtualMachineMO vmMo) {
List<UnmanagedInstanceTO.Disk> instanceDisks = new ArrayList<>();
VirtualDisk[] disks = null;
try {
disks = vmMo.getAllDiskDevice();
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance disks. " + e.getMessage());
}
if (disks != null) {
for (VirtualDevice diskDevice : disks) {
try {
if (diskDevice instanceof VirtualDisk) {
UnmanagedInstanceTO.Disk instanceDisk = new UnmanagedInstanceTO.Disk();
VirtualDisk disk = (VirtualDisk) diskDevice;
instanceDisk.setDiskId(disk.getDiskObjectId());
instanceDisk.setLabel(disk.getDeviceInfo() != null ? disk.getDeviceInfo().getLabel() : "");
instanceDisk.setFileBaseName(vmMo.getVmdkFileBaseName(disk));
instanceDisk.setImagePath(getAbsoluteVmdkFile(disk));
instanceDisk.setCapacity(disk.getCapacityInBytes());
instanceDisk.setPosition(diskDevice.getUnitNumber());
DatastoreFile file = new DatastoreFile(getAbsoluteVmdkFile(disk));
if (StringUtils.isNoneEmpty(file.getFileBaseName(), file.getDatastoreName())) {
VirtualMachineDiskInfo diskInfo = vmMo.getDiskInfoBuilder().getDiskInfoByBackingFileBaseName(file.getFileBaseName(), file.getDatastoreName());
instanceDisk.setChainInfo(getGson().toJson(diskInfo));
}
for (VirtualDevice device : vmMo.getAllDeviceList()) {
if (diskDevice.getControllerKey() == device.getKey()) {
if (device instanceof VirtualIDEController) {
instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
instanceDisk.setControllerUnit(((VirtualIDEController) device).getBusNumber());
} else if (device instanceof VirtualSCSIController) {
instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
instanceDisk.setControllerUnit(((VirtualSCSIController) device).getBusNumber());
} else {
instanceDisk.setController(DiskControllerType.none.toString());
}
break;
}
}
if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
VirtualDeviceFileBackingInfo diskBacking = (VirtualDeviceFileBackingInfo) disk.getBacking();
ManagedObjectReference morDs = diskBacking.getDatastore();
DatastoreInfo info = (DatastoreInfo) vmMo.getContext().getVimClient().getDynamicProperty(diskBacking.getDatastore(), "info");
if (info instanceof NasDatastoreInfo) {
NasDatastoreInfo dsInfo = (NasDatastoreInfo) info;
instanceDisk.setDatastoreName(dsInfo.getName());
if (dsInfo.getNas() != null) {
instanceDisk.setDatastoreHost(dsInfo.getNas().getRemoteHost());
instanceDisk.setDatastorePath(dsInfo.getNas().getRemotePath());
instanceDisk.setDatastoreType(dsInfo.getNas().getType());
}
} else {
instanceDisk.setDatastoreName(info.getName());
}
}
s_logger.info(vmMo.getName() + " " + disk.getDeviceInfo().getLabel() + " " + disk.getDeviceInfo().getSummary() + " " + disk.getDiskObjectId() + " " + disk.getCapacityInKB() + " " + instanceDisk.getController());
instanceDisks.add(instanceDisk);
}
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance disk info. " + e.getMessage());
}
}
Collections.sort(instanceDisks, new Comparator<UnmanagedInstanceTO.Disk>() {
@Override
public int compare(final UnmanagedInstanceTO.Disk disk1, final UnmanagedInstanceTO.Disk disk2) {
return extractInt(disk1) - extractInt(disk2);
}
int extractInt(UnmanagedInstanceTO.Disk disk) {
String num = disk.getLabel().replaceAll("\\D", "");
// return 0 if no digits found
return num.isEmpty() ? 0 : Integer.parseInt(num);
}
});
}
return instanceDisks;
}
use of com.vmware.vim25.VirtualSCSIController in project cloudstack by apache.
the class HypervisorHostHelper method getControllerSpec.
private static VirtualDeviceConfigSpec getControllerSpec(String diskController, int busNum) {
VirtualDeviceConfigSpec controllerSpec = new VirtualDeviceConfigSpec();
VirtualController controller = null;
if (diskController.equalsIgnoreCase(DiskControllerType.ide.toString())) {
controller = new VirtualIDEController();
} else if (DiskControllerType.pvscsi == DiskControllerType.getType(diskController)) {
controller = new ParaVirtualSCSIController();
} else if (DiskControllerType.lsisas1068 == DiskControllerType.getType(diskController)) {
controller = new VirtualLsiLogicSASController();
} else if (DiskControllerType.buslogic == DiskControllerType.getType(diskController)) {
controller = new VirtualBusLogicController();
} else if (DiskControllerType.lsilogic == DiskControllerType.getType(diskController)) {
controller = new VirtualLsiLogicController();
}
if (!diskController.equalsIgnoreCase(DiskControllerType.ide.toString())) {
((VirtualSCSIController) controller).setSharedBus(VirtualSCSISharing.NO_SHARING);
}
controller.setBusNumber(busNum);
controller.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
controllerSpec.setDevice(controller);
controllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
return controllerSpec;
}
use of com.vmware.vim25.VirtualSCSIController in project cloudstack by apache.
the class VirtualMachineMOTest method getVirtualScSiDeviceList.
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;
}
use of com.vmware.vim25.VirtualSCSIController in project cloudstack by apache.
the class VirtualMachineMO method getScsiControllerInfo.
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);
}
Aggregations