]> git.proxmox.com Git - pve-manager.git/commitdiff
followup: refactor & code cleanup
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 24 Apr 2019 10:22:58 +0000 (10:22 +0000)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 24 Apr 2019 10:22:58 +0000 (10:22 +0000)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Ceph/OSD.pm

index 9f1e677975e6c28fd169ee1539ce74b2f61a5e91..11f3949e7d69f84763f016fb7e1acf16d9b638d0 100644 (file)
@@ -45,19 +45,18 @@ my $get_osd_status = sub {
 my $get_osd_usage = sub {
     my ($rados) = @_;
 
-    my $res = $rados->mon_command({ prefix => 'pg dump', dumpcontents => [ 'osds' ]}) || [];
-    my $osdlist;
-
-    if (ref($res) eq "HASH") { # since nautilus
-       $osdlist = $res->{osd_stats};
-    } elsif (ref($res) eq "ARRAY") { # until luminous
-       $osdlist = $res;
-    } else { # bail
-       die "unknown format of pg dump osds\n";
+    my $osdlist = $rados->mon_command({ prefix => 'pg dump', dumpcontents => [ 'osds' ]});
+    if (!($osdlist && ref($osdlist))) {
+       warn "got unknown result format for 'pg dump osds' command\n";
+       return [];
     }
 
-    my $osdstat;
-    foreach my $d (@$osdlist) {
+    if (ref($osdlist) eq "HASH") { # since nautilus
+       $osdlist = $osdlist->{osd_stats};
+    }
+
+    my $osdstat = {};
+    for my $d (@$osdlist) {
        $osdstat->{$d->{osd}} = $d if defined($d->{osd});
     }
 
@@ -96,7 +95,7 @@ __PACKAGE__->register_method ({
 
        my ($osdhash, $flags) = &$get_osd_status($rados);
 
-       my $usagehash = &$get_osd_usage($rados);
+       my $osd_usage = $get_osd_usage->($rados);
 
        my $osdmetadata_tmp = $rados->mon_command({ prefix => 'osd metadata' });
 
@@ -124,7 +123,7 @@ __PACKAGE__->register_method ({
                $new->{in} = $stat->{in} if defined($stat->{in});
            }
 
-           if (my $stat = $usagehash->{$e->{id}}) {
+           if (my $stat = $osd_usage->{$e->{id}}) {
                $new->{total_space} = ($stat->{kb} || 1) * 1024;
                $new->{bytes_used} = ($stat->{kb_used} || 0) * 1024;
                $new->{percent_used} = ($new->{bytes_used}*100)/$new->{total_space};