Search in sources :

Example 6 with LibvirtStoragePoolDef

use of com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef in project cloudstack by apache.

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.storagePoolCreateXML(spd.toString(), 0);
        return sp;
    } catch (LibvirtException e) {
        s_logger.error(e.toString());
        if (sp != null) {
            try {
                if (sp.isPersistent() == 1) {
                    sp.destroy();
                    sp.undefine();
                } else {
                    sp.destroy();
                }
                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.hypervisor.kvm.resource.LibvirtStoragePoolDef)

Example 7 with LibvirtStoragePoolDef

use of com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef in project cloudstack by apache.

the class ManagedNfsStorageAdaptor method connectPhysicalDisk.

/*
     * creates a nfs storage pool using libvirt
     */
@Override
public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map<String, String> details) {
    StoragePool sp = null;
    Connect conn = null;
    String targetPath = null;
    LibvirtStoragePoolDef spd = null;
    try {
        conn = LibvirtConnection.getConnection();
        if (conn == null) {
            throw new CloudRuntimeException("Failed to create Libvrt Connection");
        }
        targetPath = "/mnt" + volumeUuid;
        spd = new LibvirtStoragePoolDef(PoolType.NETFS, volumeUuid, details.get(DiskTO.UUID), pool.getSourceHost(), details.get(DiskTO.MOUNT_POINT), targetPath);
        _storageLayer.mkdir(targetPath);
        s_logger.debug(spd.toString());
        sp = conn.storagePoolCreateXML(spd.toString(), 0);
        if (sp == null) {
            throw new CloudRuntimeException("Failed to create storage pool:" + volumeUuid);
        }
        try {
            if (sp.isActive() == 0) {
                // s_logger.debug("attempting to activate pool " + name);
                sp.create(0);
            }
            // now add the storage pool
            LibvirtStoragePool storagePool = (LibvirtStoragePool) getStoragePool(pool.getUuid());
            storagePool.setPool(sp);
            return true;
        } catch (LibvirtException e) {
            String error = e.toString();
            if (error.contains("Storage source conflict")) {
                throw new CloudRuntimeException("A pool matching this location already exists in libvirt, " + " but has a different UUID/Name. Cannot create new pool without first " + " removing it. Check for inactive pools via 'virsh pool-list --all'. " + error);
            } else {
                throw new CloudRuntimeException(error);
            }
        }
    } catch (LibvirtException e) {
        s_logger.error(e.toString());
        // if error is that pool is mounted, try to handle it
        if (e.toString().contains("already mounted")) {
            s_logger.error("Attempting to unmount old mount libvirt is unaware of at " + targetPath);
            String result = Script.runSimpleBashScript("umount -l " + targetPath);
            if (result == null) {
                s_logger.error("Succeeded in unmounting " + targetPath);
                try {
                    conn.storagePoolCreateXML(spd.toString(), 0);
                    s_logger.error("Succeeded in redefining storage");
                    return true;
                } catch (LibvirtException l) {
                    s_logger.error("Target was already mounted, unmounted it but failed to redefine storage:" + l);
                }
            } else {
                s_logger.error("Failed in unmounting and redefining storage");
            }
        } else {
            s_logger.error("Internal error occurred when attempting to mount:" + e.getMessage());
            // stacktrace for agent.log
            e.printStackTrace();
            throw new CloudRuntimeException(e.toString());
        }
        return false;
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) LibvirtStoragePoolDef(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)

Aggregations

LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)7 LibvirtException (org.libvirt.LibvirtException)7 StoragePool (org.libvirt.StoragePool)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 Connect (org.libvirt.Connect)3 Secret (org.libvirt.Secret)2 LibvirtSecretDef (com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)1 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)1