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