diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-12-20 23:41:39 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-12-20 23:41:39 +0000 |
| commit | b827dc2983b2604bb00d79f372c8a696370d83c8 (patch) | |
| tree | 242a4386d692dbc00fad7b8ef86c820c6c0e2783 | |
| parent | d7673f7655c631cafbaf5e95439c1c07bd267714 (diff) | |
| parent | b3bbd09131e127e7540f4ccdb1376c10bace8b7a (diff) | |
| download | nova-b827dc2983b2604bb00d79f372c8a696370d83c8.tar.gz nova-b827dc2983b2604bb00d79f372c8a696370d83c8.tar.xz nova-b827dc2983b2604bb00d79f372c8a696370d83c8.zip | |
Merge "Add extension to allow hiding of addresses"
29 files changed, 705 insertions, 2 deletions
diff --git a/doc/api_samples/all_extensions/extensions-get-resp.json b/doc/api_samples/all_extensions/extensions-get-resp.json index b85fae2de..f2ed617bf 100644 --- a/doc/api_samples/all_extensions/extensions-get-resp.json +++ b/doc/api_samples/all_extensions/extensions-get-resp.json @@ -249,6 +249,14 @@ "updated": "2012-07-06T00:00:00+00:00" }, { + "alias": "os-hide-server-addresses", + "description": "Support hiding server addresses in certain states.", + "links": [], + "name": "HideServerAddresses", + "namespace": "http://docs.openstack.org/compute/ext/hide_server_addresses/api/v1.1", + "updated": "2012-12-11T00:00:00+00:00" + }, + { "alias": "os-hosts", "description": "Admin-only host administration", "links": [], @@ -401,4 +409,4 @@ "updated": "2011-03-25T00:00:00+00:00" } ] -} +}
\ No newline at end of file diff --git a/doc/api_samples/all_extensions/extensions-get-resp.xml b/doc/api_samples/all_extensions/extensions-get-resp.xml index 049498fc4..a17f415f5 100644 --- a/doc/api_samples/all_extensions/extensions-get-resp.xml +++ b/doc/api_samples/all_extensions/extensions-get-resp.xml @@ -107,6 +107,9 @@ <extension alias="os-fping" updated="2012-07-06T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/fping/api/v1.1" name="Fping"> <description>Fping Management Extension.</description> </extension> + <extension alias="os-hide-server-addresses" updated="2012-12-11T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/hide_server_addresses/api/v1.1" name="HideServerAddresses"> + <description>Support hiding server addresses in certain states.</description> + </extension> <extension alias="os-hosts" updated="2011-06-29T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/hosts/api/v1.1" name="Hosts"> <description>Admin-only host administration</description> </extension> @@ -164,4 +167,4 @@ <extension alias="os-volumes" updated="2011-03-25T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/volumes/api/v1.1" name="Volumes"> <description>Volumes support</description> </extension> -</extensions> +</extensions>
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/server-get-resp.json b/doc/api_samples/os-hide-server-addresses/server-get-resp.json new file mode 100644 index 000000000..b4209f461 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-get-resp.json @@ -0,0 +1,54 @@ +{ + "server": { + "accessIPv4": "", + "accessIPv6": "", + "addresses": { + "private": [ + { + "addr": "192.168.0.3", + "version": 4 + } + ] + }, + "created": "2012-12-19T20:32:40Z", + "flavor": { + "id": "1", + "links": [ + { + "href": "http://openstack.example.com/openstack/flavors/1", + "rel": "bookmark" + } + ] + }, + "hostId": "d2697421d9869915ee376575508fdba76432f9b3ef451e7a1f86c62e", + "id": "2e9157dc-deea-4ee7-820a-640ecba32b5a", + "image": { + "id": "70a599e0-31e7-49b7-b260-868f441e862b", + "links": [ + { + "href": "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/2e9157dc-deea-4ee7-820a-640ecba32b5a", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/2e9157dc-deea-4ee7-820a-640ecba32b5a", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "2012-12-19T20:32:42Z", + "user_id": "fake" + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/server-get-resp.xml b/doc/api_samples/os-hide-server-addresses/server-get-resp.xml new file mode 100644 index 000000000..caa4a2fa5 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-get-resp.xml @@ -0,0 +1,19 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" status="ACTIVE" updated="2012-12-19T20:32:39Z" hostId="4ae230cb1f554a4a4e02b03bc79c2da5354c3051a70cef6298ace888" name="new-server-test" created="2012-12-19T20:32:37Z" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="b8b02dd4-b2bb-441d-b52a-ee5c89c832d2"> + <image id="70a599e0-31e7-49b7-b260-868f441e862b"> + <atom:link href="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" rel="bookmark"/> + </image> + <flavor id="1"> + <atom:link href="http://openstack.example.com/openstack/flavors/1" rel="bookmark"/> + </flavor> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <addresses> + <network id="private"> + <ip version="4" addr="192.168.0.3"/> + </network> + </addresses> + <atom:link href="http://openstack.example.com/v2/openstack/servers/b8b02dd4-b2bb-441d-b52a-ee5c89c832d2" rel="self"/> + <atom:link href="http://openstack.example.com/openstack/servers/b8b02dd4-b2bb-441d-b52a-ee5c89c832d2" rel="bookmark"/> +</server>
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/server-post-req.json b/doc/api_samples/os-hide-server-addresses/server-post-req.json new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-post-req.json diff --git a/doc/api_samples/os-hide-server-addresses/server-post-req.xml b/doc/api_samples/os-hide-server-addresses/server-post-req.xml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-post-req.xml diff --git a/doc/api_samples/os-hide-server-addresses/server-post-resp.json b/doc/api_samples/os-hide-server-addresses/server-post-resp.json new file mode 100644 index 000000000..15282fde4 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-post-resp.json @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "c47PrLGGmARP", + "id": "1130fd6e-4d52-4e2a-848f-89b28fa03a7a", + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/1130fd6e-4d52-4e2a-848f-89b28fa03a7a", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/1130fd6e-4d52-4e2a-848f-89b28fa03a7a", + "rel": "bookmark" + } + ] + } +}
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/server-post-resp.xml b/doc/api_samples/os-hide-server-addresses/server-post-resp.xml new file mode 100644 index 000000000..446fe5a9c --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/server-post-resp.xml @@ -0,0 +1,6 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="cc81aaca-5c3c-4ac6-bffe-79eb7a12def2" adminPass="4Z9kWS2YcY9f"> + <metadata/> + <atom:link href="http://openstack.example.com/v2/openstack/servers/cc81aaca-5c3c-4ac6-bffe-79eb7a12def2" rel="self"/> + <atom:link href="http://openstack.example.com/openstack/servers/cc81aaca-5c3c-4ac6-bffe-79eb7a12def2" rel="bookmark"/> +</server>
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/servers-details-resp.json b/doc/api_samples/os-hide-server-addresses/servers-details-resp.json new file mode 100644 index 000000000..3787cd707 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/servers-details-resp.json @@ -0,0 +1,56 @@ +{ + "servers": [ + { + "accessIPv4": "", + "accessIPv6": "", + "addresses": { + "private": [ + { + "addr": "192.168.0.3", + "version": 4 + } + ] + }, + "created": "2012-12-19T20:32:37Z", + "flavor": { + "id": "1", + "links": [ + { + "href": "http://openstack.example.com/openstack/flavors/1", + "rel": "bookmark" + } + ] + }, + "hostId": "11c1ae0bb109cd0467c62e96917cfa2956a9f3c1dce9a6565d80f5eb", + "id": "625a1d37-3515-49ad-91e2-21075a1b2ccf", + "image": { + "id": "70a599e0-31e7-49b7-b260-868f441e862b", + "links": [ + { + "href": "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/625a1d37-3515-49ad-91e2-21075a1b2ccf", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/625a1d37-3515-49ad-91e2-21075a1b2ccf", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "2012-12-19T20:32:39Z", + "user_id": "fake" + } + ] +}
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/servers-details-resp.xml b/doc/api_samples/os-hide-server-addresses/servers-details-resp.xml new file mode 100644 index 000000000..0296cc167 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/servers-details-resp.xml @@ -0,0 +1,21 @@ +<?xml version='1.0' encoding='UTF-8'?> +<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1"> + <server status="ACTIVE" updated="2012-12-19T20:32:42Z" hostId="120a7c150d2ad92ce84590d0780c67b9e8be59b7084d0bc292ec0378" name="new-server-test" created="2012-12-19T20:32:40Z" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="55db7849-8ec4-46dd-8897-492d82282f29"> + <image id="70a599e0-31e7-49b7-b260-868f441e862b"> + <atom:link href="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" rel="bookmark"/> + </image> + <flavor id="1"> + <atom:link href="http://openstack.example.com/openstack/flavors/1" rel="bookmark"/> + </flavor> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <addresses> + <network id="private"> + <ip version="4" addr="192.168.0.3"/> + </network> + </addresses> + <atom:link href="http://openstack.example.com/v2/openstack/servers/55db7849-8ec4-46dd-8897-492d82282f29" rel="self"/> + <atom:link href="http://openstack.example.com/openstack/servers/55db7849-8ec4-46dd-8897-492d82282f29" rel="bookmark"/> + </server> +</servers>
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/servers-list-resp.json b/doc/api_samples/os-hide-server-addresses/servers-list-resp.json new file mode 100644 index 000000000..f0042254b --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/servers-list-resp.json @@ -0,0 +1,18 @@ +{ + "servers": [ + { + "id": "120eed64-e7db-409c-b565-38ce2bc90021", + "links": [ + { + "href": "http://openstack.example.com/v2/openstack/servers/120eed64-e7db-409c-b565-38ce2bc90021", + "rel": "self" + }, + { + "href": "http://openstack.example.com/openstack/servers/120eed64-e7db-409c-b565-38ce2bc90021", + "rel": "bookmark" + } + ], + "name": "new-server-test" + } + ] +}
\ No newline at end of file diff --git a/doc/api_samples/os-hide-server-addresses/servers-list-resp.xml b/doc/api_samples/os-hide-server-addresses/servers-list-resp.xml new file mode 100644 index 000000000..3225a4c36 --- /dev/null +++ b/doc/api_samples/os-hide-server-addresses/servers-list-resp.xml @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1"> + <server name="new-server-test" id="7c3e9b55-f06c-499b-9d72-266e7806ce5a"> + <atom:link href="http://openstack.example.com/v2/openstack/servers/7c3e9b55-f06c-499b-9d72-266e7806ce5a" rel="self"/> + <atom:link href="http://openstack.example.com/openstack/servers/7c3e9b55-f06c-499b-9d72-266e7806ce5a" rel="bookmark"/> + </server> +</servers>
\ No newline at end of file diff --git a/etc/nova/policy.json b/etc/nova/policy.json index d06430129..f1e16d834 100644 --- a/etc/nova/policy.json +++ b/etc/nova/policy.json @@ -54,6 +54,7 @@ "compute_extension:floating_ips_bulk": "rule:admin_api", "compute_extension:fping": "", "compute_extension:fping:all_tenants": "rule:admin_api", + "compute_extension:hide_server_addresses": "is_admin:False", "compute_extension:hosts": "rule:admin_api", "compute_extension:hypervisors": "rule:admin_api", "compute_extension:instance_usage_audit_log": "rule:admin_api", diff --git a/nova/api/openstack/compute/contrib/hide_server_addresses.py b/nova/api/openstack/compute/contrib/hide_server_addresses.py new file mode 100644 index 000000000..bb8ee553a --- /dev/null +++ b/nova/api/openstack/compute/contrib/hide_server_addresses.py @@ -0,0 +1,89 @@ +# Copyright 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Extension for hiding server addresses in certain states.""" + + +from nova.api.openstack import extensions +from nova.api.openstack import wsgi +from nova.compute import vm_states +from nova.openstack.common import cfg +from nova.openstack.common import log as logging + +opts = [ + cfg.ListOpt('osapi_hide_server_address_states', + default=[vm_states.BUILDING], + help='List of instance states that should hide network info'), +] + + +CONF = cfg.CONF +CONF.register_opts(opts) +LOG = logging.getLogger(__name__) + +authorize = extensions.soft_extension_authorizer('compute', + 'hide_server_addresses') + + +class Controller(wsgi.Controller): + def __init__(self, *args, **kwargs): + super(Controller, self).__init__(*args, **kwargs) + hidden_states = CONF.osapi_hide_server_address_states + + # NOTE(jkoelker) _ is not considered uppercase ;) + valid_vm_states = [getattr(vm_states, state) + for state in dir(vm_states) + if state.isupper()] + self.hide_address_states = [state.lower() + for state in hidden_states + if state in valid_vm_states] + + def _perhaps_hide_addresses(self, instance, resp_server): + if instance.get('vm_state') in self.hide_address_states: + resp_server['addresses'] = {} + + @wsgi.extends + def show(self, req, resp_obj, id): + resp = resp_obj + if not authorize(req.environ['nova.context']): + return + + if 'server' in resp.obj and 'addresses' in resp.obj['server']: + instance = req.get_db_instance(id) + self._perhaps_hide_addresses(instance, resp.obj['server']) + + @wsgi.extends + def detail(self, req, resp_obj): + resp = resp_obj + if not authorize(req.environ['nova.context']): + return + + for server in list(resp.obj['servers']): + if 'addresses' in server: + instance = req.get_db_instance(server['id']) + self._perhaps_hide_addresses(instance, server) + + +class Hide_server_addresses(extensions.ExtensionDescriptor): + """Support hiding server addresses in certain states.""" + + name = 'HideServerAddresses' + alias = 'os-hide-server-addresses' + namespace = ('http://docs.openstack.org/compute/ext/' + 'hide_server_addresses/api/v1.1') + updated = '2012-12-11T00:00:00+00:00' + + def get_controller_extensions(self): + return [extensions.ControllerExtension(self, 'servers', Controller())] diff --git a/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py b/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py new file mode 100644 index 000000000..7991bc27f --- /dev/null +++ b/nova/tests/api/openstack/compute/contrib/test_hide_server_addresses.py @@ -0,0 +1,151 @@ +# Copyright 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import itertools + +from lxml import etree +import webob + +from nova.api.openstack import wsgi +from nova import compute +from nova.compute import vm_states +from nova import exception +from nova.openstack.common import jsonutils +from nova import test +from nova.tests.api.openstack import fakes + + +SENTINEL = object() + + +def fake_compute_get(*args, **kwargs): + def _return_server(*_args, **_kwargs): + return fakes.stub_instance(*args, **kwargs) + return _return_server + + +class HideServerAddressesTest(test.TestCase): + content_type = 'application/json' + + def setUp(self): + super(HideServerAddressesTest, self).setUp() + fakes.stub_out_nw_api(self.stubs) + self.flags( + osapi_compute_extension=[ + 'nova.api.openstack.compute.contrib.select_extensions'], + osapi_compute_ext_list=['Hide_server_addresses']) + + def _make_request(self, url): + req = webob.Request.blank(url) + req.headers['Accept'] = self.content_type + res = req.get_response(fakes.wsgi_app(init_only=('servers',))) + return res + + @staticmethod + def _get_server(body): + return jsonutils.loads(body).get('server') + + @staticmethod + def _get_servers(body): + return jsonutils.loads(body).get('servers') + + @staticmethod + def _get_addresses(server): + return server.get('addresses', SENTINEL) + + def _check_addresses(self, addresses, exists): + self.assertTrue(addresses is not SENTINEL) + if exists: + self.assertTrue(addresses) + else: + self.assertFalse(addresses) + + def test_show_hides_in_building(self): + instance_id = 1 + uuid = fakes.get_fake_uuid(instance_id) + self.stubs.Set(compute.api.API, 'get', + fake_compute_get(instance_id, uuid=uuid, + vm_state=vm_states.BUILDING)) + res = self._make_request('/v2/fake/servers/%s' % uuid) + self.assertEqual(res.status_int, 200) + + server = self._get_server(res.body) + addresses = self._get_addresses(server) + self._check_addresses(addresses, exists=False) + + def test_show(self): + instance_id = 1 + uuid = fakes.get_fake_uuid(instance_id) + self.stubs.Set(compute.api.API, 'get', + fake_compute_get(instance_id, uuid=uuid, + vm_state=vm_states.ACTIVE)) + res = self._make_request('/v2/fake/servers/%s' % uuid) + self.assertEqual(res.status_int, 200) + + server = self._get_server(res.body) + addresses = self._get_addresses(server) + self._check_addresses(addresses, exists=True) + + def test_detail_hides_building_server_addresses(self): + instance_0 = fakes.stub_instance(0, uuid=fakes.get_fake_uuid(0), + vm_state=vm_states.ACTIVE) + instance_1 = fakes.stub_instance(1, uuid=fakes.get_fake_uuid(1), + vm_state=vm_states.BUILDING) + instances = [instance_0, instance_1] + + def get_all(*args, **kwargs): + return instances + + self.stubs.Set(compute.api.API, 'get_all', get_all) + res = self._make_request('/v2/fake/servers/detail') + + self.assertEqual(res.status_int, 200) + servers = self._get_servers(res.body) + + self.assertEqual(len(servers), len(instances)) + + for instance, server in itertools.izip(instances, servers): + addresses = self._get_addresses(server) + exists = (instance['vm_state'] == vm_states.ACTIVE) + self._check_addresses(addresses, exists=exists) + + def test_no_instance_passthrough_404(self): + + def fake_compute_get(*args, **kwargs): + raise exception.InstanceNotFound() + + self.stubs.Set(compute.api.API, 'get', fake_compute_get) + res = self._make_request('/v2/fake/servers/' + fakes.get_fake_uuid()) + + self.assertEqual(res.status_int, 404) + + +class HideAddressesXmlTest(HideServerAddressesTest): + content_type = 'application/xml' + + @staticmethod + def _get_server(body): + return etree.XML(body) + + @staticmethod + def _get_servers(body): + return etree.XML(body).getchildren() + + @staticmethod + def _get_addresses(server): + addresses = server.find('{%s}addresses' % wsgi.XMLNS_V11) + if addresses is None: + return SENTINEL + return addresses diff --git a/nova/tests/fake_policy.py b/nova/tests/fake_policy.py index 9c1140922..80eb08743 100644 --- a/nova/tests/fake_policy.py +++ b/nova/tests/fake_policy.py @@ -130,6 +130,7 @@ policy_data = """ "compute_extension:floating_ips_bulk": "", "compute_extension:fping": "", "compute_extension:fping:all_tenants": "is_admin:True", + "compute_extension:hide_server_addresses": "", "compute_extension:hosts": "", "compute_extension:hypervisors": "", "compute_extension:instance_usage_audit_log": "", diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl index 4a8d96844..20f9044f9 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl @@ -241,6 +241,14 @@ "updated": "%(timestamp)s" }, { + "alias": "os-hide-server-addresses", + "description": "Support hiding server addresses in certain states.", + "links": [], + "name": "HideServerAddresses", + "namespace": "http://docs.openstack.org/compute/ext/hide_server_addresses/api/v1.1", + "updated": "2012-12-11T00:00:00+00:00" + }, + { "alias": "os-hosts", "description": "%(text)s", "links": [], diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl index 7d4683986..1669ff957 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl @@ -90,6 +90,9 @@ <extension alias="os-floating-ips-bulk" name="FloatingIpsBulk" namespace="http://docs.openstack.org/compute/ext/floating_ips_bulk/api/v2" updated="2012-10-29T13:25:27-06:00"> <description>%(text)s</description> </extension> + <extension alias="os-hide-server-addresses" updated="2012-12-11T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/hide_server_addresses/api/v1.1" name="HideServerAddresses"> + <description>Support hiding server addresses in certain states.</description> + </extension> <extension alias="os-hosts" updated="%(timestamp)s" namespace="http://docs.openstack.org/compute/ext/hosts/api/v1.1" name="Hosts"> <description>%(text)s</description> </extension> diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.json.tpl new file mode 100644 index 000000000..86e39aedc --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.json.tpl @@ -0,0 +1,54 @@ +{ + "server": { + "accessIPv4": "", + "accessIPv6": "", + "addresses": { + "private": [ + { + "addr": "%(ip)s", + "version": 4 + } + ] + }, + "created": "%(timestamp)s", + "flavor": { + "id": "1", + "links": [ + { + "href": "%(host)s/openstack/flavors/1", + "rel": "bookmark" + } + ] + }, + "hostId": "%(hostid)s", + "id": "%(id)s", + "image": { + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/openstack/images/%(uuid)s", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(id)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(id)s", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "%(timestamp)s", + "user_id": "fake" + } +} diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.xml.tpl new file mode 100644 index 000000000..adc8a5c1b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-get-resp.xml.tpl @@ -0,0 +1,19 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" status="ACTIVE" updated="%(timestamp)s" hostId="%(hostid)s" name="new-server-test" created="%(timestamp)s" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="%(id)s"> + <image id="%(uuid)s"> + <atom:link href="%(host)s/openstack/images/%(uuid)s" rel="bookmark"/> + </image> + <flavor id="1"> + <atom:link href="%(host)s/openstack/flavors/1" rel="bookmark"/> + </flavor> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <addresses> + <network id="private"> + <ip version="4" addr="%(ip)s"/> + </network> + </addresses> + <atom:link href="%(host)s/v2/openstack/servers/%(id)s" rel="self"/> + <atom:link href="%(host)s/openstack/servers/%(id)s" rel="bookmark"/> +</server> diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.json.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.json.tpl new file mode 100644 index 000000000..d3916d1aa --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.json.tpl @@ -0,0 +1,16 @@ +{ + "server" : { + "name" : "new-server-test", + "imageRef" : "%(host)s/openstack/images/%(image_id)s", + "flavorRef" : "%(host)s/openstack/flavors/1", + "metadata" : { + "My Server Name" : "Apache1" + }, + "personality" : [ + { + "path" : "/etc/banner.txt", + "contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.xml.tpl new file mode 100644 index 000000000..f92614984 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-req.xml.tpl @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="%(host)s/openstack/images/%(image_id)s" flavorRef="%(host)s/openstack/flavors/1" name="new-server-test"> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <personality> + <file path="/etc/banner.txt"> + ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp + dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k + IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs + c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g + QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo + ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv + dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy + c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 + b25zLiINCg0KLVJpY2hhcmQgQmFjaA== + </file> + </personality> +</server> diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.json.tpl new file mode 100644 index 000000000..d5f030c87 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "%(password)s", + "id": "%(id)s", + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(uuid)s", + "rel": "bookmark" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.xml.tpl new file mode 100644 index 000000000..3bb13e69b --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/server-post-resp.xml.tpl @@ -0,0 +1,6 @@ +<?xml version='1.0' encoding='UTF-8'?> +<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="%(id)s" adminPass="%(password)s"> + <metadata/> + <atom:link href="%(host)s/v2/openstack/servers/%(uuid)s" rel="self"/> + <atom:link href="%(host)s/openstack/servers/%(uuid)s" rel="bookmark"/> +</server> diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.json.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.json.tpl new file mode 100644 index 000000000..e244ea0df --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.json.tpl @@ -0,0 +1,56 @@ +{ + "servers": [ + { + "accessIPv4": "", + "accessIPv6": "", + "addresses": { + "private": [ + { + "addr": "%(ip)s", + "version": 4 + } + ] + }, + "created": "%(timestamp)s", + "flavor": { + "id": "1", + "links": [ + { + "href": "%(host)s/openstack/flavors/1", + "rel": "bookmark" + } + ] + }, + "hostId": "%(hostid)s", + "id": "%(id)s", + "image": { + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/openstack/images/%(uuid)s", + "rel": "bookmark" + } + ] + }, + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(id)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(id)s", + "rel": "bookmark" + } + ], + "metadata": { + "My Server Name": "Apache1" + }, + "name": "new-server-test", + "progress": 0, + "status": "ACTIVE", + "tenant_id": "openstack", + "updated": "%(timestamp)s", + "user_id": "fake" + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.xml.tpl new file mode 100644 index 000000000..568807ecb --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-details-resp.xml.tpl @@ -0,0 +1,21 @@ +<?xml version='1.0' encoding='UTF-8'?> +<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1"> + <server status="ACTIVE" updated="%(timestamp)s" hostId="%(hostid)s" name="new-server-test" created="%(timestamp)s" userId="fake" tenantId="openstack" accessIPv4="" accessIPv6="" progress="0" id="%(id)s"> + <image id="%(uuid)s"> + <atom:link href="%(host)s/openstack/images/%(uuid)s" rel="bookmark"/> + </image> + <flavor id="1"> + <atom:link href="%(host)s/openstack/flavors/1" rel="bookmark"/> + </flavor> + <metadata> + <meta key="My Server Name">Apache1</meta> + </metadata> + <addresses> + <network id="private"> + <ip version="4" addr="%(ip)s"/> + </network> + </addresses> + <atom:link href="%(host)s/v2/openstack/servers/%(id)s" rel="self"/> + <atom:link href="%(host)s/openstack/servers/%(id)s" rel="bookmark"/> + </server> +</servers> diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.json.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.json.tpl new file mode 100644 index 000000000..8b97dc28d --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.json.tpl @@ -0,0 +1,18 @@ +{ + "servers": [ + { + "id": "%(id)s", + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(id)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(id)s", + "rel": "bookmark" + } + ], + "name": "new-server-test" + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.xml.tpl new file mode 100644 index 000000000..03bee03a6 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hide-server-addresses/servers-list-resp.xml.tpl @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<servers xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1"> + <server name="new-server-test" id="%(id)s"> + <atom:link href="%(host)s/v2/openstack/servers/%(id)s" rel="self"/> + <atom:link href="%(host)s/openstack/servers/%(id)s" rel="bookmark"/> + </server> +</servers> diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index a9fbb8fe3..a33b39da4 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -457,6 +457,16 @@ class ServersSampleAllExtensionXmlTest(ServersSampleXmlTest): all_extensions = True +class ServersSampleHideAddressesJsonTest(ServersSampleJsonTest): + extension_name = '.'.join(('nova.api.openstack.compute.contrib', + 'hide_server_addresses', + 'Hide_server_addresses')) + + +class ServersSampleHideAddressesXMLTest(ServersSampleHideAddressesJsonTest): + ctype = 'xml' + + class ServersMetadataJsonTest(ServersSampleBase): def _create_and_set(self, subs): uuid = self._post_server() |
