# HG changeset patch
# User Cole Robinson <crobinso@redhat.com>
# Date 1253112830 14400
# Node ID 6a398359952bfd8cc62e36afc26bb470862ce42d
# Parent 252ff7bc5ff9e95f49dd7deb6ef6af07287a5055
virt-install: Add 'format' option to --disk
Allows specifying storage volume format (raw, qcow2, etc.).
diff -r 252ff7bc5ff9 -r 6a398359952b man/en/virt-install.1
--- a/man/en/virt-install.1 Sun Sep 13 18:20:15 2009 -0400
+++ b/man/en/virt-install.1 Wed Sep 16 10:53:50 2009 -0400
@@ -659,6 +659,11 @@
The cache value can be 'none', 'writethrough', or 'writeback'.
\&'writethrough' provides read caching. 'writeback' provides
read and write caching.
+.IP "\fBformat\fR" 4
+.IX Item "format"
+Image format to be used if creating managed storage. For file volumes, this
+can be 'raw', 'qcow2', 'vmdk', etc. See format types in
+<http://libvirt.org/storage.html> for possible values.
.RE
.RS 2
.Sp
diff -r 252ff7bc5ff9 -r 6a398359952b man/en/virt-install.pod.in
--- a/man/en/virt-install.pod.in Sun Sep 13 18:20:15 2009 -0400
+++ b/man/en/virt-install.pod.in Wed Sep 16 10:53:50 2009 -0400
@@ -435,6 +435,12 @@
'writethrough' provides read caching. 'writeback' provides
read and write caching.
+=item B<format>
+
+Image format to be used if creating managed storage. For file volumes, this
+can be 'raw', 'qcow2', 'vmdk', etc. See format types in
+L<http://libvirt.org/storage.html> for possible values.
+
=back
See the examples section for some uses. This option deprecates C<--file>,
diff -r 252ff7bc5ff9 -r 6a398359952b tests/clitest.py
--- a/tests/clitest.py Sun Sep 13 18:20:15 2009 -0400
+++ b/tests/clitest.py Wed Sep 16 10:53:50 2009 -0400
@@ -62,6 +62,7 @@
'MANAGEDEXIST2' : "/default-pool/testvol2.img",
'MANAGEDNEW1' : "/default-pool/clonevol",
'MANAGEDNEW2' : "/default-pool/clonevol",
+ 'MANAGEDDISKNEW1' : "/disk-pool/newvol1.img",
}
debug = False
@@ -130,6 +131,12 @@
"--disk path=%(EXISTIMG1)s --disk path=%(EXISTIMG1)s --disk path=%(EXISTIMG1)s --disk path=%(EXISTIMG1)s,device=cdrom",
# > 16 scsi disks
" --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi --disk path=%(EXISTIMG1)s,bus=scsi",
+ # Unmanaged file using format 'raw'
+ "--disk path=%(NEWIMG1)s,format=raw,size=.0000001",
+ # Managed file using format raw
+ "--disk path=%(MANAGEDNEW1)s,format=raw,size=.0000001",
+ # Managed file using format qcow2
+ "--disk path=%(MANAGEDNEW1)s,format=qcow2,size=.0000001",
],
"invalid": [
@@ -153,6 +160,12 @@
"--disk pool=%(POOL)s",
# Unknown cache type
"--disk path=%(EXISTIMG1)s,perms=ro,size=.0001,cache=FOOBAR",
+ # Unmanaged file using non-raw format
+ "--disk path=%(NEWIMG1)s,format=qcow2,size=.0000001",
+ # Managed file using unknown format
+ "--disk path=%(MANAGEDNEW1)s,format=frob,size=.0000001",
+ # Managed disk using any format
+ "--disk path=%(MANAGEDDISKNEW1)s,format=raw,size=.0000001",
]
}, # category "storage"
diff -r 252ff7bc5ff9 -r 6a398359952b virt-install
--- a/virt-install Sun Sep 13 18:20:15 2009 -0400
+++ b/virt-install Wed Sep 16 10:53:50 2009 -0400
@@ -156,7 +156,8 @@
ro = False
shared = False
sparse = True
- option_whitelist = ["perms", "cache", "bus", "device", "size", "sparse"]
+ option_whitelist = ["perms", "cache", "bus", "device", "size", "sparse",
+ "format"]
# Strip media type
path, ignore, optstr = partition(path, ",")
@@ -200,6 +201,7 @@
devtype = opts.get("device")
bus = opts.get("bus")
cache = opts.get("cache")
+ fmt = opts.get("format")
# We return (path, (poolname, volname), volinst, device, bus, readonly,
# shared)
@@ -220,6 +222,8 @@
suffix=".img")
volinst = vc(pool_name=path, name=vname, conn=guest.conn,
allocation=0, capacity=(size and size*1024*1024*1024))
+ if fmt:
+ volinst.format = fmt
elif path_type == "vol=":
if not path.count("/"):
@@ -235,7 +239,7 @@
if not devtype:
devtype = virtinst.VirtualDisk.DEVICE_DISK
ret = (abspath, voltuple, volinst, devtype, bus, ro, shared, size, sparse,
- cache)
+ cache, fmt)
logging.debug("parse_disk: returning %s" % str(ret))
return ret
@@ -252,13 +256,13 @@
# Get disk parameters
if is_file_path:
(path, voltuple, volinst, device, bus, readOnly, shared, size,
- sparse, cache) = \
+ sparse, cache, fmt) = \
(disk, None, None, virtinst.VirtualDisk.DEVICE_DISK, None, False,
- False, size, sparse, None)
+ False, size, sparse, None, None)
else:
(path, voltuple, volinst,
device, bus, readOnly, shared,
- size, sparse, cache) = parse_disk_option(guest, disk, size)
+ size, sparse, cache, fmt) = parse_disk_option(guest, disk, size)
if not sparse and volinst:
volinst.allocation = volinst.capacity
@@ -266,7 +270,7 @@
'volInstall': volinst, 'volName': voltuple,
'readOnly': readOnly, 'shareable': shared,
'device': device, 'bus': bus, 'conn': guest.conn,
- 'driverCache': cache}
+ 'driverCache': cache, 'format': fmt}
d = cli.disk_prompt(None, kwargs)
diff -r 252ff7bc5ff9 -r 6a398359952b virtinst/VirtualDisk.py
--- a/virtinst/VirtualDisk.py Sun Sep 13 18:20:15 2009 -0400
+++ b/virtinst/VirtualDisk.py Wed Sep 16 10:53:50 2009 -0400
@@ -146,7 +146,7 @@
device=DEVICE_DISK, driverName=None, driverType=None,
readOnly=False, sparse=True, conn=None, volObject=None,
volInstall=None, volName=None, bus=None, shareable=False,
- driverCache=None, selinuxLabel=None):
+ driverCache=None, selinuxLabel=None, format=None):
"""
@param path: filesystem path to the disk image.
@type path: C{str}
@@ -183,6 +183,8 @@
@type driverCache: member of cache_types
@param selinuxLabel: Used for labelling new or relabel existing storage
@type selinuxLabel: C{str}
+ @param format: Storage volume format to use when creating storage
+ @type format: C{str}
"""
VirtualDevice.__init__(self, conn=conn)
@@ -200,6 +202,7 @@
self._driver_cache = None
self._selinux_label = None
self._clone_path = None
+ self._format = None
# XXX: No property methods for these
self.transient = transient
@@ -219,6 +222,7 @@
self._set_shareable(shareable, validate=False)
self._set_driver_cache(driverCache, validate=False)
self._set_selinux_label(selinuxLabel, validate=False)
+ self._set_format(format, validate=False)
if volName:
self.__lookup_vol_name(volName)
@@ -375,6 +379,14 @@
self.__validate_wrapper("_selinux_label", val, validate)
selinux_label = property(_get_selinux_label, _set_selinux_label)
+ def _get_format(self):
+ return self._format
+ def _set_format(self, val, validate=True):
+ if val is not None:
+ self._check_str(val, "format")
+ self.__validate_wrapper("_format", val, validate)
+ format = property(_get_format, _set_format)
+
# Validation assistance methods
# Initializes attribute if it hasn't been done, then validates args.
@@ -392,6 +404,24 @@
setattr(self, varname, orig)
raise
+ def __set_format(self):
+ if not self.format:
+ return
+
+ if not self.__creating_storage():
+ return
+
+ if self.vol_install:
+ if not hasattr(self.vol_install, "format"):
+ raise ValueError(_("Storage type does not support format "
+ "parameter."))
+ if self.vol_install.format != self.format:
+ self.vol_install.format = self.format
+
+ elif self.format != "raw":
+ raise RuntimeError(_("Format cannot be specified for "
+ "unmanaged storage."))
+
def __set_size(self):
"""
Fill in 'size' attribute for existing storage.
@@ -700,6 +730,7 @@
create_media = self.__creating_storage()
self.__set_size()
+ self.__set_format()
if not self.selinux_label:
# If we are using existing storage, pull the label from it