use of com.linbit.linstor.api.DevelopersApi 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.DevelopersApi in project cloudstack by apache.
the class LinstorStorageAdaptor method disconnectPhysicalDiskByPath.
/**
* disconnectPhysicalDiskByPath is called after e.g. a live migration.
* The problem is we have no idea just from the path to which linstor-controller
* this resource would belong to. But as it should be highly unlikely that someone
* uses more than one linstor-controller to manage resource on the same kvm host.
* We will just take the first stored storagepool.
*/
@Override
public boolean disconnectPhysicalDiskByPath(String localPath) {
// get first storage pool from the map, as we don't know any better:
if (!MapStorageUuidToStoragePool.isEmpty()) {
s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath);
String firstKey = MapStorageUuidToStoragePool.keySet().stream().findFirst().get();
final KVMStoragePool pool = MapStorageUuidToStoragePool.get(firstKey);
s_logger.debug("Linstor: Using storpool: " + pool.getUuid());
final DevelopersApi api = getLinstorAPI(pool);
try {
List<ResourceWithVolumes> resources = api.viewResources(Collections.singletonList(localNodeName), null, null, null, null, null);
Optional<ResourceWithVolumes> rsc = getResourceByPath(resources, localPath);
if (rsc.isPresent()) {
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
rdm.deleteProps(Collections.singletonList("DrbdOptions/Net/allow-two-primaries"));
ApiCallRcList answers = api.resourceDefinitionModify(rsc.get().getName(), rdm);
if (answers.hasError()) {
s_logger.error("Failed to remove 'allow-two-primaries' on " + rsc.get().getName());
throw new CloudRuntimeException(answers.get(0).getMessage());
}
return true;
}
s_logger.warn("Linstor: Couldn't find resource for this path: " + localPath);
} catch (ApiException apiEx) {
s_logger.error(apiEx);
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
}
}
return false;
}
use of com.linbit.linstor.api.DevelopersApi 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