[pve-devel] [PATCH manager 05/14] ceph: mon list: make more robust

Dominik Csapak d.csapak at proxmox.com
Tue Jun 18 15:42:49 CEST 2019


in a case where we cannot connect to any monitor, we did not get
any info even if we have them via the pmxcfs

so get the RADOS object in an eval, and get the info we have from the
config/pmxcfs, and set the state to unknown if we cannot query via RADOS

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Ceph/MON.pm | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index 52d0ae1c..c7de3624 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -83,11 +83,11 @@ __PACKAGE__->register_method ({
 
 	my $cfg = cfs_read_file('ceph.conf');
 
-	my $monhash = {};
+	my $rados = eval { PVE::RADOS->new() };
+	warn $@ if $@;
+	my $monhash = PVE::Ceph::Services::get_services_info("mon", $cfg, $rados);
 
-	eval {
-	    my $rados = PVE::RADOS->new();
-	    $monhash = PVE::Ceph::Services::get_services_info("mon", $cfg, $rados);
+	if ($rados) {
 	    my $monstat = $rados->mon_command({ prefix => 'mon_status' });
 
 	    my $mons = $monstat->{monmap}->{mons};
@@ -101,8 +101,13 @@ __PACKAGE__->register_method ({
 		}
 	    }
 
-	};
-	warn $@ if $@;
+	} else {
+	    # we cannot check the status if we do not have a RADOS
+	    # object, so set the state to unknown
+	    foreach my $monid (sort keys %$monhash) {
+		$monhash->{$monid}->{state} = 'unknown';
+	    }
+	}
 
 	return PVE::RESTHandler::hash_to_array($monhash, 'name');
     }});
-- 
2.11.0





More information about the pve-devel mailing list