cli: Add simple mode --disk size=X

Works the same as pool=default, we generate a disk image path and
create it in the default pool.
This commit is contained in:
Cole Robinson 2014-02-10 18:32:57 -05:00
parent 7bff99f853
commit cdd9dbe7fc
3 changed files with 15 additions and 7 deletions

View File

@ -473,9 +473,13 @@ general format of a disk string is
--disk opt1=val1,opt2=val2,...
To specify media, the command can either be:
The simplest invocation to create a new 10G disk image and associated disk device:
--disk /some/storage/path,opt1=val1
--disk size=10
virt-install will generate a path name, and place it in the default image location for the hypervisor. To specify media, the command can either be:
--disk /some/storage/path[,opt1=val1]...
or explicitly specify one of the following arguments:
@ -1422,7 +1426,7 @@ CDROM drive, auto launching a graphical VNC viewer
--virt-type kvm \
--name demo \
--memory 500 \
--disk path=/var/lib/libvirt/images/demo.img,size=8 \
--disk size=8 \
--graphics vnc \
--cdrom /dev/cdrom \
--os-variant fedora13

View File

@ -653,6 +653,7 @@ c = vinst.add_category("remote", "--connect %(REMOTEURI)s --nographics --noautoc
c.add_valid("--nodisks --pxe") # Simple pxe nodisks
c.add_valid("--pxe --disk vol=%(POOL)s/%(VOL)s") # Using existing managed storage 2
c.add_valid("--pxe --disk pool=%(POOL)s,size=.04") # Creating storage on managed pool
c.add_valid("--pxe --disk size=.04") # Creating storage on implied pool=default
c.add_valid("--pxe --disk /foo/bar/baz,size=.01") # Creating any random path on the remote host
c.add_valid("--pxe --disk /dev/zde") # /dev file that we just pass through to the remote VM
c.add_invalid("--pxe --disk /foo/bar/baz") # File that doesn't exist after auto storage setup
@ -707,7 +708,6 @@ c.add_invalid("--file %(NEWIMG1)s --file-size 100000 --nonsparse") # Nonexistin
c.add_invalid("--file %(NEWIMG1)s --file-size 100000") # Huge file, sparse, but no prompting
c.add_invalid("--file %(NEWIMG1)s") # Nonexisting file, no size
c.add_invalid("--file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s") # Too many IDE
c.add_invalid("--file-size .0001") # Size, no file
c.add_invalid("--disk pool=foopool,size=.0001") # Specify a nonexistent pool
c.add_invalid("--disk vol=%(POOL)s/foovol") # Specify a nonexistent volume
c.add_invalid("--disk pool=%(POOL)s") # Specify a pool with no size

View File

@ -806,8 +806,8 @@ def add_disk_option(stog, editexample=False):
editmsg += "\n--disk cache= (unset cache)"
stog.add_argument("--disk", action="append",
help=_("Specify storage with various options. Ex.\n"
"--disk path=/my/existing/disk\n"
"--disk path=/my/new/disk,size=5 (in gigabytes)\n"
"--disk size=10 (new 10GB image in default location)\n"
"--disk path=/my/existing/disk,cache=none\n"
"--disk device=cdrom,bus=scsi\n"
"--disk=?") + editmsg)
@ -1528,8 +1528,12 @@ def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
volobj = None
# Strip media type
if sum([bool(p) for p in [path, pool, vol]]) > 1:
optcount = sum([bool(p) for p in [path, pool, vol]])
if optcount > 1:
fail(_("Cannot specify more than 1 storage path"))
if optcount == 0 and size:
# Saw something like --disk size=X, have it imply pool=default
pool = "default"
if path:
abspath = os.path.abspath(path)