|
28 | 28 |
|
29 | 29 | import javax.annotation.Nonnull; |
30 | 30 |
|
| 31 | +import org.apache.cloudstack.storage.datastore.util.LinstorUtil; |
31 | 32 | import org.apache.cloudstack.utils.qemu.QemuImg; |
32 | 33 | import org.apache.cloudstack.utils.qemu.QemuImgException; |
33 | 34 | import org.apache.cloudstack.utils.qemu.QemuImgFile; |
@@ -489,39 +490,8 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP |
489 | 490 | } |
490 | 491 |
|
491 | 492 | public long getCapacity(LinstorStoragePool pool) { |
492 | | - DevelopersApi linstorApi = getLinstorAPI(pool); |
493 | 493 | final String rscGroupName = pool.getResourceGroup(); |
494 | | - try { |
495 | | - List<ResourceGroup> rscGrps = linstorApi.resourceGroupList( |
496 | | - Collections.singletonList(rscGroupName), |
497 | | - null, |
498 | | - null, |
499 | | - null); |
500 | | - |
501 | | - if (rscGrps.isEmpty()) { |
502 | | - final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); |
503 | | - s_logger.error(errMsg); |
504 | | - throw new CloudRuntimeException(errMsg); |
505 | | - } |
506 | | - |
507 | | - List<StoragePool> storagePools = linstorApi.viewStoragePools( |
508 | | - Collections.emptyList(), |
509 | | - rscGrps.get(0).getSelectFilter().getStoragePoolList(), |
510 | | - null, |
511 | | - null, |
512 | | - null |
513 | | - ); |
514 | | - |
515 | | - final long capacity = storagePools.stream() |
516 | | - .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) |
517 | | - .mapToLong(sp -> sp.getTotalCapacity() != null ? sp.getTotalCapacity() : 0) |
518 | | - .sum() * 1024; // linstor uses kiB |
519 | | - s_logger.debug("Linstor: GetCapacity() -> " + capacity); |
520 | | - return capacity; |
521 | | - } catch (ApiException apiEx) { |
522 | | - s_logger.error(apiEx.getMessage()); |
523 | | - throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); |
524 | | - } |
| 494 | + return LinstorUtil.getCapacityBytes(pool.getSourceHost(), rscGroupName); |
525 | 495 | } |
526 | 496 |
|
527 | 497 | public long getAvailable(LinstorStoragePool pool) { |
@@ -550,7 +520,7 @@ public long getAvailable(LinstorStoragePool pool) { |
550 | 520 |
|
551 | 521 | final long free = storagePools.stream() |
552 | 522 | .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) |
553 | | - .mapToLong(StoragePool::getFreeCapacity).sum() * 1024; // linstor uses KiB |
| 523 | + .mapToLong(sp -> sp.getFreeCapacity() != null ? sp.getFreeCapacity() : 0L).sum() * 1024; // linstor uses KiB |
554 | 524 |
|
555 | 525 | s_logger.debug("Linstor: getAvailable() -> " + free); |
556 | 526 | return free; |
@@ -586,7 +556,9 @@ public long getUsed(LinstorStoragePool pool) { |
586 | 556 |
|
587 | 557 | final long used = storagePools.stream() |
588 | 558 | .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) |
589 | | - .mapToLong(sp -> sp.getTotalCapacity() - sp.getFreeCapacity()).sum() * 1024; // linstor uses Kib |
| 559 | + .mapToLong(sp -> sp.getTotalCapacity() != null && sp.getFreeCapacity() != null ? |
| 560 | + sp.getTotalCapacity() - sp.getFreeCapacity() : 0L) |
| 561 | + .sum() * 1024; // linstor uses Kib |
590 | 562 | s_logger.debug("Linstor: getUsed() -> " + used); |
591 | 563 | return used; |
592 | 564 | } catch (ApiException apiEx) { |
|
0 commit comments