diff --git a/novaclient/tests/unit/fixture_data/servers.py b/novaclient/tests/unit/fixture_data/servers.py index 8e53ecdb2..1635e33dc 100644 --- a/novaclient/tests/unit/fixture_data/servers.py +++ b/novaclient/tests/unit/fixture_data/servers.py @@ -205,6 +205,19 @@ class Base(base.Fixture): self.requests_mock.delete(self.url(u, 'metadata', 'key1'), json=self.diagnostic, headers=self.json_headers) + metadata3 = {'meta': { + 'Server Label': 'Web Head 1' + }} + self.requests_mock.get(self.url(1234, 'metadata', 'Server Label'), + json=metadata3, + headers=self.json_headers) + metadata4 = {'metadata': { + 'Server Label': 'Web Head 1', + 'Image Version': '2.1' + }} + self.requests_mock.get(self.url(1234, 'metadata'), + json=metadata4, + headers=self.json_headers) get_security_groups = { "security_groups": [{ diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py index 93fefabfe..36eded7a8 100644 --- a/novaclient/tests/unit/v2/test_servers.py +++ b/novaclient/tests/unit/v2/test_servers.py @@ -463,6 +463,23 @@ class ServersTest(utils.FixturedTestCase): self.assert_called('PUT', '/servers/1234/metadata/test_key', {'meta': {'test_key': 'test_value'}}) + def test_get_server_meta(self): + m = self.cs.servers.get_meta(1234, 'Server Label') + self.assert_request_id(m, fakes.FAKE_REQUEST_ID_LIST) + self.assert_called('GET', '/servers/1234/metadata/Server%20Label') + self.assertEqual(m, {'meta': { + 'Server Label': 'Web Head 1' + }}) + + def test_list_server_meta(self): + m = self.cs.servers.list_meta(1234) + self.assert_request_id(m, fakes.FAKE_REQUEST_ID_LIST) + self.assert_called('GET', '/servers/1234/metadata') + self.assertEqual(m, {'metadata': { + 'Server Label': 'Web Head 1', + 'Image Version': '2.1' + }}) + def test_find(self): server = self.cs.servers.find(name='sample-server') self.assert_request_id(server, fakes.FAKE_REQUEST_ID_LIST) diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py index 37f55316a..81c702dfb 100644 --- a/novaclient/v2/servers.py +++ b/novaclient/v2/servers.py @@ -2039,6 +2039,26 @@ class ServerManager(base.BootingManagerWithFind): return self._update("/servers/%s/metadata/%s" % (base.getid(server), key), body) + def list_meta(self, server): + """ + Lists all metadata for a server. + :param server: The :class:`Server` (or its ID). + :returns: A dict of metadata. + """ + resp, body = self.api.client.get("/servers/%s/metadata" % + base.getid(server)) + return base.DictWithMeta(body, resp) + + def get_meta(self, server, key): + """ + Shows details for a metadata item, by key, for a server. + :param server: The :class:`Server` (or its ID). + :param key: metadata key to get + """ + resp, body = self.api.client.get("/servers/%s/metadata/%s" % + (base.getid(server), key)) + return base.DictWithMeta(body, resp) + def get_console_output(self, server, length=None): """ Get text console log output from Server. diff --git a/releasenotes/notes/get-list-metadata-8afcc8f32ad82dda.yaml b/releasenotes/notes/get-list-metadata-8afcc8f32ad82dda.yaml new file mode 100644 index 000000000..c67cd18a6 --- /dev/null +++ b/releasenotes/notes/get-list-metadata-8afcc8f32ad82dda.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Adds supports for Nova Server get and list metadata API.