]> git.proxmox.com Git - librados2-perl.git/blobdiff - PVE/RADOS.pm
mon_command: refactor to pass all data to perl
[librados2-perl.git] / PVE / RADOS.pm
index 463abc785398ffabd33e0c62b2111418d790f143..bec502812e98843fcf2ac03174f0ad954a63fa8f 100644 (file)
@@ -201,7 +201,7 @@ sub new {
            my $res;
            eval {
                if ($cmd eq 'M') { # rados monitor commands
-                   $res = pve_rados_mon_command($self->{conn}, [ $data ]);
+                   $res = encode_json(pve_rados_mon_command($self->{conn}, [ $data ]));
                } elsif ($cmd eq 'C') { # class methods
                    my $aref = decode_json($data);
                    my $method = shift @$aref;
@@ -265,13 +265,25 @@ sub mon_command {
 
     my $json = encode_json($cmd);
 
-    my $raw = eval { $sendcmd->($self, 'M', $json) };
+    my $ret = $sendcmd->($self, 'M', $json);
     die "error with '$cmd->{prefix}': $@" if $@;
 
+    my $raw = decode_json($ret);
+
+    die "error with '$cmd->{prefix}': mon_command failed - $raw->{status_message}\n"
+       if $raw->{return_code} < 0;
+
+    my $data = '';
     if ($cmd->{format} && $cmd->{format} eq 'json') {
-       return length($raw) ? decode_json($raw) : undef;
+       $data = length($raw->{data}) ? decode_json($raw->{data}) : undef;
+    } else {
+       $data = $raw->{data};
     }
-    return $raw;
+    return {
+       return_code => $raw->{return_code},
+       status_message => $raw->{status_message},
+       data => $data,
+    };
 }