diff --git a/novaclient/client.py b/novaclient/client.py index c136722ec..af84bcf0a 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -139,7 +139,7 @@ class HTTPClient(httplib2.Http): def delete(self, url, **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. We may get redirected to another site, fail or actually get back a service catalog with a token and our endpoints.""" @@ -149,8 +149,9 @@ class HTTPClient(httplib2.Http): self.auth_url = url self.service_catalog = \ 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( attr='region', filter_value=self.region_name) @@ -184,7 +185,7 @@ class HTTPClient(httplib2.Http): _logger.debug("Using Endpoint URL: %s" % url) resp, body = self.request(url, "GET", 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): magic_tuple = urlparse.urlsplit(self.auth_url) @@ -198,9 +199,9 @@ class HTTPClient(httplib2.Http): self.version = part break - # TODO(sandy): Assume admin endpoint is service endpoint+1 for now. - # Ideally this is going to have to be provided by the admin. - new_netloc = netloc.replace(':%d' % port, ':%d' % (port + 1)) + # TODO(sandy): Assume admin endpoint is 35357 for now. + # Ideally this is going to have to be provided by the service catalog. + new_netloc = netloc.replace(':%d' % port, ':%d' % (35357)) admin_url = urlparse.urlunsplit( (scheme, new_netloc, path, query, frag)) diff --git a/novaclient/service_catalog.py b/novaclient/service_catalog.py index d342ef916..5e7fe47be 100644 --- a/novaclient/service_catalog.py +++ b/novaclient/service_catalog.py @@ -33,6 +33,15 @@ class ServiceCatalog(object): """Fetch the public URL from the Compute service for a particular endpoint attribute. If none given, return 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'] for service in catalog: