Refactored BaseAddressHandler

Change-Id: I2ffd2ab0be094e18fe2f25020654f0d20c96e7ed
This commit is contained in:
Erik Olof Gunnar Andersson 2015-04-10 11:26:36 +00:00
parent 83f6d28fdb
commit aad35879ed
3 changed files with 23 additions and 13 deletions

View File

@ -107,7 +107,7 @@ class BaseAddressHandler(NotificationHandler):
def _get_format(self): def _get_format(self):
return cfg.CONF[self.name].get('format') or self.default_format 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): resource_type=None, resource_id=None):
""" """
Create a a record from addresses Create a a record from addresses
@ -124,8 +124,8 @@ class BaseAddressHandler(NotificationHandler):
'Deprecation notice: Unmanaged designate-sink records are ' 'Deprecation notice: Unmanaged designate-sink records are '
'being deprecated please update the call ' 'being deprecated please update the call '
'to remove managed=False')) 'to remove managed=False'))
LOG.debug('Using DomainID: %s' % cfg.CONF[self.name].domain_id) LOG.debug('Using DomainID: %s' % domain_id)
domain = self.get_domain(cfg.CONF[self.name].domain_id) domain = self.get_domain(domain_id)
LOG.debug('Domain: %r' % domain) LOG.debug('Domain: %r' % domain)
data = extra.copy() data = extra.copy()
@ -166,8 +166,8 @@ class BaseAddressHandler(NotificationHandler):
recordset['id'], recordset['id'],
Record(**record_values)) Record(**record_values))
def _delete(self, managed=True, resource_id=None, resource_type='instance', def _delete(self, domain_id, managed=True, resource_id=None,
criterion=None): resource_type='instance', criterion=None):
""" """
Handle a generic delete of a fixed ip within a domain Handle a generic delete of a fixed ip within a domain
@ -184,7 +184,7 @@ class BaseAddressHandler(NotificationHandler):
context.all_tenants = True context.all_tenants = True
context.edit_managed_records = True context.edit_managed_records = True
criterion.update({'domain_id': cfg.CONF[self.name].domain_id}) criterion.update({'domain_id': domain_id})
if managed: if managed:
criterion.update({ criterion.update({
@ -201,6 +201,6 @@ class BaseAddressHandler(NotificationHandler):
LOG.debug('Deleting record %s' % record['id']) LOG.debug('Deleting record %s' % record['id'])
self.central_api.delete_record(context, self.central_api.delete_record(context,
cfg.CONF[self.name].domain_id, domain_id,
record['recordset_id'], record['recordset_id'],
record['id']) record['id'])

View File

@ -55,17 +55,23 @@ class NeutronFloatingHandler(BaseAddressHandler):
LOG.debug('%s received notification - %s' % LOG.debug('%s received notification - %s' %
(self.get_canonical_name(), event_type)) (self.get_canonical_name(), event_type))
domain_id = cfg.CONF[self.name].domain_id
if event_type.startswith('floatingip.delete'): 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') resource_type='floatingip')
elif event_type.startswith('floatingip.update'): elif event_type.startswith('floatingip.update'):
if payload['floatingip']['fixed_ip_address']: if payload['floatingip']['fixed_ip_address']:
address = { address = {
'version': 4, 'version': 4,
'address': payload['floatingip']['floating_ip_address']} 'address': payload['floatingip']['floating_ip_address']
self._create([address], payload['floatingip'], }
self._create(addresses=[address],
extra=payload['floatingip'],
domain_id=domain_id,
resource_id=payload['floatingip']['id'], resource_id=payload['floatingip']['id'],
resource_type='floatingip') resource_type='floatingip')
elif not payload['floatingip']['fixed_ip_address']: 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') resource_type='floatingip')

View File

@ -54,11 +54,15 @@ class NovaFixedHandler(BaseAddressHandler):
def process_notification(self, context, event_type, payload): def process_notification(self, context, event_type, payload):
LOG.debug('NovaFixedHandler received notification - %s' % event_type) LOG.debug('NovaFixedHandler received notification - %s' % event_type)
domain_id = cfg.CONF[self.name].domain_id
if event_type == 'compute.instance.create.end': 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_id=payload['instance_id'],
resource_type='instance') resource_type='instance')
elif event_type == 'compute.instance.delete.start': 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') resource_type='instance')