diff options
-rw-r--r-- | nova/api/openstack/servers.py | 28 | ||||
-rw-r--r-- | nova/api/openstack/v1_0/__init__.py | 0 | ||||
-rw-r--r-- | nova/api/openstack/v1_0/servers.py | 6 | ||||
-rw-r--r-- | nova/api/openstack/v1_1/__init__.py | 0 | ||||
-rw-r--r-- | nova/api/openstack/v1_1/servers.py | 8 | ||||
-rw-r--r-- | nova/tests/api/openstack/fakes.py | 1 | ||||
-rw-r--r-- | nova/tests/api/openstack/test_servers.py | 23 |
7 files changed, 45 insertions, 21 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 940c2c47e..0d36546d7 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -27,6 +27,8 @@ from nova import wsgi from nova import utils from nova.api.openstack import common from nova.api.openstack import faults +from nova.api.openstack.v1_0 import servers as v1_0 +from nova.api.openstack.v1_1 import servers as v1_1 from nova.auth import manager as auth_manager from nova.compute import instance_types from nova.compute import power_state @@ -54,7 +56,7 @@ class Controller(wsgi.Controller): def ips(self, req, id): try: instance = self.compute_api.get(req.environ['nova.context'], id) - return _addresses_builder(req)(instance) + return _get_addresses_builder(req)(instance) except exception.NotFound: return faults.Fault(exc.HTTPNotFound()) @@ -460,7 +462,7 @@ def _build_server(req, inst, is_detail): inst_dict[k] = inst[v] inst_dict['status'] = power_mapping[inst_dict['status']] - inst_dict['addresses'] = _addresses_builder(req)(inst) + inst_dict['addresses'] = _get_addresses_builder(req)(inst) # Return the metadata as a dictionary metadata = {} @@ -475,25 +477,9 @@ def _build_server(req, inst, is_detail): return dict(server=inst_dict) -def _addresses_builder(req): +def _get_addresses_builder(req): version = req.environ['nova.context'].version if version == '1.1': - return _build_addresses_11 + return v1_1.build_addresses else: - return _build_addresses_10 - - -def _build_addresses_10(inst): - private_ips = utils.get_from_path(inst, 'fixed_ip/address') - public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') - return dict(public=public_ips, private=private_ips) - - -def _build_addresses_11(inst): - private_ips = utils.get_from_path(inst, 'fixed_ip/address') - private_ips = [dict(version=4, addr=a) for a in private_ips] - public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') - public_ips = [dict(version=4, addr=a) for a in public_ips] - return dict(public=public_ips, private=private_ips) - - + return v1_0.build_addresses diff --git a/nova/api/openstack/v1_0/__init__.py b/nova/api/openstack/v1_0/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/nova/api/openstack/v1_0/__init__.py diff --git a/nova/api/openstack/v1_0/servers.py b/nova/api/openstack/v1_0/servers.py new file mode 100644 index 000000000..d332b1378 --- /dev/null +++ b/nova/api/openstack/v1_0/servers.py @@ -0,0 +1,6 @@ +from nova import utils + +def build_addresses(inst): + private_ips = utils.get_from_path(inst, 'fixed_ip/address') + public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') + return dict(public=public_ips, private=private_ips) diff --git a/nova/api/openstack/v1_1/__init__.py b/nova/api/openstack/v1_1/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/nova/api/openstack/v1_1/__init__.py diff --git a/nova/api/openstack/v1_1/servers.py b/nova/api/openstack/v1_1/servers.py new file mode 100644 index 000000000..012fc3e5c --- /dev/null +++ b/nova/api/openstack/v1_1/servers.py @@ -0,0 +1,8 @@ +from nova import utils + +def build_addresses(inst): + private_ips = utils.get_from_path(inst, 'fixed_ip/address') + private_ips = [dict(version=4, addr=a) for a in private_ips] + public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') + public_ips = [dict(version=4, addr=a) for a in public_ips] + return dict(public=public_ips, private=private_ips) diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 8ec1629f4..7af62c57f 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -81,6 +81,7 @@ def wsgi_app(inner_application=None): api = openstack.FaultWrapper(auth.AuthMiddleware( ratelimiting.RateLimitingMiddleware(inner_application))) mapper['/v1.0'] = api + mapper['/v1.1'] = api mapper['/'] = openstack.FaultWrapper(openstack.Versions()) return mapper diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index c1e05b18a..a2bd875a4 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -21,6 +21,7 @@ import json import stubout import webob +from nova import context from nova import db from nova import flags from nova import test @@ -176,6 +177,28 @@ class ServersTest(test.TestCase): self.assertEqual(len(addresses["private"]), 1) self.assertEqual(addresses["private"][0], private) + def test_get_server_by_id_with_addresses_v1_1(self): + class FakeRequestContext(object): + def __init__(self, user, project, *args, **kwargs): + self.user_id = 1 + self.project_id = 1 + self.version = '1.1' + self.stubs.Set(context, 'RequestContext', FakeRequestContext) + private = "192.168.0.3" + public = ["1.2.3.4"] + new_return_server = return_server_with_addresses(private, public) + self.stubs.Set(nova.db.api, 'instance_get', new_return_server) + req = webob.Request.blank('/v1.1/servers/1') + res = req.get_response(fakes.wsgi_app()) + res_dict = json.loads(res.body) + self.assertEqual(res_dict['server']['id'], '1') + self.assertEqual(res_dict['server']['name'], 'server1') + addresses = res_dict['server']['addresses'] + self.assertEqual(len(addresses["public"]), len(public)) + self.assertEqual(addresses["public"][0], {"version": 4, "addr": public[0]}) + self.assertEqual(len(addresses["private"]), 1) + self.assertEqual(addresses["private"][0], {"version": 4, "addr": private}) + def test_get_server_list(self): req = webob.Request.blank('/v1.0/servers') res = req.get_response(fakes.wsgi_app()) |