Updating the sample handler to be compatible with mitaka/newton

Change-Id: I9440a9c7e268df346071b7d23d90ccc87345ee6d
This commit is contained in:
Erik Olof Gunnar Andersson 2016-09-17 05:40:01 +02:00
parent 2b69b54d99
commit 9648a3d1f5
2 changed files with 29 additions and 29 deletions

View File

@ -16,6 +16,7 @@
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from designate.context import DesignateContext
from designate.objects import Record from designate.objects import Record
from designate.notification_handler.base import NotificationHandler from designate.notification_handler.base import NotificationHandler
@ -32,8 +33,8 @@ cfg.CONF.register_group(cfg.OptGroup(
cfg.CONF.register_opts([ cfg.CONF.register_opts([
cfg.StrOpt('control-exchange', default='nova'), cfg.StrOpt('control-exchange', default='nova'),
cfg.ListOpt('notification-topics', default=['designate']), cfg.ListOpt('notification-topics', default=['designate']),
cfg.StrOpt('domain-name', default='example.org.'), cfg.StrOpt('zone-name', default='example.org.'),
cfg.StrOpt('domain-id', default='12345'), cfg.StrOpt('zone-id', default='12345'),
], group='handler:sample') ], group='handler:sample')
@ -46,12 +47,9 @@ class SampleHandler(NotificationHandler):
Return a tuple of (exchange, [topics]) this handler wants to receive Return a tuple of (exchange, [topics]) this handler wants to receive
events from. events from.
""" """
exchange = cfg.CONF['handler:sample'].control_exchange exchange = cfg.CONF[self.name].control_exchange
topics = [topic for topic in cfg.CONF[self.name].notification_topics]
notification_topics = cfg.CONF['handler:sample'].notification_topics return exchange, topics
notification_topics = [t + ".info" for t in notification_topics]
return (exchange, notification_topics)
def get_event_types(self): def get_event_types(self):
return [ return [
@ -60,24 +58,28 @@ class SampleHandler(NotificationHandler):
def process_notification(self, context, event_type, payload): def process_notification(self, context, event_type, payload):
# Do something with the notification.. e.g: # Do something with the notification.. e.g:
domain_id = cfg.CONF['handler:sample'].domain_id zone_id = cfg.CONF[self.name].zone_id
domain_name = cfg.CONF['handler:sample'].domain_name zone_name = cfg.CONF[self.name].zone_name
hostname = '%s.%s' % (payload['instance_id'], domain_name) record_name = '%s.%s' % (payload['instance_id'], zone_name)
context = DesignateContext().elevated()
context.all_tenants = True
# context.edit_managed_records = True
for fixed_ip in payload['fixed_ips']: for fixed_ip in payload['fixed_ips']:
if fixed_ip['version'] == 4: recordset_values = {
values = dict( 'zone_id': zone_id,
type='A', 'name': record_name,
name=hostname, 'type': 'A' if fixed_ip['version'] == 4 else 'AAAA'
data=fixed_ip['address'] }
)
self.central_api.create_record(domain_id, Record(**values))
elif fixed_ip['version'] == 6: record_values = {
values = dict( 'data': fixed_ip['address'],
type='AAAA', }
name=hostname,
data=fixed_ip['address'] recordset = self._find_or_create_recordset(context,
) **recordset_values)
self.central_api.create_record(domain_id, Record(**values))
self.central_api.create_record(context, zone_id, recordset['id'],
Record(**record_values))

View File

@ -1,6 +1,5 @@
[metadata] [metadata]
name = designate-ext-samplehandler name = designate-ext-samplehandler
version = 2013.2
summary = Sample Designate Handler Extension summary = Sample Designate Handler Extension
description-file = description-file =
README.rst README.rst
@ -22,11 +21,10 @@ setup-hooks =
pbr.hooks.setup_hook pbr.hooks.setup_hook
[files] [files]
packages = packages = designate_ext_samplehandler
designate_ext_samplehandler
[entry_points] [entry_points]
designate.notification_handler = designate.notification.handler =
sample = designate_ext_samplehandler.notification_handler.sample:SampleHandler sample = designate_ext_samplehandler.notification_handler.sample:SampleHandler
[build_sphinx] [build_sphinx]