diff options
author | Abhishek Kekane <akekane@redhat.com> | 2021-02-18 07:59:29 +0000 |
---|---|---|
committer | Dan Smith <dansmith@redhat.com> | 2021-03-02 10:02:14 -0800 |
commit | e0a35a1150a7afe1e28b8d9b59a9e41951276baa (patch) | |
tree | c6640b52ab3b8f8871ab40be703e4cd59dbf52f8 /glanceclient/v2 | |
parent | e8f427e1088b6de488bfa6af811d62415b073c34 (diff) | |
download | python-glanceclient-e0a35a1150a7afe1e28b8d9b59a9e41951276baa.tar.gz |
Get tasks associated with image
Add support to get tasks associated with specific image.
bp: messages-api
Change-Id: Ia505cf6f47ca6c628e195be3ca5231d22d53040d
Diffstat (limited to 'glanceclient/v2')
-rw-r--r-- | glanceclient/v2/images.py | 19 | ||||
-rw-r--r-- | glanceclient/v2/shell.py | 18 |
2 files changed, 37 insertions, 0 deletions
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index 341485d..b412c42 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -197,6 +197,25 @@ class Controller(object): return self._get(image_id) @utils.add_req_id_to_object() + def get_associated_image_tasks(self, image_id): + """Get the tasks associated with an image. + + :param image_id: ID of the image + :raises: exc.HTTPNotImplemented if Glance is not new enough to support + this API (v2.12). + """ + # NOTE (abhishekk): Verify that /v2i/images/%s/tasks is supported by + # glance + if utils.has_version(self.http_client, 'v2.12'): + url = '/v2/images/%s/tasks' % image_id + resp, body = self.http_client.get(url) + body.pop('self', None) + return body, resp + else: + raise exc.HTTPNotImplemented( + 'This operation is not supported by Glance.') + + @utils.add_req_id_to_object() def data(self, image_id, do_checksum=True, allow_md5_fallback=False): """Retrieve data of an image. diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 592b2da..c38d046 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -468,6 +468,24 @@ def do_image_show(gc, args): utils.print_image(image, args.human_readable, int(args.max_column_width)) +@utils.arg('id', metavar='<IMAGE_ID>', help=_('ID of image to get tasks.')) +def do_image_tasks(gc, args): + """Get tasks associated with image""" + columns = ['Message', 'Status', 'Updated at'] + if args.verbose: + columns_to_prepend = ['Image Id', 'Task Id'] + columns_to_extend = ['User Id', 'Request Id', + 'Result', 'Owner', 'Input', 'Expires at'] + columns = columns_to_prepend + columns + columns_to_extend + try: + tasks = gc.images.get_associated_image_tasks(args.id) + utils.print_dict_list(tasks['tasks'], columns) + except exc.HTTPNotFound: + utils.exit('Image %s not found.' % args.id) + except exc.HTTPNotImplemented: + utils.exit('Server does not support image tasks API (v2.12)') + + @utils.arg('--image-id', metavar='<IMAGE_ID>', required=True, help=_('Image to display members of.')) def do_member_list(gc, args): |