Use configured endpoint_type everywhere

It seems there has been some usage forgotten in pollsters.

Change-Id: I19c3b05377d484a7c50cd4534f26405ea67f1232
This commit is contained in:
Julien Danjou 2013-07-24 12:49:11 +02:00
parent a4b1b54a48
commit 2c0dd5d079
4 changed files with 11 additions and 13 deletions

View File

@ -15,6 +15,7 @@
# under the License. # under the License.
import datetime import datetime
from oslo.config import cfg
from keystoneclient import exceptions from keystoneclient import exceptions
import requests import requests
@ -56,9 +57,9 @@ class _Base(plugin.CentralPollster):
@staticmethod @staticmethod
def get_kwapi_client(ksclient): def get_kwapi_client(ksclient):
"""Returns a KwapiClient configured with the proper url and token.""" """Returns a KwapiClient configured with the proper url and token."""
endpoint = ksclient.service_catalog.url_for(service_type='energy', endpoint = ksclient.service_catalog.url_for(
endpoint_type='internalURL' service_type='energy',
) endpoint_type=cfg.CONF.service_credentials.os_endpoint_type)
return KwapiClient(endpoint, ksclient.auth_token) return KwapiClient(endpoint, ksclient.auth_token)
CACHE_KEY_PROBE = 'kwapi.probes' CACHE_KEY_PROBE = 'kwapi.probes'

View File

@ -22,6 +22,7 @@ from __future__ import absolute_import
import itertools import itertools
import glanceclient import glanceclient
from oslo.config import cfg
from ceilometer import counter from ceilometer import counter
from ceilometer.openstack.common import timeutils from ceilometer.openstack.common import timeutils
@ -34,7 +35,7 @@ class _Base(plugin.PollsterBase):
def get_glance_client(ksclient): def get_glance_client(ksclient):
endpoint = ksclient.service_catalog.url_for( endpoint = ksclient.service_catalog.url_for(
service_type='image', service_type='image',
endpoint_type='internalURL') endpoint_type=cfg.CONF.service_credentials.os_endpoint_type)
# hard-code v1 glance API version selection while v2 API matures # hard-code v1 glance API version selection while v2 API matures
return glanceclient.Client('1', endpoint, return glanceclient.Client('1', endpoint,

View File

@ -62,7 +62,7 @@ class _Base(plugin.PollsterBase):
try: try:
endpoint = ksclient.service_catalog.url_for( endpoint = ksclient.service_catalog.url_for(
service_type='object-store', service_type='object-store',
endpoint_type='adminURL') endpoint_type=cfg.CONF.service_credentials.os_endpoint_type)
except exceptions.EndpointNotFound: except exceptions.EndpointNotFound:
LOG.debug(_("Swift endpoint not found")) LOG.debug(_("Swift endpoint not found"))
raise StopIteration() raise StopIteration()
@ -75,14 +75,7 @@ class _Base(plugin.PollsterBase):
def _neaten_url(endpoint, tenant_id): def _neaten_url(endpoint, tenant_id):
"""Transform the registered url to standard and valid format. """Transform the registered url to standard and valid format.
""" """
return urljoin(endpoint, '/v1/' + cfg.CONF.reseller_prefix + tenant_id)
path = 'v1/' + cfg.CONF.reseller_prefix + tenant_id
# remove the tail '/' of the endpoint.
if endpoint.endswith('/'):
endpoint = endpoint[:-1]
return urljoin(endpoint, path)
class ObjectsPollster(_Base): class ObjectsPollster(_Base):

View File

@ -120,6 +120,9 @@ class TestSwiftPollster(base.TestCase):
self.assertEqual(standard_url, self.assertEqual(standard_url,
swift._Base._neaten_url(test_endpoint + '/v1', swift._Base._neaten_url(test_endpoint + '/v1',
test_tenant_id)) test_tenant_id))
self.assertEqual(standard_url,
swift._Base._neaten_url(standard_url,
test_tenant_id))
def test_metering(self): def test_metering(self):
self.stubs.Set(self.factory, '_iter_accounts', self.stubs.Set(self.factory, '_iter_accounts',