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