Search in sources :

Example 21 with StorageVol

use of org.libvirt.StorageVol in project cloudstack by apache.

the class LibvirtStorageAdaptor method createPhysicalDiskByLibVirt.

private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool pool, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    LibvirtStorageVolumeDef.VolumeFormat libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.getFormat(format);
    String volPath = null;
    String volName = null;
    long volAllocation = 0;
    long volCapacity = 0;
    LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null);
    s_logger.debug(volDef.toString());
    try {
        StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        volPath = vol.getPath();
        volName = vol.getName();
        volAllocation = vol.getInfo().allocation;
        volCapacity = vol.getInfo().capacity;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, volName, pool);
    disk.setFormat(format);
    disk.setSize(volAllocation);
    disk.setVirtualSize(volCapacity);
    return disk;
}
Also used : VolumeFormat(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat) StoragePool(org.libvirt.StoragePool) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 22 with StorageVol

use of org.libvirt.StorageVol in project cloudstack by apache.

the class LibvirtStorageAdaptor method copyVolume.

public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException {
    StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0);
    String srcPath = srcVol.getKey();
    String destPath = vol.getKey();
    Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout);
    return vol;
}
Also used : StorageVol(org.libvirt.StorageVol)

Example 23 with StorageVol

use of org.libvirt.StorageVol in project cloudstack by apache.

the class LibvirtStorageAdaptor method getVolume.

public StorageVol getVolume(StoragePool pool, String volName) {
    StorageVol vol = null;
    try {
        vol = pool.storageVolLookupByName(volName);
    } catch (LibvirtException e) {
        s_logger.debug("Could not find volume " + volName + ": " + e.getMessage());
    }
    /**
     * The volume was not found in the storage pool
     * This can happen when a volume has just been created on a different host and
     * since then the libvirt storage pool has not been refreshed.
     */
    if (vol == null) {
        try {
            s_logger.debug("Refreshing storage pool " + pool.getName());
            refreshPool(pool);
        } catch (LibvirtException e) {
            s_logger.debug("Failed to refresh storage pool: " + e.getMessage());
        }
        try {
            vol = pool.storageVolLookupByName(volName);
            s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool");
        } catch (LibvirtException e) {
            throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage());
        }
    }
    return vol;
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 24 with StorageVol

use of org.libvirt.StorageVol in project cloudstack by apache.

the class LibvirtComputingResourceTest method testResizeVolumeCommand.

@Test
public void testResizeVolumeCommand() {
    final String path = "nfs:/127.0.0.1/storage/secondary";
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final Long currentSize = 100l;
    final Long newSize = 200l;
    final boolean shrinkOk = true;
    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);
    final Connect conn = Mockito.mock(Connect.class);
    final StorageVol v = Mockito.mock(StorageVol.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(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
    when(storagePool.getType()).thenReturn(StoragePoolType.RBD);
    when(vol.getFormat()).thenReturn(PhysicalDiskFormat.FILE);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnection()).thenReturn(conn);
        when(conn.storageVolLookupByPath(path)).thenReturn(v);
        when(conn.getLibVirVersion()).thenReturn(10010l);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    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(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnection();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) 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) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StorageVol (org.libvirt.StorageVol)24 LibvirtException (org.libvirt.LibvirtException)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Connect (org.libvirt.Connect)9 StoragePool (org.libvirt.StoragePool)7 LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)6 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)4 Test (org.junit.Test)3 IoCTX (com.ceph.rados.IoCTX)2 Rados (com.ceph.rados.Rados)2 RadosException (com.ceph.rados.exceptions.RadosException)2 Rbd (com.ceph.rbd.Rbd)2 RbdException (com.ceph.rbd.RbdException)2 RbdImage (com.ceph.rbd.RbdImage)2 RbdSnapInfo (com.ceph.rbd.jna.RbdSnapInfo)2 Answer (com.cloud.agent.api.Answer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)2 LibvirtStorageVolumeDef (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef)2