From 91b3d687d77887c59f4e31fdd457ff6b22168dc7 Mon Sep 17 00:00:00 2001 From: Philip Knouff Date: Thu, 2 Feb 2012 16:22:16 -0500 Subject: Adds flags for href prefixes bug #924090 Change-Id: I66358b3f526a5d356e11281ee32ce80e7b74d474 --- nova/api/openstack/common.py | 18 ++++++++++++++++-- nova/api/openstack/compute/views/images.py | 6 ++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index b46a6c1eb..c19b8f103 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -457,14 +457,18 @@ class ViewBuilder(object): """Return href string with proper limit and marker params.""" params = request.params.copy() params["marker"] = identifier - url = os.path.join(request.application_url, + prefix = self._update_link_prefix(request.application_url, + FLAGS.osapi_compute_link_prefix) + url = os.path.join(prefix, request.environ["nova.context"].project_id, self._collection_name) return "%s?%s" % (url, dict_to_query_str(params)) def _get_href_link(self, request, identifier): """Return an href string pointing to this object.""" - return os.path.join(request.application_url, + prefix = self._update_link_prefix(request.application_url, + FLAGS.osapi_compute_link_prefix) + return os.path.join(prefix, request.environ["nova.context"].project_id, self._collection_name, str(identifier)) @@ -472,6 +476,8 @@ class ViewBuilder(object): def _get_bookmark_link(self, request, identifier): """Create a URL that refers to a specific resource.""" base_url = remove_version_from_href(request.application_url) + base_url = self._update_link_prefix(base_url, + FLAGS.osapi_compute_link_prefix) return os.path.join(base_url, request.environ["nova.context"].project_id, self._collection_name, @@ -492,3 +498,11 @@ class ViewBuilder(object): "href": self._get_next_link(request, last_item_id), }) return links + + def _update_link_prefix(self, orig_url, prefix): + if not prefix: + return orig_url + url_parts = list(urlparse.urlsplit(orig_url)) + prefix_parts = list(urlparse.urlsplit(prefix)) + url_parts[1] = prefix_parts[1] + return urlparse.urlunsplit(url_parts) diff --git a/nova/api/openstack/compute/views/images.py b/nova/api/openstack/compute/views/images.py index 5ef1af59b..865e7df85 100644 --- a/nova/api/openstack/compute/views/images.py +++ b/nova/api/openstack/compute/views/images.py @@ -18,9 +18,13 @@ import os.path from nova.api.openstack import common +from nova import flags from nova import utils +FLAGS = flags.FLAGS + + class ViewBuilder(common.ViewBuilder): _collection_name = "images" @@ -109,6 +113,8 @@ class ViewBuilder(common.ViewBuilder): def _get_alternate_link(self, request, identifier): """Create an alternate link for a specific flavor id.""" glance_url = utils.generate_glance_url() + glance_url = self._update_link_prefix(glance_url, + FLAGS.osapi_glance_link_prefix) return os.path.join(glance_url, request.environ["nova.context"].project_id, self._collection_name, -- cgit