mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2024-07-04 11:22:56 -05:00
Add support for qemu-img v8 to create_box.sh (#1790)
Since version 8 of qemu-img tool it produces more verbose JSON-output with multiple `virtual-size` keys which leads to incorrect generation of `metadata.json` file (all values of `virtual-size` are placed into file and it becomes non-valid JSON). This behavious was described in #1746 . Example of old JSON output: { "virtual-size": 34359738368, "filename": "vm-100-disk-0.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 2941440, "format-specific": { "type": "qcow2", "data": { "compat": "1.1", "compression-type": "zlib", "lazy-refcounts": false, "refcount-bits": 16, "corrupt": false, "extended-l2": false } }, "dirty-flag": false } Example of new JSON output: { "children": [ { "name": "file", "info": { "children": [ ], "virtual-size": 42956488704, "filename": "/var/lib/libvirt/images/proxmox_6.4.qcow2", "format": "file", "actual-size": 1305301504, "format-specific": { "type": "file", "data": { } }, "dirty-flag": false } } ], "virtual-size": 42949672960, "filename": "/var/lib/libvirt/images/proxmox_6.4.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 1305301504, "format-specific": { "type": "qcow2", "data": { "compat": "1.1", "compression-type": "zlib", "lazy-refcounts": true, "refcount-bits": 16, "corrupt": false, "extended-l2": false } }, "dirty-flag": false } This change adds comatibility in a fast-fix-way: awk regex gets in account only `virtual-size` key on the first level of `qemu-img info` JSON-output.
This commit is contained in:
parent
cf37fd44f6
commit
a94ce0d7b6
|
@ -91,8 +91,10 @@ cd "$TMP_DIR"
|
|||
|
||||
#Using the awk int function here to truncate the virtual image size to an
|
||||
#integer since the fog-libvirt library does not seem to properly handle
|
||||
#floating point.
|
||||
IMG_SIZE=$(qemu-img info --output=json "$TMP_IMG" | awk '/virtual-size/{s=int($2)/(1024^3); print (s == int(s)) ? s : int(s)+1 }')
|
||||
#floating point. Regex in awk function takes in account only "virtual-size"
|
||||
#value on the first level of JSON (since QEMU v8 there are multiple
|
||||
#"virtual-size"s in disk info).
|
||||
IMG_SIZE=$(qemu-img info --output=json "$TMP_IMG" | awk '/^\s{0,4}"virtual-size/{s=int($2)/(1024^3); print (s == int(s)) ? s : int(s)+1 }')
|
||||
|
||||
echo "{$IMG_SIZE}"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user