diff options
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 33 | ||||
| -rw-r--r-- | nova/api/openstack/compute/views/images.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/compute/views/versions.py | 8 |
3 files changed, 26 insertions, 22 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index c3d0c2f94..a9ffebaa8 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -33,11 +33,21 @@ from nova.openstack.common import cfg from nova.openstack.common import log as logging from nova import quota - -LOG = logging.getLogger(__name__) +osapi_opts = [ + cfg.StrOpt('osapi_compute_link_prefix', + default=None, + help='Base URL that will be presented to users in links ' + 'to the OpenStack Compute API'), + cfg.StrOpt('osapi_glance_link_prefix', + default=None, + help='Base URL that will be presented to users in links ' + 'to glance resources'), +] CONF = cfg.CONF -CONF.import_opt('osapi_compute_link_prefix', 'nova.config') +CONF.register_opts(osapi_opts) CONF.import_opt('osapi_max_limit', 'nova.config') + +LOG = logging.getLogger(__name__) QUOTAS = quota.QUOTAS @@ -444,8 +454,7 @@ class ViewBuilder(object): """Return href string with proper limit and marker params.""" params = request.params.copy() params["marker"] = identifier - prefix = self._update_link_prefix(request.application_url, - CONF.osapi_compute_link_prefix) + prefix = self._update_compute_link_prefix(request.application_url) url = os.path.join(prefix, request.environ["nova.context"].project_id, collection_name) @@ -453,8 +462,7 @@ class ViewBuilder(object): def _get_href_link(self, request, identifier, collection_name): """Return an href string pointing to this object.""" - prefix = self._update_link_prefix(request.application_url, - CONF.osapi_compute_link_prefix) + prefix = self._update_compute_link_prefix(request.application_url) return os.path.join(prefix, request.environ["nova.context"].project_id, collection_name, @@ -463,8 +471,7 @@ class ViewBuilder(object): def _get_bookmark_link(self, request, identifier, collection_name): """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, - CONF.osapi_compute_link_prefix) + base_url = self._update_compute_link_prefix(base_url) return os.path.join(base_url, request.environ["nova.context"].project_id, collection_name, @@ -501,3 +508,11 @@ class ViewBuilder(object): prefix_parts = list(urlparse.urlsplit(prefix)) url_parts[0:2] = prefix_parts[0:2] return urlparse.urlunsplit(url_parts) + + def _update_glance_link_prefix(self, orig_url): + return self._update_link_prefix(orig_url, + CONF.osapi_glance_link_prefix) + + def _update_compute_link_prefix(self, orig_url): + return self._update_link_prefix(orig_url, + CONF.osapi_compute_link_prefix) diff --git a/nova/api/openstack/compute/views/images.py b/nova/api/openstack/compute/views/images.py index 84326f356..13662c546 100644 --- a/nova/api/openstack/compute/views/images.py +++ b/nova/api/openstack/compute/views/images.py @@ -18,12 +18,8 @@ import os.path from nova.api.openstack import common -from nova.openstack.common import cfg from nova import utils -CONF = cfg.CONF -CONF.import_opt('osapi_glance_link_prefix', 'nova.config') - class ViewBuilder(common.ViewBuilder): @@ -122,8 +118,7 @@ class ViewBuilder(common.ViewBuilder): def _get_alternate_link(self, request, identifier): """Create an alternate link for a specific image id.""" glance_url = utils.generate_glance_url() - glance_url = self._update_link_prefix(glance_url, - CONF.osapi_glance_link_prefix) + glance_url = self._update_glance_link_prefix(glance_url) return os.path.join(glance_url, request.environ["nova.context"].project_id, self._collection_name, diff --git a/nova/api/openstack/compute/views/versions.py b/nova/api/openstack/compute/views/versions.py index a8c4286dd..105921ff0 100644 --- a/nova/api/openstack/compute/views/versions.py +++ b/nova/api/openstack/compute/views/versions.py @@ -19,11 +19,6 @@ import copy import os from nova.api.openstack import common -from nova.openstack.common import cfg - - -CONF = cfg.CONF -CONF.import_opt('osapi_compute_link_prefix', 'nova.config') def get_view_builder(req): @@ -93,8 +88,7 @@ class ViewBuilder(common.ViewBuilder): def generate_href(self, path=None): """Create an url that refers to a specific version_number.""" - prefix = self._update_link_prefix(self.base_url, - CONF.osapi_compute_link_prefix) + prefix = self._update_compute_link_prefix(self.base_url) version_number = 'v2' if path: path = path.strip('/') |
