Adding CLI command for `glance member-get`

This patch adds a command ``image member get`` which displays
a particular member associated to the image.

Change-Id: I48d3151f8e204e1eb5cfff67ce1e333d1cfb9322
This commit is contained in:
Mridula Joshi 2023-12-20 05:03:40 +00:00
parent d09aec3459
commit 93b2e66d2d
5 changed files with 105 additions and 1 deletions

View File

@ -54,7 +54,7 @@ md-tag-show,,Describe a specific metadata definitions tag inside a namespace.
md-tag-update,,Rename a metadata definitions tag inside a namespace.
member-create,image add project,Create member for a given image.
member-delete,image remove project,Delete image member.
member-get,,Show details of an image member
member-get,image member get,Show details of an image member
member-list,image member list,Describe sharing permissions by image.
member-update,image set --accept --reject --status,Update the status of a member for a given image.
stores-delete,image delete --store,Delete image from specific store.

1 cache-clear cached image list Clear all images from cache, queue or both.
54 md-tag-update Rename a metadata definitions tag inside a namespace.
55 member-create image add project Create member for a given image.
56 member-delete image remove project Delete image member.
57 member-get image member get Show details of an image member
58 member-list image member list Describe sharing permissions by image.
59 member-update image set --accept --reject --status Update the status of a member for a given image.
60 stores-delete image delete --store Delete image from specific store.

View File

@ -992,6 +992,43 @@ class RemoveProjectImage(command.Command):
image_client.remove_member(member=project_id, image=image.id)
class ShowProjectImage(command.ShowOne):
_description = _("Show a particular project associated with image")
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
"image",
metavar="<image>",
help=_("Image (name or ID)"),
)
parser.add_argument(
"member",
metavar="<project>",
help=_("Project to show (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
return parser
def take_action(self, parsed_args):
image_client = self.app.client_manager.image
image = image_client.find_image(
parsed_args.image,
ignore_missing=False,
)
obj = image_client.get_member(
image=image.id,
member=parsed_args.member,
)
display_columns, columns = _get_member_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
return (display_columns, data)
class SaveImage(command.Command):
_description = _("Save an image locally")

View File

@ -1093,6 +1093,66 @@ class TestRemoveProjectImage(TestImage):
self.assertIsNone(result)
class TestShowProjectImage(TestImage):
_image = image_fakes.create_one_image()
new_member = image_fakes.create_one_image_member(
attrs={'image_id': _image.id, 'member_id': 'member1'}
)
columns = (
'created_at',
'image_id',
'member_id',
'schema',
'status',
'updated_at',
)
datalist = (
new_member.created_at,
_image.id,
new_member.member_id,
new_member.schema,
new_member.status,
new_member.updated_at,
)
def setUp(self):
super().setUp()
# This is the return value for utils.find_resource()
self.image_client.find_image.return_value = self._image
self.image_client.get_member.return_value = self.new_member
# Get the command object to test
self.cmd = _image.ShowProjectImage(self.app, None)
def test_show_project_image(self):
arglist = [
self._image.id,
'member1',
]
verifylist = [
('image', self._image.id),
('member', 'member1'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.image_client.find_image.assert_called_with(
self._image.id, ignore_missing=False
)
self.image_client.get_member.assert_called_with(
member='member1',
image=self._image.id,
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data)
class TestImageSet(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``image member get`` command which accepts an
image_id and member_id and displays the detail of
the particular meber associated to the image.

View File

@ -379,6 +379,7 @@ openstack.image.v2 =
image_list = openstackclient.image.v2.image:ListImage
image_member_list = openstackclient.image.v2.image:ListImageProjects
image_remove_project = openstackclient.image.v2.image:RemoveProjectImage
image_member_get = openstackclient.image.v2.image:ShowProjectImage
image_save = openstackclient.image.v2.image:SaveImage
image_show = openstackclient.image.v2.image:ShowImage
image_set = openstackclient.image.v2.image:SetImage