Search in sources :

Example 1 with StoragePoolInfo

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

the class LibvirtStorageAdaptor method createFileBasedStoragePool.

public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
    if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
        return null;
    }
    File path = new File(localStoragePath);
    if (!(path.canWrite() && path.canRead() && path.canExecute())) {
        return null;
    }
    StoragePool pool = null;
    try {
        pool = conn.storagePoolLookupByUUIDString(uuid);
    } catch (LibvirtException e) {
    }
    if (pool == null) {
        LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, localStoragePath);
        try {
            pool = conn.storagePoolDefineXML(spd.toString(), 0);
            pool.create(0);
        } catch (LibvirtException e) {
            if (pool != null) {
                try {
                    pool.destroy();
                    pool.undefine();
                } catch (LibvirtException e1) {
                }
                pool = null;
            }
            throw new CloudRuntimeException(e.toString());
        }
    }
    try {
        StoragePoolInfo spi = pool.getInfo();
        if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            pool.create(0);
        }
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    return pool;
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(org.libvirt.StoragePoolInfo) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef) File(java.io.File)

Example 2 with StoragePoolInfo

use of org.libvirt.StoragePoolInfo 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 3 with StoragePoolInfo

use of org.libvirt.StoragePoolInfo in project cloudstack by apache.

the class KVMHABase method getMountPoint.

protected String getMountPoint(NfsStoragePool storagePool) {
    StoragePool pool = null;
    String poolName = null;
    try {
        pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID);
        if (pool != null) {
            StoragePoolInfo spi = pool.getInfo();
            if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
                pool.create(0);
            } else {
            /*
                     * Sometimes, the mount point is lost, even libvirt thinks
                     * the storage pool still running
                     */
            }
            poolName = pool.getName();
        }
    } catch (LibvirtException e) {
        s_logger.debug("Ignoring libvirt error.", e);
    } finally {
        try {
            if (pool != null) {
                pool.free();
            }
        } catch (LibvirtException e) {
            s_logger.debug("Ignoring libvirt error.", e);
        }
    }
    return checkingMountPoint(storagePool, poolName);
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) StoragePoolInfo(org.libvirt.StoragePoolInfo)

Example 4 with StoragePoolInfo

use of org.libvirt.StoragePoolInfo in project cosmic by MissionCriticalCloud.

the class KvmHaBase method getMountPoint.

protected String getMountPoint(final NfsStoragePool storagePool) {
    StoragePool pool = null;
    String poolName = null;
    try {
        pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool.innerPoolUuid);
        if (pool != null) {
            final StoragePoolInfo spi = pool.getInfo();
            if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
                pool.create(0);
            } else {
            /*
           * Sometimes, the mount point is lost, even libvirt thinks the storage pool still running
           */
            }
            poolName = pool.getName();
        }
    } catch (final LibvirtException e) {
        logger.debug("Ignoring libvirt error.", e);
    } finally {
        try {
            if (pool != null) {
                pool.free();
            }
        } catch (final LibvirtException e) {
            logger.debug("Ignoring libvirt error.", e);
        }
    }
    return checkingMountPoint(storagePool, poolName);
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) StoragePoolInfo(org.libvirt.StoragePoolInfo)

Example 5 with StoragePoolInfo

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

the class KVMHABase method getMountPoint.

protected String getMountPoint(NfsStoragePool storagePool) {
    StoragePool pool = null;
    String poolName = null;
    try {
        pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID);
        if (pool != null) {
            StoragePoolInfo spi = pool.getInfo();
            if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
                pool.create(0);
            } else {
            /*
					 * Sometimes, the mount point is lost, even libvirt thinks
					 * the storage pool still running
					 */
            }
        }
        poolName = pool.getName();
    } catch (LibvirtException e) {
    } finally {
        try {
            if (pool != null) {
                pool.free();
            }
        } catch (LibvirtException e) {
        }
    }
    return checkingMountPoint(storagePool, poolName);
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) StoragePoolInfo(org.libvirt.StoragePoolInfo)

Aggregations

LibvirtException (org.libvirt.LibvirtException)8 StoragePool (org.libvirt.StoragePool)8 StoragePoolInfo (org.libvirt.StoragePoolInfo)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 LibvirtStoragePoolDef (com.cloud.agent.resource.computing.LibvirtStoragePoolDef)3 Connect (org.libvirt.Connect)3 LibvirtStorageVolumeDef (com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef)2 StorageVol (org.libvirt.StorageVol)2 File (java.io.File)1