From 58929b550bf0188e225cbce8296337d0e47dcc13 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 7 Mar 2014 17:33:18 -0800 Subject: [PATCH] Add support for creating qcow2 images (#1210413) (cherry picked from commit 07d5cb176d5bb6c909036e5963d14afdb2918038) Related: rhbz#1210413 --- src/pylorax/imgutils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py index 9aec894f..e93ee0d5 100644 --- a/src/pylorax/imgutils.py +++ b/src/pylorax/imgutils.py @@ -113,6 +113,18 @@ def mksparse(outfile, size): fobj = open(outfile, "w") os.ftruncate(fobj.fileno(), size) +def mkqcow2(outfile, size, options=None): + '''use qemu-img to create a file of the given size. + options is a list of options passed to qemu-img + + Default format is qcow2, override by passing "-f", fmt + in options. + ''' + options = options or [] + if "-f" not in options: + options.extend(["-f", "qcow2"]) + runcmd(["qemu-img", "create"] + options + [outfile, str(size)]) + def loop_attach(outfile): '''Attach a loop device to the given file. Return the loop device name. Raises CalledProcessError if losetup fails.'''