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):
|
class BaseAddressHandler(NotificationHandler):
|
||||||
default_format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
|
|
||||||
|
|
||||||
def _get_ip_data(self, addr_dict):
|
def _get_ip_data(self, addr_dict):
|
||||||
ip = addr_dict['address']
|
ip = addr_dict['address']
|
||||||
version = addr_dict['version']
|
version = addr_dict['version']
|
||||||
|
@ -105,9 +103,6 @@ class BaseAddressHandler(NotificationHandler):
|
||||||
data["octet%s" % i] = ip_data[i]
|
data["octet%s" % i] = ip_data[i]
|
||||||
return data
|
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,
|
def _create(self, addresses, extra, domain_id, managed=True,
|
||||||
resource_type=None, resource_id=None):
|
resource_type=None, resource_id=None):
|
||||||
"""
|
"""
|
||||||
|
@ -141,31 +136,32 @@ class BaseAddressHandler(NotificationHandler):
|
||||||
event_data = data.copy()
|
event_data = data.copy()
|
||||||
event_data.update(self._get_ip_data(addr))
|
event_data.update(self._get_ip_data(addr))
|
||||||
|
|
||||||
recordset_values = {
|
for fmt in cfg.CONF[self.name].get('format'):
|
||||||
'domain_id': domain['id'],
|
recordset_values = {
|
||||||
'name': self._get_format() % event_data,
|
'domain_id': domain['id'],
|
||||||
'type': 'A' if addr['version'] == 4 else 'AAAA'}
|
'name': fmt % event_data,
|
||||||
|
'type': 'A' if addr['version'] == 4 else 'AAAA'}
|
||||||
|
|
||||||
recordset = self._find_or_create_recordset(
|
recordset = self._find_or_create_recordset(
|
||||||
context, **recordset_values)
|
context, **recordset_values)
|
||||||
|
|
||||||
record_values = {
|
record_values = {
|
||||||
'data': addr['address']}
|
'data': addr['address']}
|
||||||
|
|
||||||
if managed:
|
if managed:
|
||||||
record_values.update({
|
record_values.update({
|
||||||
'managed': managed,
|
'managed': managed,
|
||||||
'managed_plugin_name': self.get_plugin_name(),
|
'managed_plugin_name': self.get_plugin_name(),
|
||||||
'managed_plugin_type': self.get_plugin_type(),
|
'managed_plugin_type': self.get_plugin_type(),
|
||||||
'managed_resource_type': resource_type,
|
'managed_resource_type': resource_type,
|
||||||
'managed_resource_id': resource_id})
|
'managed_resource_id': resource_id})
|
||||||
|
|
||||||
LOG.debug('Creating record in %s / %s with values %r' %
|
LOG.debug('Creating record in %s / %s with values %r' %
|
||||||
(domain['id'], recordset['id'], record_values))
|
(domain['id'], recordset['id'], record_values))
|
||||||
self.central_api.create_record(context,
|
self.central_api.create_record(context,
|
||||||
domain['id'],
|
domain['id'],
|
||||||
recordset['id'],
|
recordset['id'],
|
||||||
Record(**record_values))
|
Record(**record_values))
|
||||||
|
|
||||||
def _delete(self, domain_id, managed=True, resource_id=None,
|
def _delete(self, domain_id, managed=True, resource_id=None,
|
||||||
resource_type='instance', criterion=None):
|
resource_type='instance', criterion=None):
|
||||||
|
|
|
@ -30,7 +30,8 @@ cfg.CONF.register_opts([
|
||||||
cfg.ListOpt('notification-topics', default=['notifications']),
|
cfg.ListOpt('notification-topics', default=['notifications']),
|
||||||
cfg.StrOpt('control-exchange', default='neutron'),
|
cfg.StrOpt('control-exchange', default='neutron'),
|
||||||
cfg.StrOpt('domain-id', default=None),
|
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')
|
], group='handler:neutron_floatingip')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@ cfg.CONF.register_opts([
|
||||||
cfg.ListOpt('notification-topics', default=['notifications']),
|
cfg.ListOpt('notification-topics', default=['notifications']),
|
||||||
cfg.StrOpt('control-exchange', default='nova'),
|
cfg.StrOpt('control-exchange', default='nova'),
|
||||||
cfg.StrOpt('domain-id', default=None),
|
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')
|
], group='handler:nova_fixed')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
domain = self.create_domain()
|
domain = self.create_domain()
|
||||||
self.domain_id = domain['id']
|
self.domain_id = domain['id']
|
||||||
self.config(domain_id=domain['id'], group='handler:neutron_floatingip')
|
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()
|
self.plugin = NeutronFloatingHandler()
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
records = self.central_service.find_records(self.admin_context,
|
records = self.central_service.find_records(self.admin_context,
|
||||||
criterion)
|
criterion)
|
||||||
|
|
||||||
self.assertEqual(3, len(records))
|
self.assertEqual(4, len(records))
|
||||||
|
|
||||||
def test_floatingip_disassociate(self):
|
def test_floatingip_disassociate(self):
|
||||||
start_event_type = 'floatingip.update.end'
|
start_event_type = 'floatingip.update.end'
|
||||||
|
@ -77,7 +80,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
records = self.central_service.find_records(self.admin_context,
|
records = self.central_service.find_records(self.admin_context,
|
||||||
criterion)
|
criterion)
|
||||||
|
|
||||||
self.assertEqual(3, len(records))
|
self.assertEqual(4, len(records))
|
||||||
|
|
||||||
self.plugin.process_notification(
|
self.plugin.process_notification(
|
||||||
self.admin_context, event_type, fixture['payload'])
|
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
|
# Ensure we start with at least 1 record, plus NS and SOA
|
||||||
records = self.central_service.find_records(self.admin_context,
|
records = self.central_service.find_records(self.admin_context,
|
||||||
criterion)
|
criterion)
|
||||||
self.assertEqual(3, len(records))
|
self.assertEqual(4, len(records))
|
||||||
|
|
||||||
self.plugin.process_notification(
|
self.plugin.process_notification(
|
||||||
self.admin_context, event_type, fixture['payload'])
|
self.admin_context, event_type, fixture['payload'])
|
||||||
|
|
|
@ -34,6 +34,9 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
domain = self.create_domain()
|
domain = self.create_domain()
|
||||||
self.domain_id = domain['id']
|
self.domain_id = domain['id']
|
||||||
self.config(domain_id=domain['id'], group='handler:nova_fixed')
|
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()
|
self.plugin = NovaFixedHandler()
|
||||||
|
|
||||||
|
@ -58,10 +61,10 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
records = self.central_service.find_records(self.admin_context,
|
records = self.central_service.find_records(self.admin_context,
|
||||||
criterion)
|
criterion)
|
||||||
|
|
||||||
self.assertEqual(3, len(records))
|
self.assertEqual(4, len(records))
|
||||||
|
|
||||||
def test_instance_create_end_utf8(self):
|
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')
|
group='handler:nova_fixed')
|
||||||
|
|
||||||
event_type = 'compute.instance.create.end'
|
event_type = 'compute.instance.create.end'
|
||||||
|
@ -119,7 +122,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
records = self.central_service.find_records(self.admin_context,
|
records = self.central_service.find_records(self.admin_context,
|
||||||
criterion)
|
criterion)
|
||||||
|
|
||||||
self.assertEqual(3, len(records))
|
self.assertEqual(4, len(records))
|
||||||
|
|
||||||
self.plugin.process_notification(
|
self.plugin.process_notification(
|
||||||
self.admin_context, event_type, fixture['payload'])
|
self.admin_context, event_type, fixture['payload'])
|
||||||
|
@ -138,7 +141,8 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
|
||||||
|
|
||||||
def test_label_in_format(self):
|
def test_label_in_format(self):
|
||||||
event_type = 'compute.instance.create.end'
|
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)
|
fixture = self.get_notification_fixture('nova', event_type)
|
||||||
with contextlib.nested(
|
with contextlib.nested(
|
||||||
mock.patch.object(self.plugin, '_find_or_create_recordset'),
|
mock.patch.object(self.plugin, '_find_or_create_recordset'),
|
||||||
|
|
|
@ -220,6 +220,7 @@ debug = False
|
||||||
#notification_topics = notifications
|
#notification_topics = notifications
|
||||||
#control_exchange = 'nova'
|
#control_exchange = 'nova'
|
||||||
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
|
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
|
||||||
|
#format = '%(hostname)s.%(domain)s'
|
||||||
|
|
||||||
#------------------------
|
#------------------------
|
||||||
# Neutron Floating Handler
|
# Neutron Floating Handler
|
||||||
|
@ -230,6 +231,7 @@ debug = False
|
||||||
#notification_topics = notifications
|
#notification_topics = notifications
|
||||||
#control_exchange = 'neutron'
|
#control_exchange = 'neutron'
|
||||||
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
|
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
|
||||||
|
#format = '%(hostname)s.%(domain)s'
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
## Pool Manager Cache Configuration
|
## Pool Manager Cache Configuration
|
||||||
|
|
Loading…
Reference in New Issue