Search in sources :

Example 1 with LibvirtStorageVolumeDef.volFormat

use of com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method createPhysicalDisk.

@Override
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, PhysicalDiskFormat format, long size) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    LibvirtStorageVolumeDef.volFormat libvirtformat = null;
    if (format == PhysicalDiskFormat.QCOW2) {
        libvirtformat = LibvirtStorageVolumeDef.volFormat.QCOW2;
    } else if (format == PhysicalDiskFormat.RAW) {
        libvirtformat = LibvirtStorageVolumeDef.volFormat.RAW;
    }
    LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null);
    s_logger.debug(volDef.toString());
    try {
        StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        KVMPhysicalDisk disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
        disk.setFormat(format);
        disk.setSize(vol.getInfo().allocation);
        disk.setVirtualSize(vol.getInfo().capacity);
        return disk;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtStorageVolumeDef(com.cloud.agent.resource.computing.LibvirtStorageVolumeDef) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) LibvirtStorageVolumeDef.volFormat(com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

LibvirtStorageVolumeDef (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef)1 LibvirtStorageVolumeDef.volFormat (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 LibvirtException (org.libvirt.LibvirtException)1 StoragePool (org.libvirt.StoragePool)1 StorageVol (org.libvirt.StorageVol)1