diff --git a/designate/notification_handler/base.py b/designate/notification_handler/base.py index f43985aad..76b68dbaf 100644 --- a/designate/notification_handler/base.py +++ b/designate/notification_handler/base.py @@ -87,8 +87,6 @@ class NotificationHandler(ExtensionPlugin): class BaseAddressHandler(NotificationHandler): - default_format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s' - def _get_ip_data(self, addr_dict): ip = addr_dict['address'] version = addr_dict['version'] @@ -105,9 +103,6 @@ class BaseAddressHandler(NotificationHandler): data["octet%s" % i] = ip_data[i] return data - def _get_format(self): - return cfg.CONF[self.name].get('format') or self.default_format - def _create(self, addresses, extra, domain_id, managed=True, resource_type=None, resource_id=None): """ @@ -141,31 +136,32 @@ class BaseAddressHandler(NotificationHandler): event_data = data.copy() event_data.update(self._get_ip_data(addr)) - recordset_values = { - 'domain_id': domain['id'], - 'name': self._get_format() % event_data, - 'type': 'A' if addr['version'] == 4 else 'AAAA'} + for fmt in cfg.CONF[self.name].get('format'): + recordset_values = { + 'domain_id': domain['id'], + 'name': fmt % event_data, + 'type': 'A' if addr['version'] == 4 else 'AAAA'} - recordset = self._find_or_create_recordset( - context, **recordset_values) + recordset = self._find_or_create_recordset( + context, **recordset_values) - record_values = { - 'data': addr['address']} + record_values = { + 'data': addr['address']} - if managed: - record_values.update({ - 'managed': managed, - 'managed_plugin_name': self.get_plugin_name(), - 'managed_plugin_type': self.get_plugin_type(), - 'managed_resource_type': resource_type, - 'managed_resource_id': resource_id}) + if managed: + record_values.update({ + 'managed': managed, + 'managed_plugin_name': self.get_plugin_name(), + 'managed_plugin_type': self.get_plugin_type(), + 'managed_resource_type': resource_type, + 'managed_resource_id': resource_id}) - LOG.debug('Creating record in %s / %s with values %r' % - (domain['id'], recordset['id'], record_values)) - self.central_api.create_record(context, - domain['id'], - recordset['id'], - Record(**record_values)) + LOG.debug('Creating record in %s / %s with values %r' % + (domain['id'], recordset['id'], record_values)) + self.central_api.create_record(context, + domain['id'], + recordset['id'], + Record(**record_values)) def _delete(self, domain_id, managed=True, resource_id=None, resource_type='instance', criterion=None): diff --git a/designate/notification_handler/neutron.py b/designate/notification_handler/neutron.py index 3690a0b5c..b147fc801 100644 --- a/designate/notification_handler/neutron.py +++ b/designate/notification_handler/neutron.py @@ -30,7 +30,8 @@ cfg.CONF.register_opts([ cfg.ListOpt('notification-topics', default=['notifications']), cfg.StrOpt('control-exchange', default='neutron'), cfg.StrOpt('domain-id', default=None), - cfg.StrOpt('format', default=None) + cfg.MultiStrOpt('format', default=[ + '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s']) ], group='handler:neutron_floatingip') diff --git a/designate/notification_handler/nova.py b/designate/notification_handler/nova.py index 73a7d0690..b696904e6 100644 --- a/designate/notification_handler/nova.py +++ b/designate/notification_handler/nova.py @@ -30,7 +30,8 @@ cfg.CONF.register_opts([ cfg.ListOpt('notification-topics', default=['notifications']), cfg.StrOpt('control-exchange', default='nova'), cfg.StrOpt('domain-id', default=None), - cfg.StrOpt('format', default=None) + cfg.MultiStrOpt('format', default=[ + '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s']) ], group='handler:nova_fixed') diff --git a/designate/tests/test_notification_handler/test_neutron.py b/designate/tests/test_notification_handler/test_neutron.py index 91ab8f195..2f4480921 100644 --- a/designate/tests/test_notification_handler/test_neutron.py +++ b/designate/tests/test_notification_handler/test_neutron.py @@ -30,6 +30,9 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): domain = self.create_domain() self.domain_id = domain['id'] self.config(domain_id=domain['id'], group='handler:neutron_floatingip') + formats = ['%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s', + '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.X.%(domain)s'] + self.config(format=formats, group='handler:neutron_floatingip') self.plugin = NeutronFloatingHandler() @@ -55,7 +58,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): records = self.central_service.find_records(self.admin_context, criterion) - self.assertEqual(3, len(records)) + self.assertEqual(4, len(records)) def test_floatingip_disassociate(self): start_event_type = 'floatingip.update.end' @@ -77,7 +80,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): records = self.central_service.find_records(self.admin_context, criterion) - self.assertEqual(3, len(records)) + self.assertEqual(4, len(records)) self.plugin.process_notification( self.admin_context, event_type, fixture['payload']) @@ -113,7 +116,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): # Ensure we start with at least 1 record, plus NS and SOA records = self.central_service.find_records(self.admin_context, criterion) - self.assertEqual(3, len(records)) + self.assertEqual(4, len(records)) self.plugin.process_notification( self.admin_context, event_type, fixture['payload']) diff --git a/designate/tests/test_notification_handler/test_nova.py b/designate/tests/test_notification_handler/test_nova.py index 0f444ce68..2a8bf221a 100644 --- a/designate/tests/test_notification_handler/test_nova.py +++ b/designate/tests/test_notification_handler/test_nova.py @@ -34,6 +34,9 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): domain = self.create_domain() self.domain_id = domain['id'] self.config(domain_id=domain['id'], group='handler:nova_fixed') + self.config(format=['%(host)s.%(domain)s', + '%(host)s.foo.%(domain)s'], + group='handler:nova_fixed') self.plugin = NovaFixedHandler() @@ -58,10 +61,10 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): records = self.central_service.find_records(self.admin_context, criterion) - self.assertEqual(3, len(records)) + self.assertEqual(4, len(records)) def test_instance_create_end_utf8(self): - self.config(format='%(display_name)s.%(domain)s', + self.config(format=['%(display_name)s.%(domain)s'], group='handler:nova_fixed') event_type = 'compute.instance.create.end' @@ -119,7 +122,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): records = self.central_service.find_records(self.admin_context, criterion) - self.assertEqual(3, len(records)) + self.assertEqual(4, len(records)) self.plugin.process_notification( self.admin_context, event_type, fixture['payload']) @@ -138,7 +141,8 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): def test_label_in_format(self): event_type = 'compute.instance.create.end' - self.config(format='%(label)s.example.com', group='handler:nova_fixed') + self.config(format=['%(label)s.example.com'], + group='handler:nova_fixed') fixture = self.get_notification_fixture('nova', event_type) with contextlib.nested( mock.patch.object(self.plugin, '_find_or_create_recordset'), diff --git a/etc/designate/designate.conf.sample b/etc/designate/designate.conf.sample index 08e128634..3149f1d34 100644 --- a/etc/designate/designate.conf.sample +++ b/etc/designate/designate.conf.sample @@ -220,6 +220,7 @@ debug = False #notification_topics = notifications #control_exchange = 'nova' #format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s' +#format = '%(hostname)s.%(domain)s' #------------------------ # Neutron Floating Handler @@ -230,6 +231,7 @@ debug = False #notification_topics = notifications #control_exchange = 'neutron' #format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s' +#format = '%(hostname)s.%(domain)s' ################################### ## Pool Manager Cache Configuration