Search in sources :

Example 96 with LibvirtException

use of org.libvirt.LibvirtException 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 97 with LibvirtException

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

Example 98 with LibvirtException

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

the class LibvirtStorageAdaptor method refresh.

@Override
public boolean refresh(KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    try {
        virtPool.refresh(0);
    } catch (LibvirtException e) {
        return false;
    }
    return true;
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException)

Example 99 with LibvirtException

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

Example 100 with LibvirtException

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

the class LibvirtComputingResource method getInterfaces.

protected List<InterfaceDef> getInterfaces(Connect conn, String vmName) {
    LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        parser.parseDomainXML(dm.getXMLDesc(0));
        return parser.getInterfaces();
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<InterfaceDef>();
    } catch (Exception e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<InterfaceDef>();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException e) {
        }
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) Domain(org.libvirt.Domain) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

LibvirtException (org.libvirt.LibvirtException)176 Connect (org.libvirt.Connect)109 Answer (com.cloud.agent.api.Answer)63 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)58 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)55 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)55 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)55 Test (org.junit.Test)55 Domain (org.libvirt.Domain)53 InternalErrorException (com.cloud.exception.InternalErrorException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)41 URISyntaxException (java.net.URISyntaxException)32 StoragePool (org.libvirt.StoragePool)27 NicTO (com.cloud.agent.api.to.NicTO)25 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)23 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)22 ConfigurationException (javax.naming.ConfigurationException)22 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)21 FileNotFoundException (java.io.FileNotFoundException)17