Add commands to show image metadata

- cinder image-metadata-show volume_id
This command can be used to show the image metadata associated
with the specific volume.

Partially implements: bp support-modify-volume-image-metadata

Change-Id: I960af66038b47c1206619b99a2bb5ae561a59c4f
This commit is contained in:
Dave Chen
2015-08-05 13:56:26 +08:00
parent 6d440d2e94
commit 64bf39e93f
4 changed files with 40 additions and 0 deletions

View File

@@ -453,6 +453,8 @@ class FakeHTTPClient(base_client.HTTPClient):
assert list(body[action]) == ['metadata']
elif action == 'os-unset_image_metadata':
assert 'key' in body[action]
elif action == 'os-show_image_metadata':
assert body[action] is None
else:
raise AssertionError("Unexpected action: %s" % action)
return (resp, {}, _body)

View File

@@ -1091,3 +1091,15 @@ class ShellTest(utils.TestCase):
def test_get_capabilities(self):
self.run_command('get-capabilities host')
self.assert_called('GET', '/capabilities/host')
def test_image_metadata_show(self):
# since the request is not actually sent to cinder API but is
# calling the method in :class:`v2.fakes.FakeHTTPClient` instead.
# Thus, ignore any exception which is false negative compare
# with real API call.
try:
self.run_command('image-metadata-show 1234')
except Exception:
pass
expected = {"os-show_image_metadata": None}
self.assert_called('POST', '/volumes/1234/action', body=expected)

View File

@@ -1910,6 +1910,16 @@ def do_metadata_show(cs, args):
utils.print_dict(volume._info['metadata'], 'Metadata-property')
@utils.arg('volume', metavar='<volume>',
help='ID of volume.')
@utils.service_type('volumev2')
def do_image_metadata_show(cs, args):
"""Shows volume image metadata."""
volume = utils.find_volume(cs, args.volume)
resp, body = volume.show_image_metadata(volume)
utils.print_dict(body['metadata'], 'Metadata-property')
@utils.arg('volume',
metavar='<volume>',
help='ID of volume for which to update metadata.')

View File

@@ -114,6 +114,14 @@ class Volume(base.Resource):
"""
return self.manager.delete_image_metadata(self, volume, keys)
def show_image_metadata(self, volume):
"""Show a volume's image metadata.
:param volume : The :class: `Volume` where the image metadata
associated.
"""
return self.manager.show_image_metadata(self)
def upload_to_image(self, force, image_name, container_format,
disk_format):
"""Upload a volume to image service as an image."""
@@ -518,6 +526,14 @@ class VolumeManager(base.ManagerWithFind):
self._action("os-unset_image_metadata", volume,
{'key': key})
def show_image_metadata(self, volume):
"""Show a volume's image metadata.
:param volume : The :class: `Volume` where the image metadata
associated.
"""
return self._action("os-show_image_metadata", volume)
def upload_to_image(self, volume, force, image_name, container_format,
disk_format):
"""Upload volume to image service as image.