Merge "Add 'host' parameter to image API"

This commit is contained in:
Zuul
2018-06-13 02:26:29 +00:00
committed by Gerrit Code Review
3 changed files with 34 additions and 12 deletions

View File

@@ -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='<image>',
help='Name of the image')
parser.add_argument(
'host',
metavar='<host>',
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='<uuid>',
help='UUID of image to describe')
parser.add_argument(
'host',
metavar='<host>',
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})

View File

@@ -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

View File

@@ -21,10 +21,14 @@ def _show_image(image):
@utils.arg('image',
metavar='<image>',
help='Name of the image')
@utils.arg('host',
metavar='<host>',
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='<uuid>',
help='UUID of image to delete')
@utils.arg('host',
metavar='<host>',
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',