use of com.vmware.vim25.VirtualIDEController in project cloudstack by apache.
the class HypervisorHostHelper method getOsDiskFromOvfConf.
public static int getOsDiskFromOvfConf(VirtualMachineConfigSpec config, String deviceLocation) {
List<VirtualDeviceConfigSpec> deviceConfigList = config.getDeviceChange();
int controllerKey = 0;
int deviceSeqNumber = 0;
int controllerNumber = 0;
int deviceNodeNumber = 0;
int controllerCount = 0;
String[] virtualNodeInfo = deviceLocation.split(":");
if (deviceLocation.startsWith("scsi")) {
// get substring excluding prefix scsi
controllerNumber = Integer.parseInt(virtualNodeInfo[0].substring(4));
deviceNodeNumber = Integer.parseInt(virtualNodeInfo[1]);
for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
VirtualDevice device = deviceConfig.getDevice();
if (device instanceof VirtualSCSIController) {
if (controllerNumber == controllerCount) {
// ((VirtualSCSIController)device).getBusNumber()) {
controllerKey = device.getKey();
break;
}
controllerCount++;
}
}
} else {
// get substring excluding prefix ide
controllerNumber = Integer.parseInt(virtualNodeInfo[0].substring(3));
deviceNodeNumber = Integer.parseInt(virtualNodeInfo[1]);
controllerCount = 0;
for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
VirtualDevice device = deviceConfig.getDevice();
if (device instanceof VirtualIDEController) {
if (controllerNumber == controllerCount) {
// ((VirtualIDEController)device).getBusNumber()) {
// Only 2 IDE controllers supported and they will have bus numbers 0 and 1
controllerKey = device.getKey();
break;
}
controllerCount++;
}
}
}
// Get devices on this controller at specific device node.
for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
VirtualDevice device = deviceConfig.getDevice();
if (device instanceof VirtualDisk) {
if (controllerKey == device.getControllerKey() && deviceNodeNumber == device.getUnitNumber()) {
break;
}
deviceSeqNumber++;
}
}
return deviceSeqNumber;
}
use of com.vmware.vim25.VirtualIDEController in project cloudstack by apache.
the class VirtualMachineMO method getNumberOfIDEDevices.
public int getNumberOfIDEDevices() throws Exception {
int ideDeviceCount = 0;
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 VirtualIDEController) {
ideDeviceCount += ((VirtualIDEController) device).getDevice().size();
}
}
}
return ideDeviceCount;
}
use of com.vmware.vim25.VirtualIDEController 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.VirtualIDEController in project cloudstack by apache.
the class VirtualMachineMO method getIDEControllerKey.
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");
}
use of com.vmware.vim25.VirtualIDEController 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;
}
Aggregations