summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs
diff options
context:
space:
mode:
authorArthy Loganathan <aloganat@redhat.com>2016-10-21 11:15:30 +0530
committerJonathan Holloway <jholloway@redhat.com>2016-10-25 08:08:50 -0700
commit0e0f958776091fb155822323467efd114d7326b5 (patch)
tree3a6b92b87970de3bd0196c5c5a53fa91b6d3ca24 /glustolibs-gluster/glustolibs
parent0e45e5434241f52301b21a26b1b4de4897b23019 (diff)
Added volume_list() and get_volume_list() in volume_ops.py
Change-Id: I66339659158efd3af466ccd83aa243011eee61d8 Signed-off-by: Arthy Loganathan <aloganat@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/volume_ops.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/volume_ops.py b/glustolibs-gluster/glustolibs/gluster/volume_ops.py
index 603bcfc0d..0239152c6 100644
--- a/glustolibs-gluster/glustolibs/gluster/volume_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/volume_ops.py
@@ -703,3 +703,60 @@ def volume_sync(mnode, hostname, volname="all"):
cmd = "gluster volume sync %s %s --mode=script" % (hostname, volname)
return g.run(mnode, cmd)
+
+
+def volume_list(mnode):
+ """Executes gluster volume list cli command
+
+ Args:
+ mnode (str): Node on which cmd 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.
+
+ Example:
+ volume_list("abc.com")
+ """
+
+ cmd = "gluster volume list"
+ return g.run(mnode, cmd)
+
+
+def get_volume_list(mnode):
+ """Fetches the volume names in the gluster.
+ Uses xml output of volume list and parses it into to list
+
+ Args:
+ mnode (str): Node on which cmd has to be executed.
+
+ Returns:
+ NoneType: If there are errors
+ list: List of volume names
+
+ Example:
+ get_volume_list("abc.com")
+ >>>['testvol1', 'testvol2']
+ """
+
+ cmd = "gluster volume list --xml"
+ ret, out, _ = g.run(mnode, cmd)
+ if ret != 0:
+ g.log.error("volume list returned error")
+ return None
+
+ root = etree.XML(out)
+ vol_list = []
+ for volume in root.findall("volList"):
+ for elem in volume.getchildren():
+ if elem.tag == "volume":
+ vol_list.append(elem.text)
+
+ return vol_list