Search in sources :

Example 6 with LibvirtStoragePoolDef

use of com.cloud.agent.resource.computing.LibvirtStoragePoolDef 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)

Example 7 with LibvirtStoragePoolDef

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

the class LibvirtStorageAdaptor method getStoragePoolbyURI.

public StoragePool getStoragePoolbyURI(Connect conn, URI uri) throws LibvirtException {
    String sourcePath;
    String uuid;
    String sourceHost = "";
    String protocal;
    if (uri.getScheme().equalsIgnoreCase("local")) {
        sourcePath = _mountPoint + File.separator + uri.toString().replace("local:///", "");
        sourcePath = sourcePath.replace("//", "/");
        uuid = UUID.nameUUIDFromBytes(new String(sourcePath).getBytes()).toString();
        protocal = "DIR";
    } else {
        sourcePath = uri.getPath();
        sourcePath = sourcePath.replace("//", "/");
        sourceHost = uri.getHost();
        uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
        protocal = "NFS";
    }
    String targetPath = _mountPoint + File.separator + uuid;
    StoragePool sp = null;
    try {
        sp = conn.storagePoolLookupByUUIDString(uuid);
    } catch (LibvirtException e) {
    }
    if (sp == null) {
        try {
            LibvirtStoragePoolDef spd = null;
            if (protocal.equalsIgnoreCase("NFS")) {
                _storageLayer.mkdir(targetPath);
                spd = new LibvirtStoragePoolDef(poolType.NETFS, uuid, uuid, sourceHost, sourcePath, targetPath);
                s_logger.debug(spd.toString());
            // addStoragePool(uuid);
            } else if (protocal.equalsIgnoreCase("DIR")) {
                _storageLayer.mkdir(targetPath);
                spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, sourcePath);
            }
            synchronized (getStoragePool(uuid)) {
                sp = conn.storagePoolDefineXML(spd.toString(), 0);
                if (sp == null) {
                    s_logger.debug("Failed to define storage pool");
                    return null;
                }
                sp.create(0);
            }
            return sp;
        } catch (LibvirtException e) {
            try {
                if (sp != null) {
                    sp.undefine();
                    sp.free();
                }
            } catch (LibvirtException l) {
            }
            throw e;
        }
    } else {
        StoragePoolInfo spi = sp.getInfo();
        if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            sp.create(0);
        }
        return sp;
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) StoragePoolInfo(org.libvirt.StoragePoolInfo) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef)

Aggregations

LibvirtStoragePoolDef (com.cloud.agent.resource.computing.LibvirtStoragePoolDef)7 LibvirtException (org.libvirt.LibvirtException)7 StoragePool (org.libvirt.StoragePool)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 StoragePoolInfo (org.libvirt.StoragePoolInfo)3 Connect (org.libvirt.Connect)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)1 File (java.io.File)1