use of org.libvirt.StoragePool 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.StoragePool in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method listPhysicalDisks.
@Override
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
StoragePool virtPool = libvirtPool.getPool();
List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
try {
String[] vols = virtPool.listVolumes();
for (String volName : vols) {
KVMPhysicalDisk disk = this.getPhysicalDisk(volName, pool);
disks.add(disk);
}
return disks;
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
use of org.libvirt.StoragePool in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method deleteStoragePool.
@Override
public boolean deleteStoragePool(KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
StoragePool virtPool = libvirtPool.getPool();
try {
virtPool.destroy();
virtPool.undefine();
virtPool.free();
} catch (LibvirtException e) {
return false;
}
return true;
}
use of org.libvirt.StoragePool in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method getVolumeFromURI.
public StorageVol getVolumeFromURI(Connect conn, String volPath) throws LibvirtException, URISyntaxException {
int index = volPath.lastIndexOf("/");
URI volDir = null;
StoragePool sp = null;
StorageVol vol = null;
try {
volDir = new URI(volPath.substring(0, index));
String volName = volPath.substring(index + 1);
sp = getStoragePoolbyURI(conn, volDir);
vol = sp.storageVolLookupByName(volName);
return vol;
} catch (LibvirtException e) {
s_logger.debug("Faild to get vol path: " + e.toString());
throw e;
} finally {
try {
if (sp != null) {
sp.free();
}
} catch (LibvirtException e) {
}
}
}
use of org.libvirt.StoragePool 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());
}
}
Aggregations