Search in sources :

Example 41 with VirtualDeviceConfigSpec

use of com.vmware.vim25.VirtualDeviceConfigSpec in project cloudstack by apache.

the class VmwareResource method resizeRootDisk.

private void resizeRootDisk(VirtualMachineMO vmMo, DiskTO rootDiskTO, VmwareHypervisorHost hyperHost, VmwareContext context) throws Exception {
    Pair<VirtualDisk, String> vdisk = getVirtualDiskInfo(vmMo, rootDiskTO.getPath() + ".vmdk");
    assert (vdisk != null);
    Long reqSize = ((VolumeObjectTO) rootDiskTO.getData()).getSize() / 1024;
    VirtualDisk disk = vdisk.first();
    if (reqSize > disk.getCapacityInKB()) {
        VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk(vmMo.getDiskInfoBuilder(), rootDiskTO, hyperHost, context);
        assert (diskInfo != null);
        String[] diskChain = diskInfo.getDiskChain();
        if (diskChain != null && diskChain.length > 1) {
            s_logger.error("Unsupported Disk chain length " + diskChain.length);
            throw new Exception("Unsupported Disk chain length " + diskChain.length);
        }
        if (diskInfo.getDiskDeviceBusName() == null || !diskInfo.getDiskDeviceBusName().toLowerCase().startsWith("scsi")) {
            s_logger.error("Unsupported root disk device bus " + diskInfo.getDiskDeviceBusName());
            throw new Exception("Unsupported root disk device bus " + diskInfo.getDiskDeviceBusName());
        }
        disk.setCapacityInKB(reqSize);
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        deviceConfigSpec.setDevice(disk);
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
        vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
        if (!vmMo.configureVm(vmConfigSpec)) {
            throw new Exception("Failed to configure VM for given root disk size. vmName: " + vmMo.getName());
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) 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)

Example 42 with VirtualDeviceConfigSpec

use of com.vmware.vim25.VirtualDeviceConfigSpec in project cloudstack by apache.

the class VirtualMachineMO method ensurePvScsiDeviceController.

public void ensurePvScsiDeviceController(int requiredNumScsiControllers, int availableBusNum) throws Exception {
    VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
    int busNum = availableBusNum;
    while (busNum < requiredNumScsiControllers) {
        ParaVirtualSCSIController scsiController = new ParaVirtualSCSIController();
        scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
        scsiController.setBusNumber(busNum);
        scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
        VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
        scsiControllerSpec.setDevice(scsiController);
        scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
        vmConfig.getDeviceChange().add(scsiControllerSpec);
        busNum++;
    }
    if (configureVm(vmConfig)) {
        throw new Exception("Unable to add Scsi controllers to the VM " + getName());
    } else {
        s_logger.info("Successfully added " + requiredNumScsiControllers + " SCSI controllers.");
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ParaVirtualSCSIController(com.vmware.vim25.ParaVirtualSCSIController) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec)

Example 43 with VirtualDeviceConfigSpec

use of com.vmware.vim25.VirtualDeviceConfigSpec in project cloudstack by apache.

the class VirtualMachineMO method attachDisk.

public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain));
    synchronized (_mor.getValue().intern()) {
        VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey, vmdkDatastorePathChain, -1, 1);
        VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        deviceConfigSpec.setDevice(newDisk);
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
        reConfigSpec.getDeviceChange().add(deviceConfigSpec);
        ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (!result) {
            if (s_logger.isTraceEnabled())
                s_logger.trace("vCenter API trace - attachDisk() done(failed)");
            throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
        _context.waitForTaskProgressDone(morTask);
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) Gson(com.google.gson.Gson) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 44 with VirtualDeviceConfigSpec

use of com.vmware.vim25.VirtualDeviceConfigSpec in project cloudstack by apache.

the class VirtualMachineMO method ensureScsiDeviceControllers.

public void ensureScsiDeviceControllers(int count, int availableBusNum) throws Exception {
    int scsiControllerKey = getScsiDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
        int busNum = availableBusNum;
        while (busNum < count) {
            VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
            scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
            scsiController.setBusNumber(busNum);
            scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
            VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
            scsiControllerSpec.setDevice(scsiController);
            scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
            vmConfig.getDeviceChange().add(scsiControllerSpec);
            busNum++;
        }
        if (configureVm(vmConfig)) {
            throw new Exception("Unable to add Scsi controllers to the VM " + getName());
        } else {
            s_logger.info("Successfully added " + count + " SCSI controllers.");
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController)

Aggregations

VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)44 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)41 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)23 VirtualDevice (com.vmware.vim25.VirtualDevice)19 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)18 VirtualDisk (com.vmware.vim25.VirtualDisk)10 CloudException (com.cloud.exception.CloudException)6 InternalErrorException (com.cloud.exception.InternalErrorException)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 VirtualLsiLogicController (com.vmware.vim25.VirtualLsiLogicController)6 IOException (java.io.IOException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 ConnectException (java.net.ConnectException)6 RemoteException (java.rmi.RemoteException)6 ConfigurationException (javax.naming.ConfigurationException)6 Gson (com.google.gson.Gson)5 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)5 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)4 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)4 Pair (com.cloud.utils.Pair)4