new service catalog semantics
This commit is contained in:
parent
2b0d82c05c
commit
881427de9d
novaclient
@ -139,7 +139,7 @@ class HTTPClient(httplib2.Http):
|
|||||||
def delete(self, url, **kwargs):
|
def delete(self, url, **kwargs):
|
||||||
return self._cs_request(url, 'DELETE', **kwargs)
|
return self._cs_request(url, 'DELETE', **kwargs)
|
||||||
|
|
||||||
def _extract_service_catalog(self, url, resp, body):
|
def _extract_service_catalog(self, url, resp, body, extract_token=True):
|
||||||
"""See what the auth service told us and process the response.
|
"""See what the auth service told us and process the response.
|
||||||
We may get redirected to another site, fail or actually get
|
We may get redirected to another site, fail or actually get
|
||||||
back a service catalog with a token and our endpoints."""
|
back a service catalog with a token and our endpoints."""
|
||||||
@ -149,8 +149,9 @@ class HTTPClient(httplib2.Http):
|
|||||||
self.auth_url = url
|
self.auth_url = url
|
||||||
self.service_catalog = \
|
self.service_catalog = \
|
||||||
service_catalog.ServiceCatalog(body)
|
service_catalog.ServiceCatalog(body)
|
||||||
self.auth_token = self.service_catalog.get_token()
|
|
||||||
|
|
||||||
|
if extract_token:
|
||||||
|
self.auth_token = self.service_catalog.get_token()
|
||||||
self.management_url = self.service_catalog.url_for(
|
self.management_url = self.service_catalog.url_for(
|
||||||
attr='region',
|
attr='region',
|
||||||
filter_value=self.region_name)
|
filter_value=self.region_name)
|
||||||
@ -184,7 +185,7 @@ class HTTPClient(httplib2.Http):
|
|||||||
_logger.debug("Using Endpoint URL: %s" % url)
|
_logger.debug("Using Endpoint URL: %s" % url)
|
||||||
resp, body = self.request(url, "GET",
|
resp, body = self.request(url, "GET",
|
||||||
headers={'X-Auth_Token': self.auth_token})
|
headers={'X-Auth_Token': self.auth_token})
|
||||||
return self._extract_service_catalog(url, resp, body)
|
return self._extract_service_catalog(url, resp, body, extract_token=False)
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
magic_tuple = urlparse.urlsplit(self.auth_url)
|
magic_tuple = urlparse.urlsplit(self.auth_url)
|
||||||
@ -198,9 +199,9 @@ class HTTPClient(httplib2.Http):
|
|||||||
self.version = part
|
self.version = part
|
||||||
break
|
break
|
||||||
|
|
||||||
# TODO(sandy): Assume admin endpoint is service endpoint+1 for now.
|
# TODO(sandy): Assume admin endpoint is 35357 for now.
|
||||||
# Ideally this is going to have to be provided by the admin.
|
# Ideally this is going to have to be provided by the service catalog.
|
||||||
new_netloc = netloc.replace(':%d' % port, ':%d' % (port + 1))
|
new_netloc = netloc.replace(':%d' % port, ':%d' % (35357))
|
||||||
admin_url = urlparse.urlunsplit(
|
admin_url = urlparse.urlunsplit(
|
||||||
(scheme, new_netloc, path, query, frag))
|
(scheme, new_netloc, path, query, frag))
|
||||||
|
|
||||||
|
@ -33,6 +33,15 @@ class ServiceCatalog(object):
|
|||||||
"""Fetch the public URL from the Compute service for
|
"""Fetch the public URL from the Compute service for
|
||||||
a particular endpoint attribute. If none given, return
|
a particular endpoint attribute. If none given, return
|
||||||
the first. See tests for sample service catalog."""
|
the first. See tests for sample service catalog."""
|
||||||
|
if 'endpoints' in self.catalog:
|
||||||
|
# We have a bastardized service catalog. Treat it special. :/
|
||||||
|
for endpoint in self.catalog['endpoints']:
|
||||||
|
if not filter_value or endpoint[attr] == filter_value:
|
||||||
|
return endpoint[endpoint_type]
|
||||||
|
|
||||||
|
if not 'serviceCatalog' in self.catalog['access']:
|
||||||
|
return None
|
||||||
|
|
||||||
catalog = self.catalog['access']['serviceCatalog']
|
catalog = self.catalog['access']['serviceCatalog']
|
||||||
|
|
||||||
for service in catalog:
|
for service in catalog:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user