Implement ceilometer client plugin
This moves the client creation code out of Clients._ceilometer() into its own client plugin. Ceilometer is an integrated project, and python-ceilometerclient is a dependency, so the import is now mandatory. Change-Id: Id4961c4d9678d7bfe3739128843c41921cc8a34b
This commit is contained in:
parent
e247c291ed
commit
bbea94577f
|
@ -11,7 +11,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometerclient import client as ceilometerclient
|
||||
from heatclient import client as heatclient
|
||||
from oslo.config import cfg
|
||||
from stevedore import extension
|
||||
|
@ -124,26 +123,6 @@ class OpenStackClients(object):
|
|||
'Replace with calls to client("ceilometer")')
|
||||
return self.client('ceilometer')
|
||||
|
||||
def _ceilometer(self):
|
||||
|
||||
con = self.context
|
||||
endpoint_type = self._get_client_option('ceilometer', 'endpoint_type')
|
||||
endpoint = self.url_for(service_type='metering',
|
||||
endpoint_type=endpoint_type)
|
||||
args = {
|
||||
'auth_url': con.auth_url,
|
||||
'service_type': 'metering',
|
||||
'project_id': con.tenant,
|
||||
'token': lambda: self.auth_token,
|
||||
'endpoint_type': endpoint_type,
|
||||
'ca_file': self._get_client_option('ceilometer', 'ca_file'),
|
||||
'cert_file': self._get_client_option('ceilometer', 'cert_file'),
|
||||
'key_file': self._get_client_option('ceilometer', 'key_file'),
|
||||
'insecure': self._get_client_option('ceilometer', 'insecure')
|
||||
}
|
||||
|
||||
return ceilometerclient.Client('2', endpoint, **args)
|
||||
|
||||
def _get_client_option(self, client, option):
|
||||
try:
|
||||
group_name = 'clients_' + client
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometerclient import client as cc
|
||||
|
||||
from heat.engine.clients import client_plugin
|
||||
|
||||
|
||||
class CeilometerClientPlugin(client_plugin.ClientPlugin):
|
||||
|
||||
def _create(self):
|
||||
|
||||
con = self.context
|
||||
endpoint_type = self._get_client_option('ceilometer', 'endpoint_type')
|
||||
endpoint = self.url_for(service_type='metering',
|
||||
endpoint_type=endpoint_type)
|
||||
args = {
|
||||
'auth_url': con.auth_url,
|
||||
'service_type': 'metering',
|
||||
'project_id': con.tenant,
|
||||
'token': lambda: self.auth_token,
|
||||
'endpoint_type': endpoint_type,
|
||||
'ca_file': self._get_client_option('ceilometer', 'ca_file'),
|
||||
'cert_file': self._get_client_option('ceilometer', 'cert_file'),
|
||||
'key_file': self._get_client_option('ceilometer', 'key_file'),
|
||||
'insecure': self._get_client_option('ceilometer', 'insecure')
|
||||
}
|
||||
|
||||
return cc.Client('2', endpoint, **args)
|
|
@ -285,7 +285,7 @@ class WatchRule(object):
|
|||
sample['resource_id'] = dims.get('InstanceId')
|
||||
LOG.debug('new sample:%(k)s data:%(sample)s' % {
|
||||
'k': k, 'sample': sample})
|
||||
clients.ceilometer().samples.create(**sample)
|
||||
clients.client('ceilometer').samples.create(**sample)
|
||||
|
||||
def create_watch_data(self, data):
|
||||
if self.state == self.CEILOMETER_CONTROLLED:
|
||||
|
|
|
@ -14,25 +14,23 @@
|
|||
import copy
|
||||
import json
|
||||
|
||||
from ceilometerclient import exc as ceilometerclient_exc
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.engine import clients
|
||||
from heat.engine.clients.os import ceilometer
|
||||
from heat.engine import parser
|
||||
from heat.engine.properties import schemata
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.ceilometer import alarm
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
from heat.openstack.common.importutils import try_import
|
||||
from heat.tests.common import HeatTestCase
|
||||
from heat.tests import generic_resource
|
||||
from heat.tests import utils
|
||||
|
||||
ceilometerclient = try_import('ceilometerclient.v2')
|
||||
|
||||
alarm_template = '''
|
||||
{
|
||||
|
@ -126,7 +124,6 @@ class FakeCeilometerClient(object):
|
|||
alarms = FakeCeilometerAlarms()
|
||||
|
||||
|
||||
@testtools.skipIf(ceilometerclient is None, 'ceilometerclient unavailable')
|
||||
class CeilometerAlarmTest(HeatTestCase):
|
||||
def setUp(self):
|
||||
super(CeilometerAlarmTest, self).setUp()
|
||||
|
@ -336,7 +333,7 @@ class CeilometerAlarmTest(HeatTestCase):
|
|||
self.stack = self.create_stack(template=json.dumps(t))
|
||||
self.m.StubOutWithMock(self.fa.alarms, 'delete')
|
||||
self.fa.alarms.delete('foo').AndRaise(
|
||||
alarm.ceilometerclient_exc.HTTPNotFound())
|
||||
ceilometerclient_exc.HTTPNotFound())
|
||||
|
||||
self.m.ReplayAll()
|
||||
self.stack.create()
|
||||
|
@ -348,16 +345,15 @@ class CeilometerAlarmTest(HeatTestCase):
|
|||
self.m.VerifyAll()
|
||||
|
||||
|
||||
@testtools.skipIf(ceilometerclient is None, 'ceilometerclient unavailable')
|
||||
class CombinationAlarmTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CombinationAlarmTest, self).setUp()
|
||||
self.fc = FakeCeilometerClient()
|
||||
self.m.StubOutWithMock(clients.OpenStackClients, '_ceilometer')
|
||||
self.m.StubOutWithMock(ceilometer.CeilometerClientPlugin, '_create')
|
||||
|
||||
def create_alarm(self):
|
||||
clients.OpenStackClients._ceilometer().AndReturn(
|
||||
ceilometer.CeilometerClientPlugin._create().AndReturn(
|
||||
self.fc)
|
||||
self.m.StubOutWithMock(self.fc.alarms, 'create')
|
||||
self.fc.alarms.create(
|
||||
|
@ -454,7 +450,7 @@ class CombinationAlarmTest(HeatTestCase):
|
|||
rsrc = self.create_alarm()
|
||||
self.m.StubOutWithMock(self.fc.alarms, 'delete')
|
||||
self.fc.alarms.delete('foo').AndRaise(
|
||||
alarm.ceilometerclient_exc.HTTPNotFound())
|
||||
ceilometerclient_exc.HTTPNotFound())
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
|
|
|
@ -38,6 +38,7 @@ oslo.config.opts =
|
|||
heat.common.wsgi = heat.common.wsgi:list_opts
|
||||
|
||||
heat.clients =
|
||||
ceilometer = heat.engine.clients.os.ceilometer:CeilometerClientPlugin
|
||||
cinder = heat.engine.clients.os.cinder:CinderClientPlugin
|
||||
glance = heat.engine.clients.os.glance:GlanceClientPlugin
|
||||
nova = heat.engine.clients.os.nova:NovaClientPlugin
|
||||
|
|
Loading…
Reference in New Issue