Search in sources :

Example 11 with KVMStoragePool

use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testDestroyCommandError.

@SuppressWarnings("unchecked")
@Test
public void testDestroyCommandError() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final Volume volume = Mockito.mock(Volume.class);
    final String vmName = "Test";
    final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
    final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
    final VolumeTO vol = command.getVolume();
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
    when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) VolumeTO(com.cloud.agent.api.to.VolumeTO) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) Volume(com.cloud.storage.Volume) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with KVMStoragePool

use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testResizeVolumeCommandLinstorNotifyOnly.

@Test
public void testResizeVolumeCommandLinstorNotifyOnly() {
    final String path = "/dev/drbd1000";
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final Long currentSize = 100l;
    final Long newSize = 200l;
    final boolean shrinkOk = false;
    final String vmInstance = "Test";
    final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance, null);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
    when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
    when(vol.getPath()).thenReturn(path);
    when(storagePool.getType()).thenReturn(StoragePoolType.Linstor);
    when(vol.getFormat()).thenReturn(PhysicalDiskFormat.RAW);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(libvirtComputingResource, times(0)).getResizeScriptType(storagePool, vol);
    verify(libvirtComputingResource, times(0)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(0)).getConnection();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with KVMStoragePool

use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCreateCommandCLVM.

@Test
public void testCreateCommandCLVM() {
    final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final String templateUrl = "http://template";
    final boolean executeInSequence = false;
    final CreateCommand command = new CreateCommand(diskCharacteristics, templateUrl, pool, executeInSequence);
    final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk baseVol = Mockito.mock(KVMPhysicalDisk.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(primary.getPhysicalDisk(command.getTemplateUrl())).thenReturn(baseVol);
    when(poolManager.createDiskFromTemplate(baseVol, diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), primary, baseVol.getSize(), 0)).thenReturn(vol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CreateCommand(com.cloud.agent.api.storage.CreateCommand) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) DiskProfile(com.cloud.vm.DiskProfile) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with KVMStoragePool

use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.

the class LibvirtComputingResource method createVbd.

public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {
    final Map<String, String> details = vmSpec.getDetails();
    final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
    boolean isSecureBoot = false;
    boolean isWindowsTemplate = false;
    Collections.sort(disks, new Comparator<DiskTO>() {

        @Override
        public int compare(final DiskTO arg0, final DiskTO arg1) {
            return arg0.getDiskSeq() > arg1.getDiskSeq() ? 1 : -1;
        }
    });
    boolean isUefiEnabled = MapUtils.isNotEmpty(details) && details.containsKey(GuestDef.BootType.UEFI.toString());
    if (isUefiEnabled) {
        isSecureBoot = isSecureMode(details.get(GuestDef.BootType.UEFI.toString()));
    }
    if (vmSpec.getOs().toLowerCase().contains("window")) {
        isWindowsTemplate = true;
    }
    for (final DiskTO volume : disks) {
        KVMPhysicalDisk physicalDisk = null;
        KVMStoragePool pool = null;
        final DataTO data = volume.getData();
        if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
            DataStoreTO dataStore = data.getDataStore();
            String dataStoreUrl = null;
            if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && vmSpec.isConfigDriveOnHostCache() && data instanceof TemplateObjectTO) {
                String configDrivePath = getConfigPath() + "/" + data.getPath();
                physicalDisk = new KVMPhysicalDisk(configDrivePath, ((TemplateObjectTO) data).getUuid(), null);
                physicalDisk.setFormat(PhysicalDiskFormat.FILE);
            } else if (dataStore instanceof NfsTO) {
                NfsTO nfsStore = (NfsTO) data.getDataStore();
                dataStoreUrl = nfsStore.getUrl();
                physicalDisk = getPhysicalDiskFromNfsStore(dataStoreUrl, data);
            } else if (dataStore instanceof PrimaryDataStoreTO) {
                // In order to support directly downloaded ISOs
                PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStore;
                if (primaryDataStoreTO.getPoolType().equals(StoragePoolType.NetworkFilesystem)) {
                    String psHost = primaryDataStoreTO.getHost();
                    String psPath = primaryDataStoreTO.getPath();
                    dataStoreUrl = "nfs://" + psHost + File.separator + psPath;
                    physicalDisk = getPhysicalDiskFromNfsStore(dataStoreUrl, data);
                } else if (primaryDataStoreTO.getPoolType().equals(StoragePoolType.SharedMountPoint) || primaryDataStoreTO.getPoolType().equals(StoragePoolType.Filesystem)) {
                    physicalDisk = getPhysicalDiskPrimaryStore(primaryDataStoreTO, data);
                }
            }
        } else if (volume.getType() != Volume.Type.ISO) {
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) data.getDataStore();
            physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
            pool = physicalDisk.getPool();
        }
        String volPath = null;
        if (physicalDisk != null) {
            volPath = physicalDisk.getPath();
        }
        if (volume.getType() != Volume.Type.ISO && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2 && (pool.getType() == StoragePoolType.NetworkFilesystem || pool.getType() == StoragePoolType.SharedMountPoint || pool.getType() == StoragePoolType.Filesystem || pool.getType() == StoragePoolType.Gluster)) {
            setBackingFileFormat(physicalDisk.getPath());
        }
        // check for disk activity, if detected we should exit because vm is running elsewhere
        if (_diskActivityCheckEnabled && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
            s_logger.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere");
            try {
                HypervisorUtils.checkVolumeFileForActivity(volPath, _diskActivityCheckTimeoutSeconds, _diskActivityInactiveThresholdMilliseconds, _diskActivityCheckFileSizeMin);
            } catch (final IOException ex) {
                throw new CloudRuntimeException("Unable to check physical disk file for activity", ex);
            }
            s_logger.debug("Disk activity check cleared");
        }
        // if params contains a rootDiskController key, use its value (this is what other HVs are doing)
        DiskDef.DiskBus diskBusType = getDiskModelFromVMDetail(vmSpec);
        if (diskBusType == null) {
            diskBusType = getGuestDiskModel(vmSpec.getPlatformEmulator(), isUefiEnabled);
        }
        DiskDef.DiskBus diskBusTypeData = getDataDiskModelFromVMDetail(vmSpec);
        if (diskBusTypeData == null) {
            diskBusTypeData = (diskBusType == DiskDef.DiskBus.SCSI) ? diskBusType : DiskDef.DiskBus.VIRTIO;
        }
        final DiskDef disk = new DiskDef();
        int devId = volume.getDiskSeq().intValue();
        if (volume.getType() == Volume.Type.ISO) {
            disk.defISODisk(volPath, devId, isUefiEnabled);
            if (_guestCpuArch != null && _guestCpuArch.equals("aarch64")) {
                disk.setBusType(DiskDef.DiskBus.SCSI);
            }
        } else {
            if (diskBusType == DiskDef.DiskBus.SCSI) {
                disk.setQemuDriver(true);
                disk.setDiscard(DiscardType.UNMAP);
            }
            setDiskIoDriver(disk);
            if (pool.getType() == StoragePoolType.RBD) {
                /*
                            For RBD pools we use the secret mechanism in libvirt.
                            We store the secret under the UUID of the pool, that's why
                            we pass the pool's UUID as the authSecret
                     */
                disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(), pool.getUuid(), devId, diskBusType, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
            } else if (pool.getType() == StoragePoolType.PowerFlex) {
                disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData);
            } else if (pool.getType() == StoragePoolType.Gluster) {
                final String mountpoint = pool.getLocalPath();
                final String path = physicalDisk.getPath();
                final String glusterVolume = pool.getSourceDir().replace("/", "");
                disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null, null, devId, diskBusType, DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
            } else if (pool.getType() == StoragePoolType.CLVM || physicalDisk.getFormat() == PhysicalDiskFormat.RAW) {
                if (volume.getType() == Volume.Type.DATADISK && !(isWindowsTemplate && isUefiEnabled)) {
                    disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData);
                } else {
                    disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType);
                }
            } else {
                if (volume.getType() == Volume.Type.DATADISK && !(isWindowsTemplate && isUefiEnabled)) {
                    disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData, DiskDef.DiskFmtType.QCOW2);
                } else {
                    if (isSecureBoot) {
                        disk.defFileBasedDisk(physicalDisk.getPath(), devId, DiskDef.DiskFmtType.QCOW2, isWindowsTemplate);
                    } else {
                        disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.DiskFmtType.QCOW2);
                    }
                }
            }
        }
        if (data instanceof VolumeObjectTO) {
            final VolumeObjectTO volumeObjectTO = (VolumeObjectTO) data;
            disk.setSerial(diskUuidToSerial(volumeObjectTO.getUuid()));
            setBurstProperties(volumeObjectTO, disk);
            if (volumeObjectTO.getCacheMode() != null) {
                disk.setCacheMode(DiskDef.DiskCacheMode.valueOf(volumeObjectTO.getCacheMode().toString().toUpperCase()));
            }
        }
        if (vm.getDevices() == null) {
            s_logger.error("There is no devices for" + vm);
            throw new RuntimeException("There is no devices for" + vm);
        }
        vm.getDevices().addDevice(disk);
    }
    if (vmSpec.getType() != VirtualMachine.Type.User) {
        if (_sysvmISOPath != null) {
            final DiskDef iso = new DiskDef();
            iso.defISODisk(_sysvmISOPath);
            if (_guestCpuArch != null && _guestCpuArch.equals("aarch64")) {
                iso.setBusType(DiskDef.DiskBus.SCSI);
            }
            vm.getDevices().addDevice(iso);
        }
    }
    // For LXC, find and add the root filesystem, rbd data disks
    if (HypervisorType.LXC.toString().toLowerCase().equals(vm.getHvsType())) {
        for (final DiskTO volume : disks) {
            final DataTO data = volume.getData();
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) data.getDataStore();
            if (volume.getType() == Volume.Type.ROOT) {
                final KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
                final FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/");
                vm.getDevices().addDevice(rootFs);
            } else if (volume.getType() == Volume.Type.DATADISK) {
                final KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
                final KVMStoragePool pool = physicalDisk.getPool();
                if (StoragePoolType.RBD.equals(pool.getType())) {
                    final int devId = volume.getDiskSeq().intValue();
                    final String device = mapRbdDevice(physicalDisk);
                    if (device != null) {
                        s_logger.debug("RBD device on host is: " + device);
                        final DiskDef diskdef = new DiskDef();
                        diskdef.defBlockBasedDisk(device, devId, DiskDef.DiskBus.VIRTIO);
                        diskdef.setQemuDriver(false);
                        vm.getDevices().addDevice(diskdef);
                    } else {
                        throw new InternalErrorException("Error while mapping RBD device on host");
                    }
                }
            }
        }
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) FilesystemDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FilesystemDef) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) NfsTO(com.cloud.agent.api.to.NfsTO) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) DataTO(com.cloud.agent.api.to.DataTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 15 with KVMStoragePool

use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.

the class LibvirtComputingResource method attachOrDetachDisk.

public synchronized String attachOrDetachDisk(final Connect conn, final boolean attach, final String vmName, final KVMPhysicalDisk attachingDisk, final int devId, final Long bytesReadRate, final Long bytesReadRateMax, final Long bytesReadRateMaxLength, final Long bytesWriteRate, final Long bytesWriteRateMax, final Long bytesWriteRateMaxLength, final Long iopsReadRate, final Long iopsReadRateMax, final Long iopsReadRateMaxLength, final Long iopsWriteRate, final Long iopsWriteRateMax, final Long iopsWriteRateMaxLength, final String cacheMode) throws LibvirtException, InternalErrorException {
    List<DiskDef> disks = null;
    Domain dm = null;
    DiskDef diskdef = null;
    final KVMStoragePool attachingPool = attachingDisk.getPool();
    try {
        dm = conn.domainLookupByName(vmName);
        final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
        final String domXml = dm.getXMLDesc(0);
        parser.parseDomainXML(domXml);
        disks = parser.getDisks();
        if (!attach) {
            for (final DiskDef disk : disks) {
                final String file = disk.getDiskPath();
                if (file != null && file.equalsIgnoreCase(attachingDisk.getPath())) {
                    diskdef = disk;
                    break;
                }
            }
            if (diskdef == null) {
                throw new InternalErrorException("disk: " + attachingDisk.getPath() + " is not attached before");
            }
        } else {
            DiskDef.DiskBus busT = DiskDef.DiskBus.VIRTIO;
            for (final DiskDef disk : disks) {
                if (disk.getDeviceType() == DeviceType.DISK) {
                    if (disk.getBusType() == DiskDef.DiskBus.SCSI) {
                        busT = DiskDef.DiskBus.SCSI;
                    }
                    break;
                }
            }
            diskdef = new DiskDef();
            if (busT == DiskDef.DiskBus.SCSI) {
                diskdef.setQemuDriver(true);
                diskdef.setDiscard(DiscardType.UNMAP);
            }
            if (attachingPool.getType() == StoragePoolType.RBD) {
                diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), attachingPool.getUuid(), devId, busT, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
            } else if (attachingPool.getType() == StoragePoolType.PowerFlex) {
                diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, busT);
            } else if (attachingPool.getType() == StoragePoolType.Gluster) {
                diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), null, null, devId, busT, DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
            } else if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
                diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, busT, DiskDef.DiskFmtType.QCOW2);
            } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {
                diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, busT);
            }
            if (bytesReadRate != null && bytesReadRate > 0) {
                diskdef.setBytesReadRate(bytesReadRate);
            }
            if (bytesReadRateMax != null && bytesReadRateMax > 0) {
                diskdef.setBytesReadRateMax(bytesReadRateMax);
            }
            if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
                diskdef.setBytesReadRateMaxLength(bytesReadRateMaxLength);
            }
            if (bytesWriteRate != null && bytesWriteRate > 0) {
                diskdef.setBytesWriteRate(bytesWriteRate);
            }
            if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
                diskdef.setBytesWriteRateMax(bytesWriteRateMax);
            }
            if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
                diskdef.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
            }
            if (iopsReadRate != null && iopsReadRate > 0) {
                diskdef.setIopsReadRate(iopsReadRate);
            }
            if (iopsReadRateMax != null && iopsReadRateMax > 0) {
                diskdef.setIopsReadRateMax(iopsReadRateMax);
            }
            if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
                diskdef.setIopsReadRateMaxLength(iopsReadRateMaxLength);
            }
            if (iopsWriteRate != null && iopsWriteRate > 0) {
                diskdef.setIopsWriteRate(iopsWriteRate);
            }
            if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
                diskdef.setIopsWriteRateMax(iopsWriteRateMax);
            }
            if (cacheMode != null) {
                diskdef.setCacheMode(DiskDef.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
            }
        }
        final String xml = diskdef.toString();
        return attachOrDetachDevice(conn, attach, vmName, xml);
    } finally {
        if (dm != null) {
            dm.free();
        }
    }
}
Also used : DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) InternalErrorException(com.cloud.exception.InternalErrorException) Domain(org.libvirt.Domain)

Aggregations

Answer (com.cloud.agent.api.Answer)66 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)58 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)57 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)57 Test (org.junit.Test)57 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)47 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)46 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)41 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)40 StoragePool (com.cloud.storage.StoragePool)40 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 KvmPhysicalDisk (com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk)34 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)29 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AttachAnswer (com.cloud.storage.command.AttachAnswer)28 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)25 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)20 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)20