[libvirt] [PATCH sandbox v5 13/20] Image: Add run function
Cedric Bosdonnat
cbosdonnat at suse.com
Wed Sep 9 12:06:07 UTC 2015
On Tue, 2015-09-08 at 17:29 +0100, Daniel P. Berrange wrote:
> From: Eren Yagdiran <erenyagdiran at gmail.com>
>
> 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 at redhat.com>
> ---
> 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
More information about the libvir-list
mailing list