Search in sources :

Example 1 with LibvirtStorageVolumeDef

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());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) StorageVol(org.libvirt.StorageVol) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) StoragePoolInfo(org.libvirt.StoragePoolInfo)

Example 2 with LibvirtStorageVolumeDef

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());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) File(java.io.File)

Example 3 with LibvirtStorageVolumeDef

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;
}
Also used : VolumeFormat(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat) StoragePool(org.libvirt.StoragePool) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with LibvirtStorageVolumeDef

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);
}
Also used : LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)

Aggregations

LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 LibvirtException (org.libvirt.LibvirtException)3 StorageVol (org.libvirt.StorageVol)3 StoragePool (org.libvirt.StoragePool)2 VolumeFormat (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat)1 File (java.io.File)1 QemuImgFile (org.apache.cloudstack.utils.qemu.QemuImgFile)1 Connect (org.libvirt.Connect)1 StoragePoolInfo (org.libvirt.StoragePoolInfo)1