diff options
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/snap_ops.py')
-rw-r--r-- | glustolibs-gluster/glustolibs/gluster/snap_ops.py | 105 |
1 files changed, 48 insertions, 57 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/snap_ops.py b/glustolibs-gluster/glustolibs/gluster/snap_ops.py index 2ca5688b5..0fba7771b 100644 --- a/glustolibs-gluster/glustolibs/gluster/snap_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/snap_ops.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2015-2016 Red Hat, Inc. <http://www.redhat.com> +# Copyright (C) 2015-2020 Red Hat, Inc. <http://www.redhat.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -304,7 +304,7 @@ def get_snap_status_by_snapname(mnode, snapname): return None -def get_snap_status_by_volname(mnode, volname): +def snap_status_by_volname(mnode, volname): """Parse the output of 'gluster snapshot status' command for the given volume. @@ -313,59 +313,18 @@ def get_snap_status_by_volname(mnode, volname): volname (str): snapshot name Returns: - NoneType: None if command execution fails, parse errors. - list: list of dicts on success. - - Examples: - >>> get_snap_status_by_volname('abc.lab.eng.xyz.com', - 'testvol') - [{'volCount': '1', 'volume': {'brick': [{'path': '10.70.47.11: - testvol_brick0', 'pid': '26747', 'lvUsage': '3.52', 'volumeGroup': - 'RHS_vg0', 'lvSize': '9.95g'}, {'path': '10.70.47.16:/testvol_brick1', - 'pid': '25497', 'lvUsage': '3.52', 'volumeGroup': 'RHS_vg0', - 'lvSize': '9.95g'}], 'brickCount': '2'}, 'name': 'snap2', 'uuid': - '56a39a92-c339-47cc-a8b2-9e54bb2a6324'}, {'volCount': '1', 'volume': - {'brick': [{'path': '10.70.47.11:testvol_next_brick0', 'pid': '26719', - 'lvUsage': '4.93', 'volumeGroup': 'RHS_vg1', 'lvSize': '9.95g'}], - 'brickCount': '1'}, 'name': 'next_snap1', - 'uuid': 'dcf0cd31-c0db-47ad-92ec-f72af2d7b385'}] - """ - - cmd = "gluster snapshot status volume %s --xml" % volname - ret, out, _ = g.run(mnode, cmd) - if ret != 0: - g.log.error("Failed to execute 'snapshot status' on node %s. " - "Hence failed to get the snapshot status.", mnode) - return None - - try: - root = etree.XML(out) - except etree.ParseError: - g.log.error("Failed to parse the gluster snapshot " - "status xml output.") - return None + tuple: Tuple containing three elements (ret, out, err). + The first element 'ret' is of type 'int' and is the return value + of command execution. - snap_status_list = [] - for snap in root.findall("snapStatus/snapshots/snapshot"): - snap_status = {} - for element in snap.getchildren(): - if element.tag == "volume": - status = {} - status["brick"] = [] - for elmt in element.getchildren(): - if elmt.tag == "brick": - brick_info = {} - for el in elmt.getchildren(): - brick_info[el.tag] = el.text - status["brick"].append(brick_info) - else: - status[elmt.tag] = elmt.text + The second element 'out' is of type 'str' and is the stdout value + of the command execution. - snap_status[element.tag] = status - else: - snap_status[element.tag] = element.text - snap_status_list.append(snap_status) - return snap_status_list + The third element 'err' is of type 'str' and is the stderr value + of the command execution. + """ + cmd = "gluster snapshot status volume %s" % volname + return g.run(mnode, cmd) def snap_info(mnode, snapname="", volname=""): @@ -502,7 +461,7 @@ def get_snap_info_by_volname(mnode, volname): Args: mnode (str): Node on which command has to be executed. - volname (str): snapshot name + volname (str): volume name Returns: NoneType: None if command execution fails, parse errors. @@ -593,12 +552,17 @@ def snap_list(mnode): return g.run(mnode, cmd) -def get_snap_list(mnode): +def get_snap_list(mnode, volname=""): """Parse the output of 'gluster snapshot list' command. + If a volname is provided then the output will be specific + to that volume. Args: mnode (str): Node on which command has to be executed. + Kwargs: + volname (str): volume name + Returns: NoneType: None if command execution fails, parse errors. list: list of snapshots on success. @@ -608,7 +572,8 @@ def get_snap_list(mnode): ['snap1', 'snap2'] """ - ret, out, _ = g.run(mnode, "gluster snapshot list --xml") + cmd = "gluster snapshot list %s --xml" % volname + ret, out, _ = g.run(mnode, cmd) if ret != 0: g.log.error("Failed to execute 'snapshot list' on node %s. " "Hence failed to get the snapshot list.", mnode) @@ -750,7 +715,7 @@ def set_snap_config(mnode, option, volname=None): volname = "" cmd = ("gluster snapshot config %s %s %s --mode=script" - % (volname, option.keys()[0], option.values()[0])) + % (volname, list(option.keys())[0], list(option.values())[0])) return g.run(mnode, cmd) @@ -894,3 +859,29 @@ def snap_deactivate(mnode, snapname): cmd = "gluster snapshot deactivate %s --mode=script" % snapname return g.run(mnode, cmd) + + +def terminate_snapd_on_node(mnode): + """Terminate snapd on the specified node + + Args: + mnode(str):node on which commands has to be executed + + Returns: + tuple: Tuple containing three elements (ret, out, err). + The first element 'ret' is of type 'int' and is the return value + of command execution. + + The second element 'out' is of type 'str' and is the stdout value + of the command execution. + + The third element 'err' is of type 'str' and is the stderr value + of the command execution. + """ + cmd = "ps aux| grep -m1 snapd | awk '{print $2}'" + _, out, _ = g.run(mnode, cmd) + if out is None: + g.log.error("Failed to get the snapd PID using command %s", cmd) + return None + cmd = "kill -9 %s" % out + return g.run(mnode, cmd) |