Search in sources :

Example 41 with StoragePool

use of org.libvirt.StoragePool in project cosmic by MissionCriticalCloud.

the class ManagedNfsStorageAdaptor method getPhysicalDisk.

/*
     * creates a disk based on the created nfs storage pool using libvirt
     */
@Override
public KvmPhysicalDisk getPhysicalDisk(final String volumeUuid, final KvmStoragePool pool) {
    // now create the volume upon the given storage pool in kvm
    final Connect conn;
    StoragePool virtPool = null;
    try {
        conn = LibvirtConnection.getConnection();
        virtPool = conn.storagePoolLookupByName("/" + volumeUuid);
    } catch (final LibvirtException e1) {
        throw new CloudRuntimeException(e1.toString());
    }
    LibvirtStorageVolumeDef.VolumeFormat libvirtformat = null;
    long volCapacity = 0;
    // check whether the volume is present on the given pool
    StorageVol vol = getVolume(virtPool, volumeUuid);
    try {
        if (vol == null) {
            libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.QCOW2;
            final StoragePoolInfo poolinfo = virtPool.getInfo();
            volCapacity = poolinfo.available;
            final LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(volumeUuid, volCapacity, libvirtformat, null, null);
            logger.debug(volDef.toString());
            vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        }
        final KvmPhysicalDisk disk = new KvmPhysicalDisk(vol.getPath(), volumeUuid, pool);
        disk.setFormat(PhysicalDiskFormat.QCOW2);
        disk.setSize(vol.getInfo().allocation);
        disk.setVirtualSize(vol.getInfo().capacity);
        return disk;
    } catch (final LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) StorageVol(org.libvirt.StorageVol) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) StoragePoolInfo(org.libvirt.StoragePoolInfo)

Example 42 with StoragePool

use of org.libvirt.StoragePool in project cosmic by MissionCriticalCloud.

the class LibvirtStoragePoolTest method testExternalSnapshot.

public void testExternalSnapshot() {
    final String uuid = "60b46738-c5d0-40a9-a79e-9a4fe6295db7";
    final String name = "myfirstpool";
    final StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
    final StoragePool storage = Mockito.mock(StoragePool.class);
    final LibvirtStoragePool nfsPool = new LibvirtStoragePool(uuid, name, StoragePoolType.NetworkFilesystem, adapter, storage);
    assertFalse(nfsPool.isExternalSnapshot());
    final LibvirtStoragePool rbdPool = new LibvirtStoragePool(uuid, name, StoragePoolType.RBD, adapter, storage);
    assertTrue(rbdPool.isExternalSnapshot());
    final LibvirtStoragePool clvmPool = new LibvirtStoragePool(uuid, name, StoragePoolType.CLVM, adapter, storage);
    assertTrue(clvmPool.isExternalSnapshot());
}
Also used : StoragePool(org.libvirt.StoragePool)

Example 43 with StoragePool

use of org.libvirt.StoragePool in project cosmic by MissionCriticalCloud.

the class LibvirtStoragePoolTest method testDefaultFormats.

public void testDefaultFormats() {
    final String uuid = "f40cbf53-1f37-4c62-8912-801edf398f47";
    final String name = "myfirstpool";
    final StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
    final StoragePool storage = Mockito.mock(StoragePool.class);
    final LibvirtStoragePool nfsPool = new LibvirtStoragePool(uuid, name, StoragePoolType.NetworkFilesystem, adapter, storage);
    assertEquals(nfsPool.getDefaultFormat(), PhysicalDiskFormat.QCOW2);
    assertEquals(nfsPool.getStoragePoolType(), StoragePoolType.NetworkFilesystem);
    final LibvirtStoragePool rbdPool = new LibvirtStoragePool(uuid, name, StoragePoolType.RBD, adapter, storage);
    assertEquals(rbdPool.getDefaultFormat(), PhysicalDiskFormat.RAW);
    assertEquals(rbdPool.getStoragePoolType(), StoragePoolType.RBD);
    final LibvirtStoragePool clvmPool = new LibvirtStoragePool(uuid, name, StoragePoolType.CLVM, adapter, storage);
    assertEquals(clvmPool.getDefaultFormat(), PhysicalDiskFormat.RAW);
    assertEquals(clvmPool.getStoragePoolType(), StoragePoolType.CLVM);
}
Also used : StoragePool(org.libvirt.StoragePool)

Example 44 with StoragePool

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

the class LibvirtStoragePoolTest method testExternalSnapshot.

public void testExternalSnapshot() {
    String uuid = "60b46738-c5d0-40a9-a79e-9a4fe6295db7";
    String name = "myfirstpool";
    StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
    StoragePool storage = Mockito.mock(StoragePool.class);
    LibvirtStoragePool nfsPool = new LibvirtStoragePool(uuid, name, StoragePoolType.NetworkFilesystem, adapter, storage);
    assertFalse(nfsPool.isExternalSnapshot());
    LibvirtStoragePool rbdPool = new LibvirtStoragePool(uuid, name, StoragePoolType.RBD, adapter, storage);
    assertTrue(rbdPool.isExternalSnapshot());
    LibvirtStoragePool clvmPool = new LibvirtStoragePool(uuid, name, StoragePoolType.CLVM, adapter, storage);
    assertTrue(clvmPool.isExternalSnapshot());
}
Also used : StoragePool(org.libvirt.StoragePool)

Example 45 with StoragePool

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

the class LibvirtStoragePoolTest method testAttributes.

public void testAttributes() {
    String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da";
    String name = "myfirstpool";
    StoragePoolType type = StoragePoolType.NetworkFilesystem;
    StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
    StoragePool storage = Mockito.mock(StoragePool.class);
    LibvirtStoragePool pool = new LibvirtStoragePool(uuid, name, type, adapter, storage);
    assertEquals(pool.getCapacity(), 0);
    assertEquals(pool.getUsed(), 0);
    assertEquals(pool.getName(), name);
    assertEquals(pool.getUuid(), uuid);
    assertEquals(pool.getAvailable(), 0);
    assertEquals(pool.getStoragePoolType(), type);
    pool.setCapacity(2048);
    pool.setUsed(1024);
    pool.setAvailable(1023);
    assertEquals(pool.getCapacity(), 2048);
    assertEquals(pool.getUsed(), 1024);
    assertEquals(pool.getAvailable(), 1023);
}
Also used : StoragePool(org.libvirt.StoragePool) StoragePoolType(com.cloud.storage.Storage.StoragePoolType)

Aggregations

StoragePool (org.libvirt.StoragePool)51 LibvirtException (org.libvirt.LibvirtException)42 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)20 Connect (org.libvirt.Connect)16 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)14 StoragePoolInfo (org.libvirt.StoragePoolInfo)8 LibvirtStoragePoolDef (com.cloud.agent.resource.computing.LibvirtStoragePoolDef)7 StorageVol (org.libvirt.StorageVol)7 Secret (org.libvirt.Secret)6 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)5 LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)4 ArrayList (java.util.ArrayList)4 LibvirtSecretDef (com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)2 VolumeFormat (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat)2 Domain (org.libvirt.Domain)2 MigrateWithStorageAcrossClustersAnswer (com.cloud.agent.api.MigrateWithStorageAcrossClustersAnswer)1 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)1 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)1 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)1 VolumeTO (com.cloud.agent.api.to.VolumeTO)1