From aad35879ed4cf43fc5c7df9fd1dbcd147e10bfe8 Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Fri, 10 Apr 2015 11:26:36 +0000 Subject: [PATCH] Refactored BaseAddressHandler Change-Id: I2ffd2ab0be094e18fe2f25020654f0d20c96e7ed --- designate/notification_handler/base.py | 14 +++++++------- designate/notification_handler/neutron.py | 14 ++++++++++---- designate/notification_handler/nova.py | 8 ++++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/designate/notification_handler/base.py b/designate/notification_handler/base.py index 48df92f16..421551fe0 100644 --- a/designate/notification_handler/base.py +++ b/designate/notification_handler/base.py @@ -107,7 +107,7 @@ class BaseAddressHandler(NotificationHandler): def _get_format(self): return cfg.CONF[self.name].get('format') or self.default_format - def _create(self, addresses, extra, managed=True, + def _create(self, addresses, extra, domain_id, managed=True, resource_type=None, resource_id=None): """ Create a a record from addresses @@ -124,8 +124,8 @@ class BaseAddressHandler(NotificationHandler): 'Deprecation notice: Unmanaged designate-sink records are ' 'being deprecated please update the call ' 'to remove managed=False')) - LOG.debug('Using DomainID: %s' % cfg.CONF[self.name].domain_id) - domain = self.get_domain(cfg.CONF[self.name].domain_id) + LOG.debug('Using DomainID: %s' % domain_id) + domain = self.get_domain(domain_id) LOG.debug('Domain: %r' % domain) data = extra.copy() @@ -166,8 +166,8 @@ class BaseAddressHandler(NotificationHandler): recordset['id'], Record(**record_values)) - def _delete(self, managed=True, resource_id=None, resource_type='instance', - criterion=None): + def _delete(self, domain_id, managed=True, resource_id=None, + resource_type='instance', criterion=None): """ Handle a generic delete of a fixed ip within a domain @@ -184,7 +184,7 @@ class BaseAddressHandler(NotificationHandler): context.all_tenants = True context.edit_managed_records = True - criterion.update({'domain_id': cfg.CONF[self.name].domain_id}) + criterion.update({'domain_id': domain_id}) if managed: criterion.update({ @@ -201,6 +201,6 @@ class BaseAddressHandler(NotificationHandler): LOG.debug('Deleting record %s' % record['id']) self.central_api.delete_record(context, - cfg.CONF[self.name].domain_id, + domain_id, record['recordset_id'], record['id']) diff --git a/designate/notification_handler/neutron.py b/designate/notification_handler/neutron.py index 472c8236b..8830236d7 100644 --- a/designate/notification_handler/neutron.py +++ b/designate/notification_handler/neutron.py @@ -55,17 +55,23 @@ class NeutronFloatingHandler(BaseAddressHandler): LOG.debug('%s received notification - %s' % (self.get_canonical_name(), event_type)) + domain_id = cfg.CONF[self.name].domain_id if event_type.startswith('floatingip.delete'): - self._delete(resource_id=payload['floatingip_id'], + self._delete(domain_id=domain_id, + resource_id=payload['floatingip_id'], resource_type='floatingip') elif event_type.startswith('floatingip.update'): if payload['floatingip']['fixed_ip_address']: address = { 'version': 4, - 'address': payload['floatingip']['floating_ip_address']} - self._create([address], payload['floatingip'], + 'address': payload['floatingip']['floating_ip_address'] + } + self._create(addresses=[address], + extra=payload['floatingip'], + domain_id=domain_id, resource_id=payload['floatingip']['id'], resource_type='floatingip') elif not payload['floatingip']['fixed_ip_address']: - self._delete(resource_id=payload['floatingip']['id'], + self._delete(domain_id=domain_id, + resource_id=payload['floatingip']['id'], resource_type='floatingip') diff --git a/designate/notification_handler/nova.py b/designate/notification_handler/nova.py index 71750cbfe..be8e9e2c1 100644 --- a/designate/notification_handler/nova.py +++ b/designate/notification_handler/nova.py @@ -54,11 +54,15 @@ class NovaFixedHandler(BaseAddressHandler): def process_notification(self, context, event_type, payload): LOG.debug('NovaFixedHandler received notification - %s' % event_type) + domain_id = cfg.CONF[self.name].domain_id if event_type == 'compute.instance.create.end': - self._create(payload['fixed_ips'], payload, + self._create(addresses=payload['fixed_ips'], + extra=payload, + domain_id=domain_id, resource_id=payload['instance_id'], resource_type='instance') elif event_type == 'compute.instance.delete.start': - self._delete(resource_id=payload['instance_id'], + self._delete(domain_id=domain_id, + resource_id=payload['instance_id'], resource_type='instance')