use of com.linbit.linstor.api.ApiException 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);
}
}
Aggregations