From cbfd13c455f89043d8782f86ae7c1832fe84e0b5 Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Wed, 23 Apr 2014 15:46:37 +0530 Subject: glustercli: Added geo-rep status Added method to parse gluster cli output of "gluster volume geo-rep status" and provide output in the format {volumename : {'status': STATUS, 'detail': message string}} Temporarily parsing string output till cli xml output is available for geo-rep (https://bugzilla.redhat.com/show_bug.cgi?id=1090910) Change-Id: Ie12cfcd8bb0d3bf0b3d9c13567e40d9014c47f59 Signed-off-by: Sahina Bose Reviewed-on: http://review.gluster.org/7590 Reviewed-by: Aravinda VK Reviewed-by: Bala FA --- glusternagios/glustercli.py | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'glusternagios') diff --git a/glusternagios/glustercli.py b/glusternagios/glustercli.py index 771feeb..4426e22 100755 --- a/glusternagios/glustercli.py +++ b/glusternagios/glustercli.py @@ -94,6 +94,13 @@ class VolumeSplitBrainStatus: SPLITBRAIN = 'SPLITBRAIN' +class GeoRepStatus: + OK = 'OK' + NOT_STARTED = "NOT_STARTED" + FAULTY = "FAULTY" + PARTIAL_FAULTY = "PARTIAL_FAULTY" + + class TransportType: TCP = 'TCP' RDMA = 'RDMA' @@ -469,6 +476,66 @@ def _parseVolumeSelfHealSplitBrainInfo(out): return value +def _parseVolumeGeoRepStatus(volumeName, out): + detail = "" + status = GeoRepStatus.OK + # https://bugzilla.redhat.com/show_bug.cgi?id=1090910 - opened for xml + # output. For now parsing below string output format + # MASTER NODE MASTER VOL MASTER BRICK + # SLAVE STATUS CHECKPOINT STATUS CRAWL STATUS + slaves = {} + all_status = ['ACTIVE', 'PASSIVE', 'FAULTY', 'NOT STARTED', 'INITIALISING'] + for line in out: + if any(gstatus in line.upper() for gstatus in all_status): + nodeline = line.split() + slave = nodeline[3] + if slaves.get(slave) is None: + slaves[slave] = {'nodecount': 0, + 'faultcount': 0, + 'notstarted': 0} + slaves[slave]['nodecount'] += 1 + if GeoRepStatus.FAULTY in line.upper() \ + or "NOT STARTED" in line.upper(): + node = nodeline[0] + if GeoRepStatus.FAULTY == nodeline[4].upper(): + slaves[slave]['faultcount'] += 1 + tempstatus = GeoRepStatus.FAULTY + else: + slaves[slave]['notstarted'] += 1 + tempstatus = GeoRepStatus.NOT_STARTED + detail += ("%s - %s - %s;" % (slave, + node, + tempstatus)) + for slave, count_dict in slaves.iteritems(): + if count_dict['nodecount'] == count_dict['faultcount']: + status = GeoRepStatus.FAULTY + break + elif count_dict['faultcount'] > 0: + status = GeoRepStatus.PARTIAL_FAULTY + elif count_dict['notstarted'] > 0 and status == GeoRepStatus.OK: + status = GeoRepStatus.NOT_STARTED + return {volumeName: {'status': status, 'detail': detail}} + + +def volumeGeoRepStatus(volumeName, remoteServer=None): + """ + Arguments: + * VolumeName + Returns: + {VOLUMENAME: {'status': GEOREPSTATUS, + 'detail': detailed message}} + """ + command = _getGlusterVolCmd() + ["geo-replication", volumeName, "status"] + if remoteServer: + command += ['--remote-host=%s' % remoteServer] + + rc, out, err = _execGluster(command) + + if rc == 0: + return _parseVolumeGeoRepStatus(volumeName, out) + raise GlusterCmdFailedException(rc=rc, err=err) + + def volumeHealSplitBrainStatus(volumeName, remoteServer=None): """ Arguments: -- cgit