summaryrefslogtreecommitdiffstats
path: root/glustolibs-misc
diff options
context:
space:
mode:
authorVijay Avuthu <vavuthu@redhat.com>2018-02-02 11:35:40 +0530
committerVijay Avuthu <vavuthu@redhat.com>2018-02-09 11:50:54 +0530
commit1817b4b17f07bce549b31abec7d6f3133433bb7b (patch)
tree9724f40aa22f1b583f52191e86c181229ff16266 /glustolibs-misc
parente1b4dd00aea537cfbd2737f3f00f2cbc76ce0ce9 (diff)
Adding are_nodes_offline function
Change-Id: I591c9ca5da52e76b3300c243a5121d27ac89a8f1 Signed-off-by: Vijay Avuthu <vavuthu@redhat.com>
Diffstat (limited to 'glustolibs-misc')
-rw-r--r--glustolibs-misc/glustolibs/misc/misc_libs.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/glustolibs-misc/glustolibs/misc/misc_libs.py b/glustolibs-misc/glustolibs/misc/misc_libs.py
index 33fab9e..f4159ee 100644
--- a/glustolibs-misc/glustolibs/misc/misc_libs.py
+++ b/glustolibs-misc/glustolibs/misc/misc_libs.py
@@ -468,3 +468,39 @@ def reboot_nodes_and_wait_to_come_online(nodes, timeout=300):
g.log.info("All nodes %s are up and running" % node)
return _rc, reboot_results
+
+
+def are_nodes_offline(nodes):
+ """
+ check whether nodes are offline or not
+
+ Args:
+ nodes ( str|list ) : Node/Nodes to check whether offline or not
+
+ Returns:
+ tuple : Tuple containing two elements (ret, node_results).
+ The first element ret is of type 'bool', True if all nodes
+ are offline. False otherwise.
+
+ The second element 'node_results' is of type dictonary and it
+ contains the node and its corresponding result. If node is offline
+ then the result contains True else False.
+ """
+
+ if isinstance(nodes, str):
+ nodes = [nodes]
+
+ node_results = {}
+ for node in nodes:
+ cmd = "ping %s -c1" % node
+ ret, out, err = g.run_local(cmd)
+ if ret:
+ g.log.info("%s is offline" % node)
+ node_results[node] = True
+ else:
+ g.log.info("%s is online" % node)
+ node_results[node] = False
+
+ ret = all(node_results.values())
+
+ return ret, node_results