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):
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'])

View File

@ -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')

View File

@ -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')