Search in sources :

Example 1 with StorageVol

use of org.libvirt.StorageVol in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method getPhysicalDisk.

@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.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);
        if (voldef.getFormat() == null) {
            disk.setFormat(pool.getDefaultFormat());
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.QCOW2) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.QCOW2);
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.RAW) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.RAW);
        }
        return disk;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtStorageVolumeDef(com.cloud.agent.resource.computing.LibvirtStorageVolumeDef) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with StorageVol

use of org.libvirt.StorageVol in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method deletePhysicalDisk.

@Override
public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.getVolume(libvirtPool.getPool(), uuid);
        vol.delete(0);
        vol.free();
        return true;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with StorageVol

use of org.libvirt.StorageVol in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method copyVolume.

public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException {
    StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0);
    String srcPath = srcVol.getKey();
    String destPath = vol.getKey();
    Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout);
    return vol;
}
Also used : StorageVol(org.libvirt.StorageVol)

Example 4 with StorageVol

use of org.libvirt.StorageVol 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) {
        }
    }
}
Also used : StoragePool(org.libvirt.StoragePool) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) URI(java.net.URI)

Example 5 with StorageVol

use of org.libvirt.StorageVol 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)

Aggregations

StorageVol (org.libvirt.StorageVol)24 LibvirtException (org.libvirt.LibvirtException)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Connect (org.libvirt.Connect)9 StoragePool (org.libvirt.StoragePool)7 LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)6 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)4 Test (org.junit.Test)3 IoCTX (com.ceph.rados.IoCTX)2 Rados (com.ceph.rados.Rados)2 RadosException (com.ceph.rados.exceptions.RadosException)2 Rbd (com.ceph.rbd.Rbd)2 RbdException (com.ceph.rbd.RbdException)2 RbdImage (com.ceph.rbd.RbdImage)2 RbdSnapInfo (com.ceph.rbd.jna.RbdSnapInfo)2 Answer (com.cloud.agent.api.Answer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)2 LibvirtStorageVolumeDef (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef)2