From 666976ab05dfefaefb41a6fa41024084c1045028 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 20 Oct 2022 12:18:36 +0100 Subject: [PATCH] image: Allow providing 'data' argument to image upload, stage This feels a little more natural that setting an attribute on the object first. Change-Id: I11fd4847152b4df6229e82d9953bc7567611628c Signed-off-by: Stephen Finucane --- openstack/image/v2/image.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/openstack/image/v2/image.py b/openstack/image/v2/image.py index 7a941f082..5a79c9c1c 100644 --- a/openstack/image/v2/image.py +++ b/openstack/image/v2/image.py @@ -264,15 +264,32 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin): """ self._action(session, "reactivate") - def upload(self, session): - """Upload data into an existing image""" + def upload(self, session, *, data=None): + """Upload data into an existing image + + :param session: The session to use for making this request + :param data: Optional data to be uploaded. If not provided, the + `~Image.data` attribute will be used + :returns: The server response + """ + if data: + self.data = data url = utils.urljoin(self.base_path, self.id, 'file') return session.put(url, data=self.data, headers={"Content-Type": "application/octet-stream", "Accept": ""}) - def stage(self, session): - """Stage binary image data into an existing image""" + def stage(self, session, *, data=None): + """Stage binary image data into an existing image + + :param session: The session to use for making this request + :param data: Optional data to be uploaded. If not provided, the + `~Image.data` attribute will be used + :returns: The server response + """ + if data: + self.data = data + url = utils.urljoin(self.base_path, self.id, 'stage') response = session.put( url, data=self.data,