Search in sources :

Example 6 with VirtualSCSIController

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;
}
Also used : Task(com.vmware.vim25.mo.Task) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) HashSet(java.util.HashSet)

Example 7 with VirtualSCSIController

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;
}
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)

Example 8 with VirtualSCSIController

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;
}
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 9 with VirtualSCSIController

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

Example 10 with VirtualSCSIController

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);
}
Also used : VirtualBusLogicController(com.vmware.vim25.VirtualBusLogicController) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) Ternary(com.cloud.utils.Ternary) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualLsiLogicSASController(com.vmware.vim25.VirtualLsiLogicSASController) ArrayList(java.util.ArrayList) List(java.util.List) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController)

Aggregations

VirtualSCSIController (com.vmware.vim25.VirtualSCSIController)9 VirtualDevice (com.vmware.vim25.VirtualDevice)7 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)6 VirtualDisk (com.vmware.vim25.VirtualDisk)5 ArrayList (java.util.ArrayList)5 VirtualLsiLogicController (com.vmware.vim25.VirtualLsiLogicController)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DISK_CONTROLLER_NUMBER (com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER)3 PROVIDER_DISK_UNIQUE_ID (com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 List (java.util.List)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 RESOURCE_GROUP_NAME (com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME)2 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)2 VM_PATH_FORMAT (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT)2 ClientUtils.createCdrom (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom)2 ClientUtils.createFloppy (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy)2 ClientUtils.createHdd (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd)2 ClientUtils.detachDisk (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk)2 ClientUtils.fillInControllerUnitNumber (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber)2