summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chen <wei.d.chen@intel.com>2015-08-05 13:56:26 +0800
committerDave Chen <wei.d.chen@intel.com>2015-09-30 13:57:37 +0800
commit64bf39e93f138c45002196c0cefca3215484822c (patch)
tree9fd236b2b3921b5fc4ee438e831eade46b8297ed
parent6d440d2e942fa5d22d33e648c72deddaf501afb1 (diff)
downloadpython-cinderclient-64bf39e93f138c45002196c0cefca3215484822c.tar.gz
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
-rw-r--r--cinderclient/tests/unit/v2/fakes.py2
-rw-r--r--cinderclient/tests/unit/v2/test_shell.py12
-rw-r--r--cinderclient/v2/shell.py10
-rw-r--r--cinderclient/v2/volumes.py16
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.