diff options
| author | Naveed Massjouni <naveedm9@gmail.com> | 2011-03-15 19:55:13 -0400 |
|---|---|---|
| committer | Naveed Massjouni <naveedm9@gmail.com> | 2011-03-15 19:55:13 -0400 |
| commit | bee1951ac78688e49939aee4e2285ef0ff89adb2 (patch) | |
| tree | 18cf625b9888a62786e535a86f6459401e5b0fc7 /nova | |
| parent | d4f859803eeb5a123835a3996ccfc64d35dbcb4b (diff) | |
| download | nova-bee1951ac78688e49939aee4e2285ef0ff89adb2.tar.gz nova-bee1951ac78688e49939aee4e2285ef0ff89adb2.tar.xz nova-bee1951ac78688e49939aee4e2285ef0ff89adb2.zip | |
As suggested by Eric Day:
* changed request.environ version key to more descriptive 'api.version'
* removed python3 string formatting
* added licenses to headers on new files
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/auth.py | 2 | ||||
| -rw-r--r-- | nova/api/openstack/common.py | 3 | ||||
| -rw-r--r-- | nova/api/openstack/views/addresses.py | 22 | ||||
| -rw-r--r-- | nova/api/openstack/views/flavors.py | 23 | ||||
| -rw-r--r-- | nova/api/openstack/views/images.py | 23 | ||||
| -rw-r--r-- | nova/api/openstack/views/servers.py | 20 | ||||
| -rw-r--r-- | nova/tests/api/openstack/fakes.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_servers.py | 4 |
8 files changed, 86 insertions, 15 deletions
diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/auth.py index c820a5963..7ae285019 100644 --- a/nova/api/openstack/auth.py +++ b/nova/api/openstack/auth.py @@ -70,7 +70,7 @@ class AuthMiddleware(wsgi.Middleware): req.environ['nova.context'] = context.RequestContext(user, account) version = req.path.split('/')[1].replace('v', '') - req.environ['version'] = version + req.environ['nova.api.openstack.version'] = version return self.application def has_authentication(self, req): diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 74ac21024..d94969ff5 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -74,3 +74,6 @@ def get_image_id_from_image_hash(image_service, context, image_hash): if abs(hash(image_id)) == int(image_hash): return image_id raise exception.NotFound(image_hash) + +def get_api_version(req): + return req.environ.get('api.version') diff --git a/nova/api/openstack/views/addresses.py b/nova/api/openstack/views/addresses.py index 65c24dbd7..9d392aace 100644 --- a/nova/api/openstack/views/addresses.py +++ b/nova/api/openstack/views/addresses.py @@ -1,6 +1,22 @@ -import hashlib -from nova.compute import power_state +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 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. + from nova import utils +from nova.api.openstack import common def get_view_builder(req): @@ -8,7 +24,7 @@ def get_view_builder(req): A factory method that returns the correct builder based on the version of the api requested. ''' - version = req.environ['version'] + version = common.get_api_version(req) if version == '1.1': return ViewBuilder_1_1() else: diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index f945f9f8f..aa3c2aeb2 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -1,11 +1,28 @@ - +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 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. + +from nova.api.openstack import common def get_view_builder(req): ''' A factory method that returns the correct builder based on the version of the api requested. ''' - version = req.environ['version'] + version = common.get_api_version(req) base_url = req.application_url if version == '1.1': return ViewBuilder_1_1(base_url) @@ -26,7 +43,7 @@ class ViewBuilder_1_1(ViewBuilder): self.base_url = base_url def generate_href(self, flavor_id): - return "{0}/flavors/{1}".format(self.base_url, flavor_id) + return "%s/flavors/%s" % (self.base_url, flavor_id) class ViewBuilder_1_0(ViewBuilder): diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index a59d4a557..930b464b0 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -1,11 +1,28 @@ - +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 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. + +from nova.api.openstack import common def get_view_builder(req): ''' A factory method that returns the correct builder based on the version of the api requested. ''' - version = req.environ['version'] + version = common.get_api_version(req) base_url = req.application_url if version == '1.1': return ViewBuilder_1_1(base_url) @@ -26,7 +43,7 @@ class ViewBuilder_1_1(ViewBuilder): self.base_url = base_url def generate_href(self, image_id): - return "{0}/images/{1}".format(self.base_url, image_id) + return "%s/images/%s" % (self.base_url, image_id) class ViewBuilder_1_0(ViewBuilder): diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 2549cc11c..261acfed0 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -1,5 +1,23 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 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 hashlib from nova.compute import power_state +from nova.api.openstack import common from nova.api.openstack.views import addresses as addresses_view from nova.api.openstack.views import flavors as flavors_view from nova.api.openstack.views import images as images_view @@ -11,7 +29,7 @@ def get_view_builder(req): A factory method that returns the correct builder based on the version of the api requested. ''' - version = req.environ['version'] + version = common.get_api_version(req) addresses_builder = addresses_view.get_view_builder(req) if version == '1.1': flavor_builder = flavors_view.get_view_builder(req) diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 9c3b53ac7..a3968b57b 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -69,8 +69,8 @@ def fake_auth_init(self, application): @webob.dec.wsgify def fake_wsgi(self, req): req.environ['nova.context'] = context.RequestContext(1, 1) - if not req.environ.get('version'): - req.environ['version'] = '1.0' + if not req.environ.get('api.version'): + req.environ['api.version'] = '1.0' if req.body: req.environ['inst_dict'] = json.loads(req.body) return self.application diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 6b804d3b4..27d174fe9 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -183,7 +183,7 @@ class ServersTest(test.TestCase): 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') - req.environ['version'] = '1.1' + req.environ['api.version'] = '1.1' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(res_dict['server']['id'], '1') @@ -363,7 +363,7 @@ class ServersTest(test.TestCase): def test_get_all_server_details_v1_1(self): req = webob.Request.blank('/v1.1/servers/detail') - req.environ['version'] = '1.1' + req.environ['api.version'] = '1.1' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) |
