Add the handler plugin example to the contrib folder
Change-Id: Ibf25214cd02660628b0cbad20af5a33aba4bfae0
This commit is contained in:
parent
a5c865d0ae
commit
8059a67f00
22
contrib/designate-ext-samplehandler/.gitignore
vendored
Normal file
22
contrib/designate-ext-samplehandler/.gitignore
vendored
Normal file
@ -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
|
11
contrib/designate-ext-samplehandler/MANIFEST.in
Normal file
11
contrib/designate-ext-samplehandler/MANIFEST.in
Normal file
@ -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
|
||||
|
4
contrib/designate-ext-samplehandler/README.rst
Normal file
4
contrib/designate-ext-samplehandler/README.rst
Normal file
@ -0,0 +1,4 @@
|
||||
Sample Designate Notification Handler Extension
|
||||
===============================================
|
||||
|
||||
This repo provides a sample plugin for a custom notification hanler.
|
@ -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'])
|
@ -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')
|
2
contrib/designate-ext-samplehandler/requirements.txt
Normal file
2
contrib/designate-ext-samplehandler/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pbr>=0.6,<1.0
|
||||
-e git+https://github.com/stackforge/designate.git#egg=designate
|
54
contrib/designate-ext-samplehandler/setup.cfg
Normal file
54
contrib/designate-ext-samplehandler/setup.cfg
Normal file
@ -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
|
22
contrib/designate-ext-samplehandler/setup.py
Executable file
22
contrib/designate-ext-samplehandler/setup.py
Executable file
@ -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)
|
@ -0,0 +1,4 @@
|
||||
flake8==2.0
|
||||
hacking>=0.8.0,<0.9
|
||||
pep8==1.4.5
|
||||
pyflakes>=0.7.2,<0.7.4
|
Loading…
Reference in New Issue
Block a user