@@ -493,39 +493,8 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP
493493 }
494494
495495 public long getCapacity (LinstorStoragePool pool ) {
496- DevelopersApi linstorApi = getLinstorAPI (pool );
497496 final String rscGroupName = pool .getResourceGroup ();
498- try {
499- List <ResourceGroup > rscGrps = linstorApi .resourceGroupList (
500- Collections .singletonList (rscGroupName ),
501- null ,
502- null ,
503- null );
504-
505- if (rscGrps .isEmpty ()) {
506- final String errMsg = String .format ("Linstor: Resource group '%s' not found" , rscGroupName );
507- s_logger .error (errMsg );
508- throw new CloudRuntimeException (errMsg );
509- }
510-
511- List <StoragePool > storagePools = linstorApi .viewStoragePools (
512- Collections .emptyList (),
513- rscGrps .get (0 ).getSelectFilter ().getStoragePoolList (),
514- null ,
515- null ,
516- null
517- );
518-
519- final long capacity = storagePools .stream ()
520- .filter (sp -> sp .getProviderKind () != ProviderKind .DISKLESS )
521- .mapToLong (sp -> sp .getTotalCapacity () != null ? sp .getTotalCapacity () : 0 )
522- .sum () * 1024 ; // linstor uses kiB
523- s_logger .debug ("Linstor: GetCapacity() -> " + capacity );
524- return capacity ;
525- } catch (ApiException apiEx ) {
526- s_logger .error (apiEx .getMessage ());
527- throw new CloudRuntimeException (apiEx .getBestMessage (), apiEx );
528- }
497+ return LinstorUtil .getCapacityBytes (pool .getSourceHost (), rscGroupName );
529498 }
530499
531500 public long getAvailable (LinstorStoragePool pool ) {
@@ -554,7 +523,7 @@ public long getAvailable(LinstorStoragePool pool) {
554523
555524 final long free = storagePools .stream ()
556525 .filter (sp -> sp .getProviderKind () != ProviderKind .DISKLESS )
557- .mapToLong (StoragePool :: getFreeCapacity ).sum () * 1024 ; // linstor uses KiB
526+ .mapToLong (sp -> sp . getFreeCapacity () != null ? sp . getFreeCapacity () : 0L ).sum () * 1024 ; // linstor uses KiB
558527
559528 s_logger .debug ("Linstor: getAvailable() -> " + free );
560529 return free ;
@@ -590,7 +559,9 @@ public long getUsed(LinstorStoragePool pool) {
590559
591560 final long used = storagePools .stream ()
592561 .filter (sp -> sp .getProviderKind () != ProviderKind .DISKLESS )
593- .mapToLong (sp -> sp .getTotalCapacity () - sp .getFreeCapacity ()).sum () * 1024 ; // linstor uses Kib
562+ .mapToLong (sp -> sp .getTotalCapacity () != null && sp .getFreeCapacity () != null ?
563+ sp .getTotalCapacity () - sp .getFreeCapacity () : 0L )
564+ .sum () * 1024 ; // linstor uses Kib
594565 s_logger .debug ("Linstor: getUsed() -> " + used );
595566 return used ;
596567 } catch (ApiException apiEx ) {
0 commit comments