Search in sources :

Example 16 with StoragePool

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

the class LibvirtStorageAdaptor method CreateSharedStoragePool.

private StoragePool CreateSharedStoragePool(Connect conn, String uuid, String host, String path) {
    String mountPoint = path;
    if (!_storageLayer.exists(mountPoint)) {
        return null;
    }
    LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, host, path, path);
    StoragePool sp = null;
    try {
        s_logger.debug(spd.toString());
        sp = conn.storagePoolDefineXML(spd.toString(), 0);
        sp.create(0);
        return sp;
    } catch (LibvirtException e) {
        s_logger.debug(e.toString());
        if (sp != null) {
            try {
                sp.undefine();
                sp.free();
            } catch (LibvirtException l) {
                s_logger.debug("Failed to define shared mount point storage pool with: " + l.toString());
            }
        }
        return null;
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef)

Example 17 with StoragePool

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

Example 18 with StoragePool

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

the class LibvirtStorageAdaptor method createStoragePool.

@Override
public KVMStoragePool createStoragePool(String name, String host, String path, StoragePoolType type) {
    StoragePool sp = null;
    Connect conn = null;
    try {
        conn = LibvirtConnection.getConnection();
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    try {
        sp = conn.storagePoolLookupByUUIDString(name);
        if (sp.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            sp.undefine();
            sp = null;
        }
    } catch (LibvirtException e) {
    }
    if (sp == null) {
        if (type == StoragePoolType.NetworkFilesystem) {
            sp = createNfsStoragePool(conn, name, host, path);
        } else if (type == StoragePoolType.SharedMountPoint || type == StoragePoolType.Filesystem) {
            sp = CreateSharedStoragePool(conn, name, host, path);
        }
    }
    try {
        StoragePoolInfo spi = sp.getInfo();
        if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            sp.create(0);
        }
        LibvirtStoragePoolDef spd = getStoragePoolDef(conn, sp);
        LibvirtStoragePool pool = new LibvirtStoragePool(name, sp.getName(), type, this, sp);
        pool.setLocalPath(spd.getTargetPath());
        getStats(pool);
        return pool;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) StoragePoolInfo(org.libvirt.StoragePoolInfo) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef)

Example 19 with StoragePool

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

the class LibvirtStorageAdaptor method deleteStoragePool.

@Override
public boolean deleteStoragePool(String uuid) {
    Connect conn = null;
    try {
        conn = LibvirtConnection.getConnection();
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    StoragePool sp = null;
    try {
        sp = conn.storagePoolLookupByUUIDString(uuid);
    } catch (LibvirtException e) {
        return true;
    }
    try {
        sp.destroy();
        sp.undefine();
        sp.free();
        return true;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) StoragePool(org.libvirt.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect)

Example 20 with StoragePool

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

the class LibvirtStorageAdaptor method createCLVMStoragePool.

private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host, String path) {
    String volgroupPath = "/dev/" + path;
    String volgroupName = path;
    volgroupName = volgroupName.replaceFirst("/", "");
    LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath);
    StoragePool sp = null;
    try {
        s_logger.debug(spd.toString());
        sp = conn.storagePoolDefineXML(spd.toString(), 0);
        sp.create(0);
        return sp;
    } catch (LibvirtException e) {
        s_logger.debug(e.toString());
        if (sp != null) {
            try {
                sp.undefine();
                sp.free();
            } catch (LibvirtException l) {
                s_logger.debug("Failed to define clvm storage pool with: " + l.toString());
            }
        }
        return null;
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef)

Aggregations

StoragePool (org.libvirt.StoragePool)31 LibvirtException (org.libvirt.LibvirtException)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 Connect (org.libvirt.Connect)8 LibvirtStoragePoolDef (com.cloud.agent.resource.computing.LibvirtStoragePoolDef)7 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)7 StoragePoolInfo (org.libvirt.StoragePoolInfo)6 StorageVol (org.libvirt.StorageVol)4 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)3 Secret (org.libvirt.Secret)3 LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)2 ArrayList (java.util.ArrayList)2 LibvirtStorageVolumeDef (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef)1 LibvirtStorageVolumeDef.volFormat (com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat)1 LibvirtSecretDef (com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)1 VolumeFormat (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat)1 File (java.io.File)1 URI (java.net.URI)1