Commit 45f63dc3 authored by Guido Günther's avatar Guido Günther

Sanitize domain name

If one pastes from the output of virt-sansbox-image

  $ virt-sandbox-image list
  docker:/library/ubuntu?tag=17.04
  docker:/library/debian?tag=latest

verbatim

  $ virt-sandbox-image run -c qemu:///session docker:/library/debian?tag=latest

This fails like

  Unable to start sandbox: Failed to create domain: XML error: name library/debian:qbeilwxard cannot contain '/'

so don't allow invalid chars like '/' in domain names
Signed-off-by: Guido Günther's avatarGuido Günther <agx@sigxcpu.org>
Reviewed-by: 's avatarDaniel P. Berrange <berrange@redhat.com>
parent 7280c2ee
......@@ -27,6 +27,7 @@ import hashlib
import json
import os
import os.path
import re
import shutil
import sys
import urllib2
......@@ -81,6 +82,10 @@ def prepare(args):
templatedir=get_template_dir(args),
connect=args.connect)
def random_domain_name(tmpl):
randomid = ''.join(random.choice(string.lowercase) for i in range(10))
return re.sub('[^a-z0-9-]', '_', tmpl.path[1:], re.I) + ":" + randomid
def run(args):
if args.connect is not None:
check_connect(args.connect)
......@@ -95,8 +100,7 @@ def run(args):
name = args.name
if name is None:
randomid = ''.join(random.choice(string.lowercase) for i in range(10))
name = tmpl.path[1:] + ":" + randomid
name = random_domain_name(tmpl)
diskfile = source.get_disk(template=tmpl,
templatedir=template_dir,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment