build/import: Add --no-start flag.
[mclu.git] / mclu_stop.py
index bd7f116..883b67a 100644 (file)
@@ -18,6 +18,8 @@
 
 import argparse
 import fnmatch
+import subprocess
+
 import libvirt
 
 import lib
@@ -37,18 +39,22 @@ def cmdline (subparsers):
     )
     p.set_defaults (run=run)
 
-def run (c, args, nodes):
-    running, _ = lib.get_all_guests (c, nodes.values ())
+def run (c, args):
+    running, _ = lib.get_all_guests (c)
 
     for vm in running.values():
-        node = vm['node']
-        dom = vm['dom']
+        node_name = vm['node']
+        vm_name = vm['vm']
         # Form the name of this VM (eg. "ham0:vm") so we can match it
         # against the wildcards (eg. "ham0:*")
-        name = node.name + ":" + dom.name()
+        name = node_name + ":" + vm_name
         for wc in args.wildcards:
-            if fnmatch.fnmatch (name, wc) or fnmatch.fnmatch (dom.name(), wc):
+            if fnmatch.fnmatch (name, wc) or fnmatch.fnmatch (vm_name, wc):
                 if args.force:
-                    dom.destroy()
+                    subprocess.check_call (["virsh",
+                                            "-c", lib.uri_of_node (node_name),
+                                            "destroy", vm_name])
                 else:
-                    dom.shutdown()
+                    subprocess.check_call (["virsh",
+                                            "-c", lib.uri_of_node (node_name),
+                                            "shutdown", vm_name])