Support for vpc format in qemu assembler (fixes #164)
This commit is contained in:
parent
aece548644
commit
459a25bba7
1 changed files with 18 additions and 5 deletions
|
|
@ -32,7 +32,7 @@ STAGE_OPTS = """
|
|||
"format": {
|
||||
"description": "Image file format to use",
|
||||
"type": "string",
|
||||
"enum": ["raw", "qcow2", "vdi", "vmdk"]
|
||||
"enum": ["raw", "qcow2", "vdi", "vmdk", "vpc"]
|
||||
},
|
||||
"filename": {
|
||||
"description": "Image filename",
|
||||
|
|
@ -74,8 +74,8 @@ def main(tree, output_dir, options, loop_client):
|
|||
if size % 512 != 0:
|
||||
raise ValueError("`size` must be a multiple of sector size (512)")
|
||||
|
||||
if fmt not in ["raw", "qcow2", "vdi", "vmdk"]:
|
||||
raise ValueError("`format` must be one of raw, qcow, vdi, vmdk")
|
||||
if fmt not in ["raw", "qcow2", "vdi", "vmdk", "vpc"]:
|
||||
raise ValueError("`format` must be one of raw, qcow, vdi, vmdk, vpc")
|
||||
|
||||
image = "/var/tmp/osbuild-image.raw"
|
||||
grub2_core = "/var/tmp/grub2-core.img"
|
||||
|
|
@ -136,10 +136,23 @@ def main(tree, output_dir, options, loop_client):
|
|||
extra_args = []
|
||||
|
||||
# raw and vdi don't suppport compression
|
||||
if fmt not in ("raw", "vdi"):
|
||||
if fmt not in ("raw", "vdi", "vpc"):
|
||||
extra_args.append("-c")
|
||||
|
||||
subprocess.run(["qemu-img", "convert", "-O", fmt, *extra_args, image, f"{output_dir}/{filename}"], check=True)
|
||||
if fmt != "vpc":
|
||||
subprocess.run(["qemu-img", "convert", "-O", fmt, *extra_args, image, f"{output_dir}/{filename}"], check=True)
|
||||
else:
|
||||
# Implementation of the resize algorithm from here:
|
||||
# https://docs.microsoft.com/en-us/azure/virtual-machines/linux/create-upload-generic
|
||||
mb = 1024*1024
|
||||
rounded_size = int((size/mb + 1) * mb)
|
||||
subprocess.run(["qemu-img", "resize", image, rounded_size], check=True)
|
||||
subprocess.run(["qemu-img", "convert",
|
||||
"-f", "raw",
|
||||
"-o", "subformat=fixed,force_size",
|
||||
"-O", "vpc",
|
||||
image, f"{output_dir}/{filename}"], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = json.load(sys.stdin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue