Merge "Allow for manual setting of default service region in config"
This commit is contained in:
commit
acd690ae6c
|
@ -37,6 +37,28 @@ the site header when logged in.
|
||||||
You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of
|
You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of
|
||||||
the regions is the default one.
|
the regions is the default one.
|
||||||
|
|
||||||
|
|
||||||
|
``DEFAULT_SERVICE_REGIONS``
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
Default: ``{}``
|
||||||
|
|
||||||
|
The default service region is set on a per-endpoint basis, meaning that once
|
||||||
|
the user logs into some Keystone endpoint, if a default service region is
|
||||||
|
defined for it in this setting and exists within Keystone catalog, it will be
|
||||||
|
set as the initial service region in this endpoint. By default it is an empty
|
||||||
|
dictionary because upstream can neither predict service region names in a
|
||||||
|
specific deployment, nor tell whether this behavior is desired. The key of the
|
||||||
|
dictionary is a full url of a Keystone endpoint with version suffix, the value
|
||||||
|
is a region name.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
DEFAULT_SERVICE_REGIONS = {
|
||||||
|
OPENSTACK_KEYSTONE_URL: 'RegionOne'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
``OPENSTACK_API_VERSIONS``
|
``OPENSTACK_API_VERSIONS``
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,11 @@ def set_session_from_user(request, user):
|
||||||
|
|
||||||
def create_user_from_token(request, token, endpoint, services_region=None):
|
def create_user_from_token(request, token, endpoint, services_region=None):
|
||||||
# if the region is provided, use that, otherwise use the preferred region
|
# if the region is provided, use that, otherwise use the preferred region
|
||||||
|
default_service_regions = getattr(settings, 'DEFAULT_SERVICE_REGIONS', {})
|
||||||
|
default_service_region = default_service_regions.get(endpoint)
|
||||||
svc_region = services_region or \
|
svc_region = services_region or \
|
||||||
utils.default_services_region(token.serviceCatalog, request)
|
utils.default_services_region(token.serviceCatalog, request,
|
||||||
|
selected_region=default_service_region)
|
||||||
return User(id=token.user['id'],
|
return User(id=token.user['id'],
|
||||||
token=token,
|
token=token,
|
||||||
user=token.user['name'],
|
user=token.user['name'],
|
||||||
|
|
|
@ -375,7 +375,8 @@ def get_project_list(*args, **kwargs):
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
|
|
||||||
def default_services_region(service_catalog, request=None):
|
def default_services_region(service_catalog, request=None,
|
||||||
|
selected_region=None):
|
||||||
"""Returns the first endpoint region for first non-identity service.
|
"""Returns the first endpoint region for first non-identity service.
|
||||||
|
|
||||||
Extracted from the service catalog.
|
Extracted from the service catalog.
|
||||||
|
@ -399,8 +400,7 @@ def default_services_region(service_catalog, request=None):
|
||||||
LOG.error('No regions can be found in the service catalog.')
|
LOG.error('No regions can be found in the service catalog.')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
selected_region = None
|
if request and selected_region is None:
|
||||||
if request:
|
|
||||||
selected_region = request.COOKIES.get('services_region',
|
selected_region = request.COOKIES.get('services_region',
|
||||||
available_regions[0])
|
available_regions[0])
|
||||||
if selected_region not in available_regions:
|
if selected_region not in available_regions:
|
||||||
|
|
Loading…
Reference in New Issue