Add support for creating qcow2 images (#1210413)

(cherry picked from commit 07d5cb176d)

Related: rhbz#1210413
This commit is contained in:
Brian C. Lane 2014-03-07 17:33:18 -08:00
parent 80fcdb4f91
commit 58929b550b

View File

@ -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.'''