summaryrefslogtreecommitdiffstats
path: root/nova/api/openstack
diff options
context:
space:
mode:
authorMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2013-06-04 00:49:08 -0400
committerMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2013-06-13 11:36:42 -0400
commit90da2c677976b3e9e96bd68703a8b9d5ba347ce3 (patch)
tree8e08c5a305c0283687b93849d6b72f11ff49edf5 /nova/api/openstack
parent77595f8e08a61507ad5c7c990651fd4f8131c150 (diff)
downloadnova-90da2c677976b3e9e96bd68703a8b9d5ba347ce3.tar.gz
nova-90da2c677976b3e9e96bd68703a8b9d5ba347ce3.tar.xz
nova-90da2c677976b3e9e96bd68703a8b9d5ba347ce3.zip
Change resource links when url has no project id
This patch allow response body to be look like the request url. So if a project_id is passed the resource links on the response will also have a project_id, and in the case of api-v3 where project_id are no longer present in the url the response will not have it either. Complements bp v3-api-remove-project-id. Also fix two minor issues on the unit tests, which were breaking with this change: - When doing ServersViewBuilderTest there was no api version specified. - ServersControllerTest was duplicating api version on the application url. Change-Id: I872332ef56b4b6e99fedb43833ad45e8e654f44f
Diffstat (limited to 'nova/api/openstack')
-rw-r--r--nova/api/openstack/common.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index bec919f4b..7daf7aadb 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -454,6 +454,16 @@ def check_snapshots_enabled(f):
class ViewBuilder(object):
"""Model API responses as dictionaries."""
+ def _get_project_id(self, request):
+ """
+ Get project id from request url if present or empty string
+ otherwise
+ """
+ project_id = request.environ["nova.context"].project_id
+ if project_id in request.url:
+ return project_id
+ return ''
+
def _get_links(self, request, identifier, collection_name):
return [{
"rel": "self",
@@ -472,7 +482,7 @@ class ViewBuilder(object):
params["marker"] = identifier
prefix = self._update_compute_link_prefix(request.application_url)
url = os.path.join(prefix,
- request.environ["nova.context"].project_id,
+ self._get_project_id(request),
collection_name)
return "%s?%s" % (url, dict_to_query_str(params))
@@ -480,7 +490,7 @@ class ViewBuilder(object):
"""Return an href string pointing to this object."""
prefix = self._update_compute_link_prefix(request.application_url)
return os.path.join(prefix,
- request.environ["nova.context"].project_id,
+ self._get_project_id(request),
collection_name,
str(identifier))
@@ -489,7 +499,7 @@ class ViewBuilder(object):
base_url = remove_version_from_href(request.application_url)
base_url = self._update_compute_link_prefix(base_url)
return os.path.join(base_url,
- request.environ["nova.context"].project_id,
+ self._get_project_id(request),
collection_name,
str(identifier))