[et-mgmt-tools] [PATCH 08 of 11] Allow specification of output disk format
john.levon at sun.com
john.levon at sun.com
Mon Jul 7 22:51:38 UTC 2008
# HG changeset patch
# User john.levon at sun.com
# Date 1215470441 25200
# Node ID 9d9b282172f77f9d77035017bb0bc8e219be18ba
# Parent 20daa7230dc53978e5f67fabf7950d961ed3bdd8
Allow specification of output disk format
In particular, allow the disk conversion to be skipped.
Signed-off-by: John Levon <john.levon at sun.com>
diff --git a/man/en/virt-convert.1 b/man/en/virt-convert.1
--- a/man/en/virt-convert.1
+++ b/man/en/virt-convert.1
@@ -176,6 +176,10 @@ Input format. Currently, \f(CW\*(C`vmx\*
.IX Item "-o format"
Output format. Currently, the only supported outputs are \f(CW\*(C`virt\-image\*(C'\fR
and \f(CW\*(C`virt\-instance\*(C'\fR.
+.IP "\-D format" 4
+.IX Item "-D format"
+Output disk format, or \f(CW\*(C`none\*(C'\fR if no conversion should be performed. See
+\&\fIqemu\-img\fR\|(1).
.IP "\-d, \-\-debug" 4
.IX Item "-d, --debug"
Print debugging information
@@ -197,7 +201,7 @@ Convert a 64\-bit hvm guest:
.Ve
.SH "AUTHOR"
.IX Header "AUTHOR"
-Written by Joey Boggs
+Written by Joey Boggs and John Levon
.PP
See the \s-1AUTHORS\s0 file in the source distribution for the complete list of credits.
.SH "BUGS"
diff --git a/man/en/virt-convert.pod b/man/en/virt-convert.pod
--- a/man/en/virt-convert.pod
+++ b/man/en/virt-convert.pod
@@ -59,6 +59,11 @@ Output format. Currently, the only suppo
Output format. Currently, the only supported outputs are C<virt-image>
and C<virt-instance>.
+=item -D format
+
+Output disk format, or C<none> if no conversion should be performed. See
+L<qemu-img(1)>.
+
=item -d, --debug
Print debugging information
@@ -81,7 +86,7 @@ Convert a 64-bit hvm guest:
=head1 AUTHOR
-Written by Joey Boggs
+Written by Joey Boggs and John Levon
See the AUTHORS file in the source distribution for the complete list of credits.
diff --git a/virt-convert b/virt-convert
--- a/virt-convert
+++ b/virt-convert
@@ -30,7 +30,6 @@
# support CD-ROM
# add option for host selection
# --uuid, --os-type, --os-variant, and other virt-install options
-# disk conversion should be optional
# use qemu-img info to verify the disk type
# add some unit tests
# input/output/detection for all formats
@@ -41,6 +40,7 @@ import os
import os
import logging
import errno
+import platform
from optparse import OptionParser
import virtinst.cli as cli
@@ -67,6 +67,8 @@ def parse_args():
opts.add_option("-o", "--output-format", action="store",
dest="output_format", default="virt-image",
help=("Output format, e.g. 'virt-image'"))
+ opts.add_option("-D", "--disk-format", action="store",
+ dest="disk_format", help=("Output disk format"))
opts.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
help=("This guest should be a fully virtualized guest"))
opts.add_option("-p", "--paravirt", action="store_true", dest="paravirt",
@@ -78,6 +80,10 @@ def parse_args():
if len(args) > 2:
opts.error(("Too many arguments provided"))
+ if (options.disk_format and
+ options.disk_format not in vmconfig.disk_formats()):
+ opts.error("Unknown output disk format \"%s\"" % options.disk_format)
+
if len(args) == 1:
options.output_file = None
options.output_dir = None
@@ -210,11 +216,23 @@ def main():
(options.output_format, options.output_dir))
try:
- for d in vmdef.disks:
+ for d in vmdef.disks.values():
+ format = options.disk_format
+
+ if format == "none":
+ continue
+
+ # no auto-conversion on Solaris for VMDK disks
+ if (d.format == vmconfig.DISK_FORMAT_VMDK and
+ not format and platform.system() == "SunOS"):
+ continue
+
+ if not format:
+ format = "raw"
verbose(options, "Converting disk \"%s\" to type %s..." %
- (d.path, vmconfig.qemu_formats[vmconfig.DISK_FORMAT_RAW]))
- d.convert(options.input_dir, options.output_dir,
- vmconfig.DISK_FORMAT_RAW)
+ (d.path, format))
+
+ d.convert(options.input_dir, options.output_dir, format)
except OSError, e:
cleanup("Couldn't convert disks: %s" % e.strerror, options, created_dir)
except RuntimeError, e:
diff --git a/virtconv/vmconfig.py b/virtconv/vmconfig.py
--- a/virtconv/vmconfig.py
+++ b/virtconv/vmconfig.py
@@ -30,8 +30,9 @@ NETDEV_TYPE_BRIDGE = 2
NETDEV_TYPE_BRIDGE = 2
NETDEV_TYPE_NETWORK = 3
-DISK_FORMAT_RAW = 0
-DISK_FORMAT_VMDK = 1
+DISK_FORMAT_NONE = 0
+DISK_FORMAT_RAW = 1
+DISK_FORMAT_VMDK = 2
DISK_TYPE_DISK = 0
DISK_TYPE_CDROM = 1
@@ -45,6 +46,12 @@ qemu_formats = {
qemu_formats = {
DISK_FORMAT_RAW: "raw",
DISK_FORMAT_VMDK: "vmdk",
+}
+
+disk_format_names = {
+ "none": DISK_FORMAT_NONE,
+ "raw": DISK_FORMAT_RAW,
+ "vmdk": DISK_FORMAT_VMDK,
}
class disk(object):
@@ -64,14 +71,16 @@ class disk(object):
failures.
"""
- if self.format == output_format:
+ out_format = disk_format_names[output_format]
+
+ if self.format == out_format or out_format == DISK_FORMAT_NONE:
return
if self.type != DISK_TYPE_DISK:
return
- if output_format != DISK_FORMAT_RAW:
- raise NotImplementedError("Cannot convert to disk format %d" %
+ if out_format != DISK_FORMAT_RAW:
+ raise NotImplementedError("Cannot convert to disk format %s" %
output_format)
infile = self.path
@@ -85,10 +94,10 @@ class disk(object):
outfile = os.path.basename(outfile)
outfile = outfile.replace(disk_suffixes[self.format],
- disk_suffixes[output_format]).strip()
+ disk_suffixes[out_format]).strip()
convert_cmd = ("qemu-img convert \"%s\" -O %s \"%s\"" %
- (infile, qemu_formats[output_format],
+ (infile, qemu_formats[out_format],
os.path.join(output_dir, outfile)))
ret = os.system(convert_cmd)
@@ -97,7 +106,7 @@ class disk(object):
# Note: this is the *relative* path still
self.path = outfile
- self.format = output_format
+ self.format = out_format
class netdev(object):
"""Definition of an individual network device."""
@@ -247,6 +256,12 @@ def output_formats():
"""
return [p.name for p in _parsers if p.can_export]
+def disk_formats():
+ """
+ Return a list of supported disk formats.
+ """
+ return disk_format_names.keys()
+
def find_input(path, format = None):
"""
Search for a configuration file automatically. If @format is given,
More information about the et-mgmt-tools
mailing list