mclu list: Sort lists of guests when displaying them.
[mclu.git] / mclu_status.py
index 81b9fb0..add55ab 100644 (file)
@@ -18,6 +18,8 @@
 
 import argparse
 
+import ansible.runner
+
 import lib
 
 def cmdline (subparsers):
@@ -27,19 +29,14 @@ def cmdline (subparsers):
     )
     p.set_defaults (run=run)
 
-def run (c, args, nodes):
-    for node_name in sorted (nodes.keys ()):
-        node = nodes[node_name]
-        print "%s (%s)" % (node_name, node.host),
-        if node.ping():
-            print "\tup",
-            if node.ssh_ping():
-                print "\tssh: OK",
-                if node.libvirt_ping():
-                    print "\tlibvirt: OK"
-                else:
-                    print "\tlibvirt: dead"
-            else:
-                print "\tssh: dead"
-        else:
-            print "\tdown"
+def run (c, args):
+    runner = ansible.runner.Runner (
+        remote_user = 'root',
+        module_name = 'ping',
+        pattern = c['nodes_group'],
+    )
+    data = runner.run ()
+    for name in sorted (data['contacted']):
+        print "%s\tup" % name
+    for name in sorted (data['dark']):
+        print "%s\tdown" % name