Search in sources :

Example 1 with ResourceGroup

use of com.linbit.linstor.api.model.ResourceGroup in project cloudstack by apache.

the class LinstorUtil method getCapacityBytes.

public static long getCapacityBytes(String linstorUrl, String rscGroupName) {
    DevelopersApi linstorApi = getLinstorAPI(linstorUrl);
    try {
        List<ResourceGroup> rscGrps = linstorApi.resourceGroupList(Collections.singletonList(rscGroupName), null, null, null);
        if (rscGrps.isEmpty()) {
            final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName);
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        List<StoragePool> storagePools = linstorApi.viewStoragePools(Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null);
        return storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(StoragePool::getTotalCapacity).sum() * // linstor uses kiB
        1024;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ApiException(com.linbit.linstor.api.ApiException) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ProviderKind(com.linbit.linstor.api.model.ProviderKind) StoragePool(com.linbit.linstor.api.model.StoragePool) Collections(java.util.Collections) Configuration(com.linbit.linstor.api.Configuration) DevelopersApi(com.linbit.linstor.api.DevelopersApi) StoragePool(com.linbit.linstor.api.model.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiException(com.linbit.linstor.api.ApiException)

Example 2 with ResourceGroup

use of com.linbit.linstor.api.model.ResourceGroup in project cloudstack by apache.

the class LinstorStorageAdaptor method getUsed.

public long getUsed(LinstorStoragePool pool) {
    DevelopersApi linstorApi = getLinstorAPI(pool);
    final String rscGroupName = pool.getResourceGroup();
    try {
        List<ResourceGroup> rscGrps = linstorApi.resourceGroupList(Collections.singletonList(rscGroupName), null, null, null);
        if (rscGrps.isEmpty()) {
            final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName);
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        List<StoragePool> storagePools = linstorApi.viewStoragePools(Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null);
        final long used = storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(sp -> sp.getTotalCapacity() - sp.getFreeCapacity()).sum() * // linstor uses Kib
        1024;
        s_logger.debug("Linstor: getUsed() -> " + used);
        return used;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) HashMap(java.util.HashMap) StoragePool(com.linbit.linstor.api.model.StoragePool) Configuration(com.linbit.linstor.api.Configuration) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ProviderKind(com.linbit.linstor.api.model.ProviderKind) Map(java.util.Map) Properties(com.linbit.linstor.api.model.Properties) VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) Storage(com.cloud.storage.Storage) Nonnull(javax.annotation.Nonnull) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) ResourceMakeAvailable(com.linbit.linstor.api.model.ResourceMakeAvailable) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ResourceDefinitionModify(com.linbit.linstor.api.model.ResourceDefinitionModify) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) StringJoiner(java.util.StringJoiner) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) StoragePool(com.linbit.linstor.api.model.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiException(com.linbit.linstor.api.ApiException)

Example 3 with ResourceGroup

use of com.linbit.linstor.api.model.ResourceGroup in project cloudstack by apache.

the class LinstorStorageAdaptor method getAvailable.

public long getAvailable(LinstorStoragePool pool) {
    DevelopersApi linstorApi = getLinstorAPI(pool);
    final String rscGroupName = pool.getResourceGroup();
    try {
        List<ResourceGroup> rscGrps = linstorApi.resourceGroupList(Collections.singletonList(rscGroupName), null, null, null);
        if (rscGrps.isEmpty()) {
            final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName);
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        List<StoragePool> storagePools = linstorApi.viewStoragePools(Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null);
        final long free = storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(StoragePool::getFreeCapacity).sum() * // linstor uses KiB
        1024;
        s_logger.debug("Linstor: getAvailable() -> " + free);
        return free;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) HashMap(java.util.HashMap) StoragePool(com.linbit.linstor.api.model.StoragePool) Configuration(com.linbit.linstor.api.Configuration) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ProviderKind(com.linbit.linstor.api.model.ProviderKind) Map(java.util.Map) Properties(com.linbit.linstor.api.model.Properties) VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) Storage(com.cloud.storage.Storage) Nonnull(javax.annotation.Nonnull) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) ResourceMakeAvailable(com.linbit.linstor.api.model.ResourceMakeAvailable) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ResourceDefinitionModify(com.linbit.linstor.api.model.ResourceDefinitionModify) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) StringJoiner(java.util.StringJoiner) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) StoragePool(com.linbit.linstor.api.model.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiException(com.linbit.linstor.api.ApiException)

Example 4 with ResourceGroup

use of com.linbit.linstor.api.model.ResourceGroup in project cloudstack by apache.

the class LinstorStorageAdaptor method getCapacity.

public long getCapacity(LinstorStoragePool pool) {
    DevelopersApi linstorApi = getLinstorAPI(pool);
    final String rscGroupName = pool.getResourceGroup();
    try {
        List<ResourceGroup> rscGrps = linstorApi.resourceGroupList(Collections.singletonList(rscGroupName), null, null, null);
        if (rscGrps.isEmpty()) {
            final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName);
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        List<StoragePool> storagePools = linstorApi.viewStoragePools(Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null);
        final long capacity = storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(sp -> sp.getTotalCapacity() != null ? sp.getTotalCapacity() : 0).sum() * // linstor uses kiB
        1024;
        s_logger.debug("Linstor: GetCapacity() -> " + capacity);
        return capacity;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) HashMap(java.util.HashMap) StoragePool(com.linbit.linstor.api.model.StoragePool) Configuration(com.linbit.linstor.api.Configuration) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ProviderKind(com.linbit.linstor.api.model.ProviderKind) Map(java.util.Map) Properties(com.linbit.linstor.api.model.Properties) VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) Storage(com.cloud.storage.Storage) Nonnull(javax.annotation.Nonnull) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) ResourceMakeAvailable(com.linbit.linstor.api.model.ResourceMakeAvailable) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ResourceDefinitionModify(com.linbit.linstor.api.model.ResourceDefinitionModify) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) StringJoiner(java.util.StringJoiner) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) StoragePool(com.linbit.linstor.api.model.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ApiClient (com.linbit.linstor.api.ApiClient)4 ApiException (com.linbit.linstor.api.ApiException)4 Configuration (com.linbit.linstor.api.Configuration)4 DevelopersApi (com.linbit.linstor.api.DevelopersApi)4 ProviderKind (com.linbit.linstor.api.model.ProviderKind)4 ResourceGroup (com.linbit.linstor.api.model.ResourceGroup)4 StoragePool (com.linbit.linstor.api.model.StoragePool)4 Collections (java.util.Collections)4 List (java.util.List)4 Logger (org.apache.log4j.Logger)4 Storage (com.cloud.storage.Storage)3 ApiCallRc (com.linbit.linstor.api.model.ApiCallRc)3 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)3 Properties (com.linbit.linstor.api.model.Properties)3 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)3 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)3 ResourceGroupSpawn (com.linbit.linstor.api.model.ResourceGroupSpawn)3 ResourceMakeAvailable (com.linbit.linstor.api.model.ResourceMakeAvailable)3 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)3