Search in sources :

Example 11 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method getResizeScriptType.

public String getResizeScriptType(final KvmStoragePool pool, final KvmPhysicalDisk vol) {
    final StoragePoolType poolType = pool.getType();
    final PhysicalDiskFormat volFormat = vol.getFormat();
    if (pool.getType() == StoragePoolType.CLVM && volFormat == PhysicalDiskFormat.RAW) {
        return "CLVM";
    } else if ((poolType == StoragePoolType.NetworkFilesystem || poolType == StoragePoolType.SharedMountPoint || poolType == StoragePoolType.Filesystem || poolType == StoragePoolType.Gluster) && volFormat == PhysicalDiskFormat.QCOW2) {
        return "QCOW2";
    }
    throw new CloudRuntimeException("Cannot determine resize type from pool type " + pool.getType());
}
Also used : StoragePoolType(com.cloud.storage.Storage.StoragePoolType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalDiskFormat(com.cloud.utils.qemu.QemuImg.PhysicalDiskFormat)

Example 12 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.

the class LibvirtStoragePoolTest method testAttributes.

public void testAttributes() {
    final String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da";
    final String name = "myfirstpool";
    final StoragePoolType type = StoragePoolType.NetworkFilesystem;
    final StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
    final StoragePool storage = Mockito.mock(StoragePool.class);
    final LibvirtStoragePool pool = new LibvirtStoragePool(uuid, name, type, adapter, storage);
    assertEquals(pool.getCapacity(), 0);
    assertEquals(pool.getUsed(), 0);
    assertEquals(pool.getName(), name);
    assertEquals(pool.getUuid(), uuid);
    assertEquals(pool.getAvailable(), 0);
    assertEquals(pool.getStoragePoolType(), type);
    pool.setCapacity(2048);
    pool.setUsed(1024);
    pool.setAvailable(1023);
    assertEquals(pool.getCapacity(), 2048);
    assertEquals(pool.getUsed(), 1024);
    assertEquals(pool.getAvailable(), 1023);
}
Also used : StoragePool(org.libvirt.StoragePool) StoragePoolType(com.cloud.storage.Storage.StoragePoolType)

Example 13 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method getStoragePool.

@Override
public KVMStoragePool getStoragePool(String uuid) {
    StoragePool storage = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        storage = conn.storagePoolLookupByUUIDString(uuid);
        if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            storage.create(0);
        }
        LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage);
        StoragePoolType type = null;
        if (spd.getPoolType() == LibvirtStoragePoolDef.poolType.NETFS || spd.getPoolType() == LibvirtStoragePoolDef.poolType.DIR) {
            type = StoragePoolType.Filesystem;
        }
        LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);
        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) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef)

Example 14 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.

the class KvmStoragePoolManager method getStoragePoolByUri.

public KvmStoragePool getStoragePoolByUri(final String uri) {
    URI storageUri = null;
    try {
        storageUri = new URI(uri);
    } catch (final URISyntaxException e) {
        throw new CloudRuntimeException(e.toString());
    }
    String sourcePath = null;
    String uuid = null;
    String sourceHost = "";
    StoragePoolType protocol = null;
    if (storageUri.getScheme().equalsIgnoreCase("nfs")) {
        sourcePath = storageUri.getPath();
        sourcePath = sourcePath.replace("//", "/");
        sourceHost = storageUri.getHost();
        uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
        protocol = StoragePoolType.NetworkFilesystem;
    }
    // secondary storage registers itself through here
    return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, false);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 15 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.

the class LibvirtStorageAdaptor method getStoragePool.

@Override
public KvmStoragePool getStoragePool(final String uuid, final boolean refreshInfo) {
    logger.info("Trying to fetch storage pool " + uuid + " from libvirt");
    StoragePool storage = null;
    try {
        final Connect conn = LibvirtConnection.getConnection();
        storage = conn.storagePoolLookupByUUIDString(uuid);
        if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it.");
            storage.create(0);
        }
        final LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage);
        if (spd == null) {
            throw new CloudRuntimeException("Unable to parse the storage pool definition for storage pool " + uuid);
        }
        StoragePoolType type = null;
        if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.NETFS) {
            type = StoragePoolType.NetworkFilesystem;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.DIR) {
            type = StoragePoolType.Filesystem;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.RBD) {
            type = StoragePoolType.RBD;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.LOGICAL) {
            type = StoragePoolType.CLVM;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.GLUSTERFS) {
            type = StoragePoolType.Gluster;
        }
        final LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);
        if (pool.getType() != StoragePoolType.RBD) {
            pool.setLocalPath(spd.getTargetPath());
        } else {
            pool.setLocalPath("");
        }
        if (pool.getType() == StoragePoolType.RBD || pool.getType() == StoragePoolType.Gluster) {
            pool.setSourceHost(spd.getSourceHost());
            pool.setSourcePort(spd.getSourcePort());
            pool.setSourceDir(spd.getSourceDir());
            final String authUsername = spd.getAuthUserName();
            if (authUsername != null) {
                final Secret secret = conn.secretLookupByUUIDString(spd.getSecretUuid());
                final String secretValue = new String(Base64.encodeBase64(secret.getByteValue()), Charset.defaultCharset());
                pool.setAuthUsername(authUsername);
                pool.setAuthSecret(secretValue);
            }
        }
        if (refreshInfo) {
            logger.info("Asking libvirt to refresh storage pool " + uuid);
            pool.refresh();
        }
        pool.setCapacity(storage.getInfo().capacity);
        pool.setUsed(storage.getInfo().allocation);
        pool.setAvailable(storage.getInfo().available);
        logger.debug("Succesfully refreshed pool " + uuid + " Capacity: " + storage.getInfo().capacity + " Used: " + storage.getInfo().allocation + " Available: " + storage.getInfo().available);
        return pool;
    } catch (final LibvirtException e) {
        logger.debug("Could not find storage pool " + uuid + " in libvirt");
        throw new CloudRuntimeException(e.toString(), e);
    }
}
Also used : Secret(org.libvirt.Secret) StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) Connect(org.libvirt.Connect) LibvirtStoragePoolDef(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)

Aggregations

StoragePoolType (com.cloud.storage.Storage.StoragePoolType)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 Test (org.junit.Test)10 URISyntaxException (java.net.URISyntaxException)6 URI (java.net.URI)5 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 LibvirtException (org.libvirt.LibvirtException)5 StoragePool (org.libvirt.StoragePool)5 Map (java.util.Map)4 Connect (org.libvirt.Connect)4 HostVO (com.cloud.host.HostVO)3 HashSet (java.util.HashSet)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LinkedList (java.util.LinkedList)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 PrimaryDataStoreParameters (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters)2 StrategyPriority (org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2