[libvirt] [sandbox PATCH 11/11] Image: Add run function

Eren Yagdiran erenyagdiran at gmail.com
Thu Jul 23 15:57:37 UTC 2015


Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py b/virt-sandbox-image/virt-sandbox-image.py
index fd02567..ca17b3b 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -117,6 +117,26 @@ def check_driver(driver):
             raise ValueError("%s is not supported by Virt-sandbox" %driver)
         return True
 
+def run(args):
+    try:
+        check_driver(args.driver)
+        source = dynamic_source_loader(args.source)
+        diskfile,configfile = source.get_disk(name=args.name,path=args.imagepath)
+
+        format = "qcow2"
+        commandToRun = args.command
+        if commandToRun is None:
+            commandToRun = source.get_command(configfile)
+        cmd = ['virt-sandbox',
+               '-c',args.driver,
+               '-m','host-image:/=%s,format=%s' %(diskfile,format),
+               '--',
+               commandToRun]
+        subprocess.call(cmd)
+
+    except Exception,e:
+        print "Run Error %s" % str(e)
+
 def requires_name(parser):
     parser.add_argument("name",
                         help=_("name of the template"))
-- 
2.1.0




More information about the libvir-list mailing list