diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-02-22 12:41:12 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-02-22 12:41:12 +0000 |
commit | 064081d46dfc3f1aacefbd5d45802944ef72f27b (patch) | |
tree | ec1cbe7a73e73cfca8de7a6db1fa5dec7a8ffb40 | |
parent | 517ec9531a610843117ecfd05a987e8f34494eba (diff) | |
parent | 8059a67f0034760beb4ada51a4921f554e2626cd (diff) | |
download | designate-064081d46dfc3f1aacefbd5d45802944ef72f27b.tar.gz |
Merge "Add the handler plugin example to the contrib folder"
11 files changed, 213 insertions, 0 deletions
diff --git a/contrib/designate-ext-samplehandler/.gitignore b/contrib/designate-ext-samplehandler/.gitignore new file mode 100644 index 00000000..88f0520c --- /dev/null +++ b/contrib/designate-ext-samplehandler/.gitignore @@ -0,0 +1,22 @@ +*.pyc +*.dat +TAGS +*.egg +*.egg-info +build +.coverage +.tox +cover +venv +.venv +*.sublime-workspace +*.sqlite +var/* +etc/*.conf +etc/*.ini +AUTHORS +ChangeLog +doc/source/api/* +doc/build/* +dist +designate_ext_samplehandler/versioninfo diff --git a/contrib/designate-ext-samplehandler/MANIFEST.in b/contrib/designate-ext-samplehandler/MANIFEST.in new file mode 100644 index 00000000..23d74794 --- /dev/null +++ b/contrib/designate-ext-samplehandler/MANIFEST.in @@ -0,0 +1,11 @@ +include AUTHORS +include ChangeLog +include designate_ext_samplehandler/versioninfo +include *.txt *.ini *.cfg *.rst *.md + +exclude .gitignore +exclude .gitreview +exclude *.sublime-project + +global-exclude *.pyc + diff --git a/contrib/designate-ext-samplehandler/README.rst b/contrib/designate-ext-samplehandler/README.rst new file mode 100644 index 00000000..f055c9ee --- /dev/null +++ b/contrib/designate-ext-samplehandler/README.rst @@ -0,0 +1,4 @@ +Sample Designate Notification Handler Extension +=============================================== + +This repo provides a sample plugin for a custom notification hanler. diff --git a/contrib/designate-ext-samplehandler/designate_ext_samplehandler/__init__.py b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/__init__.py diff --git a/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/__init__.py b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/__init__.py diff --git a/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/sample.py b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/sample.py new file mode 100644 index 00000000..e651a3f4 --- /dev/null +++ b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/notification_handler/sample.py @@ -0,0 +1,76 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# Author: Kiall Mac Innes <kiall@hp.com> +# +# 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 oslo.config import cfg +from designate.openstack.common import log as logging +from designate.notification_handler.base import NotificationHandler + +LOG = logging.getLogger(__name__) + +# Setup a config group +cfg.CONF.register_group(cfg.OptGroup( + name='handler:sample', + title="Configuration for Sample Notification Handler" +)) + +# Setup the config options +cfg.CONF.register_opts([ + cfg.StrOpt('control-exchange', default='nova'), + cfg.ListOpt('notification-topics', default=['designate']), + cfg.StrOpt('domain-name', default='example.org.'), + cfg.StrOpt('domain-id', default='12345'), +], group='handler:sample') + + +class SampleHandler(NotificationHandler): + """ Sample Handler """ + __plugin_name__ = 'sample' + + def get_exchange_topics(self): + """ + Return a tuple of (exchange, [topics]) this handler wants to receive + events from. + """ + exchange = cfg.CONF['handler:sample'].control_exchange + + notification_topics = cfg.CONF['handler:sample'].notification_topics + notification_topics = [t + ".info" for t in notification_topics] + + return (exchange, notification_topics) + + def get_event_types(self): + return [ + 'compute.instance.create.end' + ] + + def process_notification(self, event_type, payload): + # Do something with the notification.. e.g: + domain_id = cfg.CONF['handler:sample'].domain_id + domain_name = cfg.CONF['handler:sample'].domain_name + + hostname = '%s.%s' % (payload['instance_id'], domain_name) + + for fixed_ip in payload['fixed_ips']: + if fixed_ip['version'] == 4: + self.central_api.create_record(domain_id, + type='A', + name=hostname, + data=fixed_ip['address']) + + elif fixed_ip['version'] == 6: + self.central_api.create_record(domain_id, + type='AAAA', + name=hostname, + data=fixed_ip['address']) diff --git a/contrib/designate-ext-samplehandler/designate_ext_samplehandler/version.py b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/version.py new file mode 100644 index 00000000..3f8c78c2 --- /dev/null +++ b/contrib/designate-ext-samplehandler/designate_ext_samplehandler/version.py @@ -0,0 +1,18 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# Author: Kiall Mac Innes <kiall@hp.com> +# +# 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. +import pbr.version + +version_info = pbr.version.VersionInfo('designate-ext-samplehandler') diff --git a/contrib/designate-ext-samplehandler/requirements.txt b/contrib/designate-ext-samplehandler/requirements.txt new file mode 100644 index 00000000..e3296eca --- /dev/null +++ b/contrib/designate-ext-samplehandler/requirements.txt @@ -0,0 +1,2 @@ +pbr>=0.6,<1.0 +-e git+https://github.com/stackforge/designate.git#egg=designate diff --git a/contrib/designate-ext-samplehandler/setup.cfg b/contrib/designate-ext-samplehandler/setup.cfg new file mode 100644 index 00000000..fd27a608 --- /dev/null +++ b/contrib/designate-ext-samplehandler/setup.cfg @@ -0,0 +1,54 @@ +[metadata] +name = designate-ext-samplehandler +version = 2013.2 +summary = Sample Designate Handler Extension +description-file = + README.rst +author = Kiall Mac Innes +author-email = kiall@hp.com +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 2.6 + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[files] +packages = + designate_ext_samplehandler + +[entry_points] +designate.notification_handler = + sample = designate_ext_samplehandler.notification_handler.sample:SampleHandler + +[build_sphinx] +all_files = 1 +build-dir = doc/build +source-dir = doc/source + +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + +[compile_catalog] +directory = designate-ext-samplehandler/locale +domain = designate-ext-samplehandler + +[update_catalog] +domain = designate-ext-samplehandler +output_dir = designate-ext-samplehandler/locale +input_file = designate-ext-samplehandler/locale/designate-ext-samplehandler.pot + +[extract_messages] +keywords = _ gettext ngettext l_ lazy_gettext +mapping_file = babel.cfg +output_file = designate-ext-samplehandler/locale/designate-ext-samplehandler.pot diff --git a/contrib/designate-ext-samplehandler/setup.py b/contrib/designate-ext-samplehandler/setup.py new file mode 100755 index 00000000..70c2b3f3 --- /dev/null +++ b/contrib/designate-ext-samplehandler/setup.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/contrib/designate-ext-samplehandler/test-requirements.txt b/contrib/designate-ext-samplehandler/test-requirements.txt new file mode 100644 index 00000000..5c9111ef --- /dev/null +++ b/contrib/designate-ext-samplehandler/test-requirements.txt @@ -0,0 +1,4 @@ +flake8==2.0 +hacking>=0.8.0,<0.9 +pep8==1.4.5 +pyflakes>=0.7.2,<0.7.4 |