diff options
author | Hongbin Lu <hongbin.lu@huawei.com> | 2017-09-10 14:34:51 -0400 |
---|---|---|
committer | Hongbin Lu <hongbin.lu@huawei.com> | 2017-09-10 14:43:33 -0400 |
commit | 35ceefe1f121c8d829173cbc8f18dd5965308073 (patch) | |
tree | 0bdf919d26babed7a79f1afefa716522d9546b6f | |
parent | 37fbc8b4fda62f104d32a87946eb9bdd9e3698ba (diff) | |
download | docker-py-35ceefe1f121c8d829173cbc8f18dd5965308073.tar.gz |
Return Image objects on image.load
In before, image.load returns what Docker API returns, which is
a text stream. This commits propose an improvement for returning
more useful information, which is a list of Image objects being
loaded.
Signed-off-by: Hongbin Lu <hongbin.lu@huawei.com>
-rw-r--r-- | docker/models/images.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/docker/models/images.py b/docker/models/images.py index d1b29ad..89e0e80 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -236,13 +236,24 @@ class ImageCollection(Collection): data (binary): Image data to be loaded. Returns: - (generator): Progress output as JSON objects + (list of :py:class:`Image`): The images. Raises: :py:class:`docker.errors.APIError` If the server returns an error. """ - return self.client.api.load_image(data) + resp = self.client.api.load_image(data) + images = [] + for chunk in resp: + if 'stream' in chunk: + match = re.search( + r'(^Loaded image ID: |^Loaded image: )(.+)$', + chunk['stream'] + ) + if match: + image_id = match.group(2) + images.append(image_id) + return [self.get(i) for i in images] def pull(self, name, tag=None, **kwargs): """ |