different-format-for-ipv4-and-ipv6

This change will allow users to define seperate
formats for ipv4 and ipv6 addresses.
this requires formatv4 and formatv6 to de defined in
designate.conf instead of format.

format has been marked depricated

Change-Id: Ief685ba6a00da5100013f4ab71768c661f37ee13
Implements: blueprint different-format-for-ipv4-and-ipv6
This commit is contained in:
Kumar Acharya 2016-07-05 09:35:24 +05:30
parent ec5889a3bb
commit 0568b66d23
5 changed files with 81 additions and 12 deletions

View File

@ -90,6 +90,9 @@ class NotificationHandler(ExtensionPlugin):
class BaseAddressHandler(NotificationHandler):
default_formatv4 = ('%(hostname)s.%(domain)s')
default_formatv6 = ('%(hostname)s.%(domain)s')
def _get_ip_data(self, addr_dict):
ip = addr_dict['address']
version = addr_dict['version']
@ -106,6 +109,16 @@ class BaseAddressHandler(NotificationHandler):
data["octet%s" % i] = ip_data[i]
return data
def _get_formatv4(self):
return cfg.CONF[self.name].get('formatv4') or \
cfg.CONF[self.name].get('format') or \
self.default_formatv4
def _get_formatv6(self):
return cfg.CONF[self.name].get('formatv6') or \
cfg.CONF[self.name].get('format') or \
self.default_formatv6
def _create(self, addresses, extra, zone_id, managed=True,
resource_type=None, resource_id=None):
"""
@ -139,7 +152,13 @@ class BaseAddressHandler(NotificationHandler):
event_data = data.copy()
event_data.update(self._get_ip_data(addr))
for fmt in cfg.CONF[self.name].get('format'):
formatv4 = self._get_formatv4()
formatv6 = self._get_formatv6()
if addr['version'] == 4:
format = formatv4
else:
format = formatv6
for fmt in format:
recordset_values = {
'zone_id': zone['id'],
'name': fmt % event_data,

View File

@ -30,8 +30,12 @@ cfg.CONF.register_opts([
cfg.ListOpt('notification-topics', default=['notifications']),
cfg.StrOpt('control-exchange', default='neutron'),
cfg.StrOpt('zone-id'),
cfg.MultiStrOpt('format', default=[
'%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(zone)s'])
cfg.MultiStrOpt('formatv4', default=None),
cfg.MultiStrOpt('format', default=None,
deprecated_for_removal=True,
deprecated_reason="Replaced by 'formatv4/formatv6'",
),
cfg.MultiStrOpt('formatv6', default=None)
], group='handler:neutron_floatingip')

View File

@ -30,8 +30,12 @@ cfg.CONF.register_opts([
cfg.ListOpt('notification-topics', default=['notifications']),
cfg.StrOpt('control-exchange', default='nova'),
cfg.StrOpt('zone-id'),
cfg.MultiStrOpt('format', default=[
'%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(zone)s'])
cfg.MultiStrOpt('formatv4', default=None),
cfg.MultiStrOpt('format', default=None,
deprecated_for_removal=True,
deprecated_reason="Replaced by 'formatv4/formatv6'",
),
cfg.MultiStrOpt('formatv6', default=None)
], group='handler:nova_fixed')

View File

@ -152,3 +152,37 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin):
finder.assert_called_once_with(
mock.ANY, type='A', zone_id=self.zone_id,
name='private.example.com')
def test_formatv4_or_format(self):
event_type = 'compute.instance.create.end'
self.config(formatv4=['%(label)s-v4.example.com'],
group='handler:nova_fixed')
fixture = self.get_notification_fixture('nova', event_type)
with mock.patch.object(self.plugin, '_find_or_create_recordset')\
as finder:
with mock.patch.object(self.plugin.central_api,
'create_record'):
finder.return_value = {'id': 'fakeid'}
self.plugin.process_notification(
self.admin_context, event_type, fixture['payload'])
finder.assert_called_once_with(
mock.ANY, type='A', zone_id=self.zone_id,
name='private-v4.example.com')
def test_formatv4_and_format(self):
event_type = 'compute.instance.create.end'
self.config(format=['%(label)s.example.com'],
group='handler:nova_fixed')
self.config(formatv4=['%(label)s-v4.example.com'],
group='handler:nova_fixed')
fixture = self.get_notification_fixture('nova', event_type)
with mock.patch.object(self.plugin, '_find_or_create_recordset')\
as finder:
with mock.patch.object(self.plugin.central_api,
'create_record'):
finder.return_value = {'id': 'fakeid'}
self.plugin.process_notification(
self.admin_context, event_type, fixture['payload'])
finder.assert_called_once_with(
mock.ANY, type='A', zone_id=self.zone_id,
name='private-v4.example.com')

View File

@ -431,10 +431,16 @@ debug = False
#domain_id =
#notification_topics = notifications
#control_exchange = 'nova'
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
#format = '%(hostname)s.%(project)s.%(domain)s'
#format = '%(hostname)s.%(domain)s'
#"format" has been depricated. Instead we now have two formaters
#each for IPv4 and IPv6.
#"formatv4" has been defined for IPv4 addresses.
#"formatv6" is for IPv6 addresses.
#
#formatv4 = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
#formatv4 = '%(hostname)s.%(project)s.%(domain)s'
#formatv4 = '%(hostname)s.%(domain)s'
#formatv6 = '%(hostname)s.%(domain)s'
#formatv6 = '%(hostname)s.%(project)s.%(domain)s'
#------------------------
# Neutron Floating Handler
#------------------------
@ -443,9 +449,11 @@ debug = False
#domain_id =
#notification_topics = notifications
#control_exchange = 'neutron'
#format = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
#format = '%(hostname)s.%(project)s.%(domain)s'
#format = '%(hostname)s.%(domain)s'
#formatv4 = '%(octet0)s-%(octet1)s-%(octet2)s-%(octet3)s.%(domain)s'
#formatv4 = '%(hostname)s.%(project)s.%(domain)s'
#formatv4 = '%(hostname)s.%(domain)s'
#formatv6 = '%(hostname)s.%(project)s.%(domain)s'
#formatv6 = '%(hostname)s.%(domain)s'
##############################
## Agent Backend Configuration