From 54a871f60e3d6928726355985f91c9870a4037b4 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 13 May 2018 19:10:40 +0000 Subject: [PATCH] Add 'host' parameter to image API Require users to input the 'host' parameter when pulling and deleting image because this is a mandatory parameter in server side. Depends-On: Ie2edde77b7444e1025559b1aa1d67c9c8782620f Change-Id: If0586243392481535c657f0a88393d53e0b3c051 Implements: blueprint rework-image-api --- zunclient/osc/v1/images.py | 24 ++++++++++++++++++------ zunclient/v1/images.py | 6 +++--- zunclient/v1/images_shell.py | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/zunclient/osc/v1/images.py b/zunclient/osc/v1/images.py index 4af97886..803dd0d8 100644 --- a/zunclient/osc/v1/images.py +++ b/zunclient/osc/v1/images.py @@ -16,6 +16,7 @@ from osc_lib.command import command from osc_lib import utils from zunclient.common import utils as zun_utils +from zunclient.i18n import _ def _image_columns(image): @@ -71,7 +72,7 @@ class ListImage(command.Lister): class PullImage(command.ShowOne): - """Pull specified image""" + """Pull specified image into a host""" log = logging.getLogger(__name__ + ".PullImage") @@ -81,12 +82,17 @@ class PullImage(command.ShowOne): 'image', metavar='', help='Name of the image') + parser.add_argument( + 'host', + metavar='', + help='Name or UUID of the host') return parser def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['repo'] = parsed_args.image + opts['host'] = parsed_args.host image = client.images.create(**opts) columns = _image_columns(image) return columns, utils.get_item_properties(image, columns) @@ -150,7 +156,7 @@ class ShowImage(command.ShowOne): class DeleteImage(command.Command): - """Delete specified image""" + """Delete specified image from a host""" log = logging.getLogger(__name__ + ".DeleteImage") @@ -160,15 +166,21 @@ class DeleteImage(command.Command): 'uuid', metavar='', help='UUID of image to describe') + parser.add_argument( + 'host', + metavar='', + help='Name or UUID of the host') return parser def take_action(self, parsed_args): client = _get_client(self, parsed_args) - img_id = parsed_args.uuid + opts = {} + opts['image_id'] = parsed_args.uuid + opts['host'] = parsed_args.host try: - client.images.delete(img_id) + client.images.delete(**opts) print(_('Request to delete image %s has been accepted.') - % img_id) + % opts['image_id']) except Exception as e: print("Delete for image %(image)s failed: %(e)s" % - {'image': img_id, 'e': e}) + {'image': opts['image_id'], 'e': e}) diff --git a/zunclient/v1/images.py b/zunclient/v1/images.py index a6066d1e..3504ea49 100644 --- a/zunclient/v1/images.py +++ b/zunclient/v1/images.py @@ -15,7 +15,7 @@ from zunclient.common import utils from zunclient import exceptions -PULL_ATTRIBUTES = ['repo'] +PULL_ATTRIBUTES = ['repo', 'host'] IMAGE_SEARCH_ATTRIBUTES = ['image', 'image_driver', 'exact_match'] @@ -96,12 +96,12 @@ class ImageManager(base.Manager): "Key must be in %s" % ','.join(PULL_ATTRIBUTES)) return self._create(self._path(), new) - def delete(self, image_id): + def delete(self, image_id, **kwargs): """Delete an image :params image_id: uuid of the image. """ - return self._delete(self._path(image_id)) + return self._delete(self._path(image_id), qparams=kwargs) def search_image(self, image, **kwargs): """Retrieves list of images based on image name and image_driver name diff --git a/zunclient/v1/images_shell.py b/zunclient/v1/images_shell.py index 4201c9d1..e4158e43 100644 --- a/zunclient/v1/images_shell.py +++ b/zunclient/v1/images_shell.py @@ -21,10 +21,14 @@ def _show_image(image): @utils.arg('image', metavar='', help='Name of the image') +@utils.arg('host', + metavar='', + help='Name or UUID of the host') def do_pull(cs, args): - """Pull an image.""" + """Pull an image into a host.""" opts = {} opts['repo'] = args.image + opts['host'] = args.host _show_image(cs.images.create(**opts)) @@ -69,9 +73,15 @@ def do_image_show(cs, args): @utils.arg('id', metavar='', help='UUID of image to delete') +@utils.arg('host', + metavar='', + help='Name or UUID of the host') def do_image_delete(cs, args): - """Delete a specific image.""" - cs.images.delete(args.id) + """Delete a specified image from a host.""" + opts = {} + opts['image_id'] = args.id + opts['host'] = args.host + cs.images.delete(**opts) @utils.arg('image',