diff options
-rw-r--r-- | cinderclient/tests/unit/v2/fakes.py | 2 | ||||
-rw-r--r-- | cinderclient/tests/unit/v2/test_shell.py | 12 | ||||
-rw-r--r-- | cinderclient/v2/shell.py | 10 | ||||
-rw-r--r-- | cinderclient/v2/volumes.py | 16 |
4 files changed, 40 insertions, 0 deletions
diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index 8182505..4093d10 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -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) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index d183564..b8d3f20 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -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) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 16e6877..0795c8a 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -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.') diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index d5eb8d0..0e76775 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -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. |