Search in sources :

Example 1 with VirtualIDEController

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;
}
Also used : VirtualIDEController(com.vmware.vim25.VirtualIDEController) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 2 with VirtualIDEController

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;
}
Also used : VirtualIDEController(com.vmware.vim25.VirtualIDEController) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with VirtualIDEController

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;
}
Also used : VirtualController(com.vmware.vim25.VirtualController) VirtualIDEController(com.vmware.vim25.VirtualIDEController) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) VirtualBusLogicController(com.vmware.vim25.VirtualBusLogicController) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualLsiLogicSASController(com.vmware.vim25.VirtualLsiLogicSASController) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController)

Example 4 with VirtualIDEController

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");
}
Also used : VirtualIDEController(com.vmware.vim25.VirtualIDEController) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) List(java.util.List) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with VirtualIDEController

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;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDeviceFileBackingInfo(com.vmware.vim25.VirtualDeviceFileBackingInfo) ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) UnmanagedInstanceTO(org.apache.cloudstack.vm.UnmanagedInstanceTO) VirtualIDEController(com.vmware.vim25.VirtualIDEController) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualIDEController (com.vmware.vim25.VirtualIDEController)5 VirtualDevice (com.vmware.vim25.VirtualDevice)4 VirtualSCSIController (com.vmware.vim25.VirtualSCSIController)3 ArrayList (java.util.ArrayList)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ParaVirtualSCSIController (com.vmware.vim25.ParaVirtualSCSIController)2 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)2 VirtualDisk (com.vmware.vim25.VirtualDisk)2 List (java.util.List)2 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 DatastoreInfo (com.vmware.vim25.DatastoreInfo)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 NasDatastoreInfo (com.vmware.vim25.NasDatastoreInfo)1 VirtualBusLogicController (com.vmware.vim25.VirtualBusLogicController)1 VirtualController (com.vmware.vim25.VirtualController)1 VirtualDeviceFileBackingInfo (com.vmware.vim25.VirtualDeviceFileBackingInfo)1 VirtualLsiLogicController (com.vmware.vim25.VirtualLsiLogicController)1 VirtualLsiLogicSASController (com.vmware.vim25.VirtualLsiLogicSASController)1