From ec4720d8fcf1154a8e1e5a2b25d716e46331e0a8 Mon Sep 17 00:00:00 2001 From: Yanks Yoon Date: Tue, 3 Sep 2024 05:49:31 +0000 Subject: [PATCH] Support streaming download of the image This changes adds support for downloading the images in chunked streams. This allows the image download to happen without holding everything in memory which can be an issue with OOM. Change-Id: I2d2c7e5f0d7fbf0d4296a5e2a08d18fcdbe2b143 --- openstack/cloud/_image.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openstack/cloud/_image.py b/openstack/cloud/_image.py index d521c80e9..c5ff08eff 100644 --- a/openstack/cloud/_image.py +++ b/openstack/cloud/_image.py @@ -88,6 +88,7 @@ class ImageCloudMixin(openstackcloud._OpenStackCloudMixin): output_path=None, output_file=None, chunk_size=1024 * 1024, + stream=False, ): """Download an image by name or ID @@ -99,6 +100,7 @@ class ImageCloudMixin(openstackcloud._OpenStackCloudMixin): this or output_path must be specified :param int chunk_size: size in bytes to read from the wire and buffer at one time. Defaults to 1024 * 1024 = 1 MiB + :param: bool stream: whether to stream the output in chunk_size. :returns: When output_path and output_file are not given - the bytes comprising the given Image when stream is False, otherwise a @@ -125,7 +127,10 @@ class ImageCloudMixin(openstackcloud._OpenStackCloudMixin): image = self.image.find_image(name_or_id, ignore_missing=False) return self.image.download_image( - image, output=output_file or output_path, chunk_size=chunk_size + image, + output=output_file or output_path, + chunk_size=chunk_size, + stream=stream, ) def get_image_exclude(self, name_or_id, exclude):