Browse Source

Add aodh client plugin

Blueprint migrate-to-use-aodh-for-alarms

Change-Id: I3f506dcaa2753bb65c8e6731c3b2db33f15859f6
changes/44/325044/12
huangtianhua 5 years ago
parent
commit
690b1a4887
  1. 1
      README.rst
  2. 4
      heat/common/config.py
  3. 50
      heat/engine/clients/os/aodh.py
  4. 24
      heat/tests/clients/test_aodh_client.py
  5. 25
      heat/tests/clients/test_clients.py
  6. 1
      requirements.txt
  7. 1
      setup.cfg

1
README.rst

@ -38,6 +38,7 @@ We have integration with
* https://git.openstack.org/cgit/openstack/python-swiftclient (s3)
* https://git.openstack.org/cgit/openstack/python-neutronclient (networking)
* https://git.openstack.org/cgit/openstack/python-ceilometerclient (metering)
* https://git.openstack.org/cgit/openstack/python-aodhclient (alarming service)
* https://git.openstack.org/cgit/openstack/python-cinderclient (storage service)
* https://git.openstack.org/cgit/openstack/python-glanceclient (image service)
* https://git.openstack.org/cgit/openstack/python-troveclient (database as a Service)

4
heat/common/config.py

@ -380,8 +380,8 @@ def list_opts():
yield profiler.list_opts()[0]
yield 'clients', default_clients_opts
for client in ('barbican', 'ceilometer', 'cinder', 'designate', 'glance',
'heat', 'keystone', 'magnum', 'manila', 'mistral',
for client in ('aodh', 'barbican', 'ceilometer', 'cinder', 'designate',
'glance', 'heat', 'keystone', 'magnum', 'manila', 'mistral',
'monasca', 'neutron', 'nova', 'sahara', 'senlin', 'swift',
'trove', 'zaqar'
):

50
heat/engine/clients/os/aodh.py

@ -0,0 +1,50 @@
#
# 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 aodhclient import client as ac
from aodhclient import exceptions
from heat.engine.clients import client_plugin
CLIENT_NAME = 'aodh'
class AodhClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions
service_types = [ALARMING] = ['alarming']
supported_versions = [V2] = ['2']
default_version = V2
def _create(self, version=None):
interface = self._get_client_option(CLIENT_NAME, 'endpoint_type')
self._keystone_session.auth = self.context.auth_plugin
return ac.Client(
version,
session=self._keystone_session,
interface=interface,
service_type=self.ALARMING)
def is_not_found(self, ex):
return isinstance(ex, exceptions.NotFound)
def is_over_limit(self, ex):
return isinstance(ex, exceptions.OverLimit)
def is_conflict(self, ex):
return isinstance(ex, exceptions.Conflict)

24
heat/tests/clients/test_aodh_client.py

@ -0,0 +1,24 @@
#
# 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 heat.tests import common
from heat.tests import utils
class AodhClientPluginTest(common.HeatTestCase):
def test_create(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('aodh')
client = plugin.client()
self.assertIsNotNone(client.alarm)

25
heat/tests/clients/test_clients.py

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from aodhclient import exceptions as aodh_exc
from ceilometerclient import exc as ceil_exc
from ceilometerclient.openstack.common.apiclient import exceptions as c_a_exc
from cinderclient import exceptions as cinder_exc
@ -483,6 +484,30 @@ class TestIsNotFound(common.HeatTestCase):
plugin='ceilometer',
exception=lambda: ceil_exc.HTTPConflict(),
)),
('aodh_not_found', dict(
is_not_found=True,
is_over_limit=False,
is_client_exception=True,
is_conflict=False,
plugin='aodh',
exception=lambda: aodh_exc.NotFound('not found'),
)),
('aodh_overlimit', dict(
is_not_found=False,
is_over_limit=True,
is_client_exception=True,
is_conflict=False,
plugin='aodh',
exception=lambda: aodh_exc.OverLimit('over'),
)),
('aodh_conflict', dict(
is_not_found=False,
is_over_limit=False,
is_client_exception=True,
is_conflict=True,
plugin='aodh',
exception=lambda: aodh_exc.Conflict('conflict'),
)),
('cinder_not_found', dict(
is_not_found=True,
is_over_limit=False,

1
requirements.txt

@ -31,6 +31,7 @@ osprofiler>=1.3.0 # Apache-2.0
oslo.versionedobjects>=1.9.1 # Apache-2.0
PasteDeploy>=1.5.0 # MIT
pycrypto>=2.6 # Public Domain
aodhclient>=0.5.0 # Apache-2.0
python-barbicanclient>=4.0.0 # Apache-2.0
python-ceilometerclient>=2.2.1 # Apache-2.0
python-cinderclient!=1.7.0,!=1.7.1,>=1.6.0 # Apache-2.0

1
setup.cfg

@ -57,6 +57,7 @@ oslo.config.opts.defaults =
heat.common.config = heat.common.config:set_config_defaults
heat.clients =
aodh = heat.engine.clients.os.aodh:AodhClientPlugin
barbican = heat.engine.clients.os.barbican:BarbicanClientPlugin
ceilometer = heat.engine.clients.os.ceilometer:CeilometerClientPlugin
cinder = heat.engine.clients.os.cinder:CinderClientPlugin

Loading…
Cancel
Save