Allow sink to create multiple entries per instance
There are a few situations where this may be useful, for example simultaneous creation of <hostname>.example.org and <instance-id>.example.org The code already existed to clean up multiple entries for a given host, so this change is pretty simple. Co-Authored-By: Zhang Gengyuan <stanzgy@gmail.com> Change-Id: I8a410107d970d079f757f9d22c44485856239517
This commit is contained in:
parent
48e96e1b70
commit
2a37061e57
@ -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):
|
||||
|
@ -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')
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
||||
|
||||
|
@ -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'])
|
||||
|
@ -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'),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user