use of com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef 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 com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef in project cloudstack by apache.
the class LibvirtStorageAdaptor method getPhysicalDisk.
@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
try {
StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
KVMPhysicalDisk disk;
LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
disk.setSize(vol.getInfo().allocation);
disk.setVirtualSize(vol.getInfo().capacity);
/**
* libvirt returns format = 'unknow', so we have to force
* the format to RAW for RBD storage volumes
*/
if (pool.getType() == StoragePoolType.RBD) {
disk.setFormat(PhysicalDiskFormat.RAW);
} else if (voldef.getFormat() == null) {
File diskDir = new File(disk.getPath());
if (diskDir.exists() && diskDir.isDirectory()) {
disk.setFormat(PhysicalDiskFormat.DIR);
} else if (volumeUuid.endsWith("tar") || volumeUuid.endsWith(("TAR"))) {
disk.setFormat(PhysicalDiskFormat.TAR);
} else if (volumeUuid.endsWith("raw") || volumeUuid.endsWith(("RAW"))) {
disk.setFormat(PhysicalDiskFormat.RAW);
} else {
disk.setFormat(pool.getDefaultFormat());
}
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.QCOW2) {
disk.setFormat(PhysicalDiskFormat.QCOW2);
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.RAW) {
disk.setFormat(PhysicalDiskFormat.RAW);
}
return disk;
} catch (LibvirtException e) {
s_logger.debug("Failed to get physical disk:", e);
throw new CloudRuntimeException(e.toString());
}
}
use of com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef 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;
}
use of com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef in project cloudstack by apache.
the class LibvirtStorageAdaptor method createVolume.
public StorageVol createVolume(Connect conn, StoragePool pool, String uuid, long size, VolumeFormat format) throws LibvirtException {
LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, format, null, null);
s_logger.debug(volDef.toString());
return pool.storageVolCreateXML(volDef.toString(), 0);
}
Aggregations