On Tue, 2015-09-08 at 17:29 +0100, Daniel P. Berrange wrote: > From: Eren Yagdiran <erenyagdiran@xxxxxxxxx> > > Run an already-built template > If there is no execution command specified by user, source.get_command will > find the command to invoke > > Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> > --- > libvirt-sandbox/image/cli.py | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/libvirt-sandbox/image/cli.py b/libvirt-sandbox/image/cli.py > index 2672a20..a06eb9c 100755 > --- a/libvirt-sandbox/image/cli.py > +++ b/libvirt-sandbox/image/cli.py > @@ -31,6 +31,8 @@ import shutil > import sys > import urllib2 > import subprocess > +import random > +import string > > if os.geteuid() == 0: > default_template_dir = "/var/lib/libvirt/templates" > @@ -97,6 +99,37 @@ def create(args): > except Exception,e: > print "Create Error %s" % str(e) > > +def run(args): > + try: > + if args.connect is not None: > + check_connect(args.connect) > + source = dynamic_source_loader(args.source) > + name = args.name > + if name is None: > + randomid = ''.join(random.choice(string.lowercase) for i in range(10)) > + name = args.template + ":" + randomid > + > + diskfile = source.get_disk(templatename=args.template, > + templatedir=args.template_dir, > + imagedir=args.image_dir, > + sandboxname=name) > + > + format = "qcow2" > + commandToRun = source.get_command(args.template, args.template_dir, args.args) > + if len(commandToRun) == 0: > + commandToRun = ["/bin/sh"] > + cmd = ['virt-sandbox', '--name', name] > + if args.connect is not None: > + cmd.append("-c") > + cmd.append(args.connect) > + params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)] > + cmd = cmd + params + ['--'] + commandToRun > + subprocess.call(cmd) > + os.unlink(diskfile) > + > + except Exception,e: > + print "Run Error %s" % str(e) > + > def requires_template(parser): > parser.add_argument("template", > help=_("name of the template")) ACK -- Cedric -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list