summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinayak Papnoi <vpapnoi@redhat.com>2018-06-13 13:04:32 +0530
committerJonathan Holloway <jholloway@redhat.com>2018-06-14 04:53:45 +0000
commit58d25cdc2b780979b56765705af17f593835f02f (patch)
tree9c0358551e46df6fc45280b9fad5dee77f1be10a
parentc3792e52ee822cb59a6cf7802023e4220e2163b5 (diff)
Quota : Library to get the quotad pid
Adding quota_libs.py with the quota_fetch_daemon_pid library. This library gets the PID of quota daemon from all the nodes. Change-Id: Icc5ecba5649a2f7fd48d5cedda6c1dd3ad8b50c0 Signed-off-by: Vinayak Papnoi <vpapnoi@redhat.com>
-rw-r--r--glustolibs-gluster/glustolibs/gluster/quota_libs.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/quota_libs.py b/glustolibs-gluster/glustolibs/gluster/quota_libs.py
index fc4275c..805db78 100644
--- a/glustolibs-gluster/glustolibs/gluster/quota_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/quota_libs.py
@@ -61,3 +61,70 @@ def quota_validate(mnode, volname, path, **kwargs):
ret = False
return ret
+
+
+def quota_fetch_daemon_pid(nodes):
+ """
+ Checks if quota daemon process is running and
+ return the process id's in dictionary format
+
+ Args:
+ nodes ( str|list ) : Node/Nodes of the cluster
+
+ Returns:
+ tuple : Tuple containing two elements (ret, quotad_pids).
+ The first element 'ret' is of type 'bool', True if and only if
+ quotad is running on all the nodes in the list and each
+ node contains only one instance of quotad running.
+ False otherwise.
+
+ The second element 'quotad_pids' is of type dictonary and it
+ contains the 'nodes' as the key and 'quotad PID' as the value.
+
+ If there is NO quota daemon running on few nodes, the first element
+ will be 'False' and the nodes which do not have a quota daemon running
+ will have a value as '-1'.
+
+ If there are MORE THAN ONE quota daemon for a node, the first element
+ will be 'False' and the value for that node will be '-1'.
+
+ Example:
+ quota_fetch_daemon_pid(["node1", "node2"])
+ (False, {'node2': ['8012'], 'node1': [-1]})
+
+ Here 'node1' doesn't have quota daemon running. Hence, value
+ of 'node1' is '-1'.
+ """
+ quotad_pids = {}
+ _rc = True
+ if isinstance(nodes, str):
+ nodes = [nodes]
+ cmd = "pgrep -f quotad | grep -v ^$$\$"
+ g.log.info("Executing cmd: %s on node %s" % (cmd, nodes))
+ results = g.run_parallel(nodes, cmd)
+ for node in results:
+ ret, out, err = results[node]
+ if ret == 0:
+ if len(out.strip().split("\n")) == 1:
+ if not out.strip():
+ g.log.info("NO Quota daemon process found "
+ "on node %s" % node)
+ _rc = False
+ quotad_pids[node] = [-1]
+ else:
+ g.log.info("Single Quota Daemon process with "
+ "pid %s found on %s",
+ out.strip().split("\n"), node)
+ quotad_pids[node] = (out.strip().split("\n"))
+ else:
+ g.log.info("More than One Quota daemon process "
+ "found on node %s" % node)
+ _rc = False
+ quotad_pids[node] = [-1]
+ else:
+ g.log.info("Not able to get Quota daemon process "
+ "from node %s" % node)
+ _rc = False
+ quotad_pids[node] = [-1]
+
+ return _rc, quotad_pids