summaryrefslogtreecommitdiff
path: root/openstackclient/image
diff options
context:
space:
mode:
authorSimon Merrick <simonmerrick@catalyst.net.nz>2020-11-19 20:05:54 +1300
committerSimon Merrick <simonmerrick@catalyst.net.nz>2020-11-25 21:25:22 +1300
commit5bdcd590ecacbc0aa8db2cbafa0ab1a9f3c28ce0 (patch)
tree4d6fd5fddc9247cf89f0eaf2e74387f6018e686f /openstackclient/image
parent7146deef00d6a91e3c588acc8fc614e5597b3f76 (diff)
downloadpython-openstackclient-5bdcd590ecacbc0aa8db2cbafa0ab1a9f3c28ce0.tar.gz
stop image downloads to memory
+ Fixes issue with large images hogging memory + stream image downloads + output to stdout if file not specified Change-Id: Ia01ff9b21a2dac5d0ccf2bd58a8640e88c5cbb36 Story: 2007672 Task: 39776
Diffstat (limited to 'openstackclient/image')
-rw-r--r--openstackclient/image/v1/image.py6
-rw-r--r--openstackclient/image/v2/image.py6
2 files changed, 10 insertions, 2 deletions
diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py
index cf1d6817..64aa3fcd 100644
--- a/openstackclient/image/v1/image.py
+++ b/openstackclient/image/v1/image.py
@@ -478,7 +478,11 @@ class SaveImage(command.Command):
image_client = self.app.client_manager.image
image = image_client.find_image(parsed_args.image)
- image_client.download_image(image.id, output=parsed_args.file)
+ output_file = parsed_args.file
+ if output_file is None:
+ output_file = getattr(sys.stdout, "buffer", sys.stdout)
+
+ image_client.download_image(image.id, stream=True, output=output_file)
class SetImage(command.Command):
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 4f3e9d0b..58d92f51 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -803,7 +803,11 @@ class SaveImage(command.Command):
image_client = self.app.client_manager.image
image = image_client.find_image(parsed_args.image)
- image_client.download_image(image.id, output=parsed_args.file)
+ output_file = parsed_args.file
+ if output_file is None:
+ output_file = getattr(sys.stdout, "buffer", sys.stdout)
+
+ image_client.download_image(image.id, stream=True, output=output_file)
class SetImage(command.Command):