Fix uploading of non-raw image files

Adds a new API query parameter to define the file size, which is then
used for the temporary image. This is required for, at least VMDK, files
to work properly in qemu-img convert.
This commit is contained in:
2023-09-29 16:13:08 -04:00
parent ad2e7750ff
commit 35e27f79ef
4 changed files with 50 additions and 9 deletions

View File

@ -3598,7 +3598,7 @@ def cli_storage_volume_upload(pool, name, image_format, image_file):
If the image format is "raw", the image is uploaded directly to the target volume without modification. Otherwise, it will be converted into raw format by "qemu-img convert" on the remote side before writing using a temporary volume. The image format must be a valid format recognized by "qemu-img", such as "vmdk" or "qcow2".
"""
if not os.path.exists(image_file):
if not path.exists(image_file):
echo(CLI_CONFIG, "ERROR: File '{}' does not exist!".format(image_file))
exit(1)
@ -4910,13 +4910,13 @@ def cli_provisioner_ova_upload(name, filename, pool):
Storage templates, provisioning scripts, and arguments for OVA-type profiles will be ignored and should not be set.
"""
if not os.path.exists(filename):
if not path.exists(filename):
echo(CLI_CONFIG, "ERROR: File '{}' does not exist!".format(filename))
exit(1)
params = dict()
params["pool"] = pool
params["ova_size"] = os.path.getsize(filename)
params["ova_size"] = path.getsize(filename)
retcode, retdata = pvc.lib.provisioner.ova_upload(
CLI_CONFIG, name, filename, params

View File

@ -21,6 +21,7 @@
import math
from os import path
from json import loads
from requests_toolbelt.multipart.encoder import (
MultipartEncoder,
@ -1209,6 +1210,11 @@ def ceph_volume_upload(config, pool, volume, image_format, image_file):
"""
import click
if image_format != "raw":
file_size = path.getsize(image_file)
else:
file_size = None
bar = UploadProgressBar(
image_file, end_message="Parsing file on remote side...", end_nl=False
)
@ -1220,7 +1226,7 @@ def ceph_volume_upload(config, pool, volume, image_format, image_file):
upload_monitor = MultipartEncoderMonitor(upload_data, bar.update)
headers = {"Content-Type": upload_monitor.content_type}
params = {"image_format": image_format}
params = {"image_format": image_format, "file_size": file_size}
response = call_api(
config,