use of org.libvirt.StoragePoolInfo in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method createFileBasedStoragePool.
public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
return null;
}
File path = new File(localStoragePath);
if (!(path.canWrite() && path.canRead() && path.canExecute())) {
return null;
}
StoragePool pool = null;
try {
pool = conn.storagePoolLookupByUUIDString(uuid);
} catch (LibvirtException e) {
}
if (pool == null) {
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, localStoragePath);
try {
pool = conn.storagePoolDefineXML(spd.toString(), 0);
pool.create(0);
} catch (LibvirtException e) {
if (pool != null) {
try {
pool.destroy();
pool.undefine();
} catch (LibvirtException e1) {
}
pool = null;
}
throw new CloudRuntimeException(e.toString());
}
}
try {
StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
}
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
return pool;
}
use of org.libvirt.StoragePoolInfo in project cloudstack by apache.
the class ManagedNfsStorageAdaptor method getPhysicalDisk.
/*
* creates a disk based on the created nfs storage pool using libvirt
*/
@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
// now create the volume upon the given storage pool in kvm
Connect conn;
StoragePool virtPool = null;
try {
conn = LibvirtConnection.getConnection();
virtPool = conn.storagePoolLookupByName("/" + volumeUuid);
} catch (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;
StoragePoolInfo poolinfo = virtPool.getInfo();
volCapacity = poolinfo.available;
LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(volumeUuid, volCapacity, libvirtformat, null, null);
s_logger.debug(volDef.toString());
vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
}
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 (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
use of org.libvirt.StoragePoolInfo in project cloudstack by apache.
the class KVMHABase method getMountPoint.
protected String getMountPoint(NfsStoragePool storagePool) {
StoragePool pool = null;
String poolName = null;
try {
pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID);
if (pool != null) {
StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
} else {
/*
* Sometimes, the mount point is lost, even libvirt thinks
* the storage pool still running
*/
}
poolName = pool.getName();
}
} catch (LibvirtException e) {
s_logger.debug("Ignoring libvirt error.", e);
} finally {
try {
if (pool != null) {
pool.free();
}
} catch (LibvirtException e) {
s_logger.debug("Ignoring libvirt error.", e);
}
}
return checkingMountPoint(storagePool, poolName);
}
use of org.libvirt.StoragePoolInfo in project cosmic by MissionCriticalCloud.
the class KvmHaBase method getMountPoint.
protected String getMountPoint(final NfsStoragePool storagePool) {
StoragePool pool = null;
String poolName = null;
try {
pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool.innerPoolUuid);
if (pool != null) {
final StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
} else {
/*
* Sometimes, the mount point is lost, even libvirt thinks the storage pool still running
*/
}
poolName = pool.getName();
}
} catch (final LibvirtException e) {
logger.debug("Ignoring libvirt error.", e);
} finally {
try {
if (pool != null) {
pool.free();
}
} catch (final LibvirtException e) {
logger.debug("Ignoring libvirt error.", e);
}
}
return checkingMountPoint(storagePool, poolName);
}
use of org.libvirt.StoragePoolInfo in project CloudStack-archive by CloudStack-extras.
the class KVMHABase method getMountPoint.
protected String getMountPoint(NfsStoragePool storagePool) {
StoragePool pool = null;
String poolName = null;
try {
pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID);
if (pool != null) {
StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
} else {
/*
* Sometimes, the mount point is lost, even libvirt thinks
* the storage pool still running
*/
}
}
poolName = pool.getName();
} catch (LibvirtException e) {
} finally {
try {
if (pool != null) {
pool.free();
}
} catch (LibvirtException e) {
}
}
return checkingMountPoint(storagePool, poolName);
}
Aggregations