diff options
author | Vijay Avuthu <vavuthu@redhat.com> | 2018-01-31 12:37:55 +0530 |
---|---|---|
committer | Vijay Avuthu <vavuthu@redhat.com> | 2018-01-31 14:36:03 +0530 |
commit | 2f374307ceb6cac8db540115f9a13208256e4542 (patch) | |
tree | 18e49df73c63271f5149c2dd5d4af3c11f3550a4 /glustolibs-misc/glustolibs/misc | |
parent | f696f3911567b65abe70e30e2be3ecf05d47b75d (diff) |
Adding function: are_nodes_online
Description :
Function to check whether given nodes are online or not
Change-Id: I92a40ac1a6bcdbdfb845413902dd0a798c68ed5c
Signed-off-by: Vijay Avuthu <vavuthu@redhat.com>
Diffstat (limited to 'glustolibs-misc/glustolibs/misc')
-rw-r--r-- | glustolibs-misc/glustolibs/misc/misc_libs.py | 36 |
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 62b854c10..c8aba410c 100644 --- a/glustolibs-misc/glustolibs/misc/misc_libs.py +++ b/glustolibs-misc/glustolibs/misc/misc_libs.py @@ -373,3 +373,39 @@ def install_arequal(list_of_nodes): g.log.info("arequal-checksum is installed on nodes: %s" % list_of_nodes) return _rc + + +def are_nodes_online(nodes): + """ + check whether nodes are online or not + + Args: + nodes ( str|list ) : Node/Nodes to check whether online or not + + Returns: + tuple : Tuple containing two elements (ret, node_results). + The first element ret is of type 'bool', True if all nodes + are online. False otherwise. + + The second element 'node_results' is of type dictonary and it + contains the node and its corresponding result. If node is online + 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] = False + else: + g.log.info("%s is online" % node) + node_results[node] = True + + ret = all(node_results.values()) + + return ret, node_results |