summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorNaveed Massjouni <naveedm9@gmail.com>2011-03-15 19:55:13 -0400
committerNaveed Massjouni <naveedm9@gmail.com>2011-03-15 19:55:13 -0400
commitbee1951ac78688e49939aee4e2285ef0ff89adb2 (patch)
tree18cf625b9888a62786e535a86f6459401e5b0fc7 /nova/api
parentd4f859803eeb5a123835a3996ccfc64d35dbcb4b (diff)
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/api')
-rw-r--r--nova/api/openstack/auth.py2
-rw-r--r--nova/api/openstack/common.py3
-rw-r--r--nova/api/openstack/views/addresses.py22
-rw-r--r--nova/api/openstack/views/flavors.py23
-rw-r--r--nova/api/openstack/views/images.py23
-rw-r--r--nova/api/openstack/views/servers.py20
6 files changed, 82 insertions, 11 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)