[pve-devel] [PATCH v2 librados2-perl 2/7] mon_command: optionally ignore errors

Aaron Lauterer a.lauterer at proxmox.com
Fri Mar 25 11:55:05 CET 2022


In some situations we do not want to abort if the Ceph API returns an
error. For example if we run the 'osd ok-to-stop' or similar calls, we
are interested in the status message in the error case.

Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---
I split the adding of "noerr" into a separate patch for a clearly
separated history

 PVE/RADOS.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/PVE/RADOS.pm b/PVE/RADOS.pm
index bec5028..36b42ed 100644
--- a/PVE/RADOS.pm
+++ b/PVE/RADOS.pm
@@ -259,7 +259,9 @@ sub cluster_stat {
 # example1: { prefix => 'get_command_descriptions'})
 # example2: { prefix => 'mon dump', format => 'json' }
 sub mon_command {
-    my ($self, $cmd) = @_;
+    my ($self, $cmd, $noerr) = @_;
+
+    $noerr = 0 if !$noerr;
 
     $cmd->{format} = 'json' if !$cmd->{format};
 
@@ -271,7 +273,7 @@ sub mon_command {
     my $raw = decode_json($ret);
 
     die "error with '$cmd->{prefix}': mon_command failed - $raw->{status_message}\n"
-	if $raw->{return_code} < 0;
+	if !$noerr && $raw->{return_code} < 0;
 
     my $data = '';
     if ($cmd->{format} && $cmd->{format} eq 'json') {
-- 
2.30.2






More information about the pve-devel mailing list