consider only first PTR value for getting changes

This commit is contained in:
Viranch Mehta
2021-08-16 20:33:22 -07:00
parent 3abea76921
commit fc39697bdd
2 changed files with 33 additions and 25 deletions
+2 -24
View File
@@ -294,30 +294,8 @@ class Manager(object):
for processor in processors:
plan = processor.process_plan(plan, sources=sources,
target=target)
if not plan:
continue
# Multi value PTR check
for change in plan.changes:
record = change.new
if not record:
# Delete - doesn't need to be checked
continue
if record._type == 'PTR' and len(record.values) > 1 and not \
target.SUPPORTS_MUTLIVALUE_PTR:
self.log.warn('target=%s does not support multi-value PTR '
'record %s; using %s as its only answer',
target, record.fqdn, record.value)
# Make a new copy of the record so as to not change a
# potentially shared object
change.new = Record.new(record.zone, record.name, {
'type': record._type,
'ttl': record.ttl,
'value': record.value,
}, source=record.source, lenient=lenient)
plans.append((target, plan))
if plan:
plans.append((target, plan))
# Return the zone as it's the desired state
return plans, zone
+31 -1
View File
@@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function, \
from six import text_type
from ..record import Record
from ..source.base import BaseSource
from ..zone import Zone
from .plan import Plan
@@ -44,6 +45,35 @@ class BaseProvider(BaseSource):
'''
return []
def _process_change(self, change):
'''
Process/manipulate each change for feature-specific corner cases
'''
if not self._include_change(change):
return False
# Multi value PTR records
record = change.new
if record and record._type == 'PTR' and len(record.values) > 1 and \
not self.SUPPORTS_MUTLIVALUE_PTR:
# replace with a single-value copy
change.new = Record.new(record.zone, record.name, {
'type': 'PTR',
'ttl': record.ttl,
'values': [record.value],
}, source=record.source)
existing = change.existing
if existing and not existing.changes(change.new, self):
# if new single-value replacement turns out to be the same,
# skip the change
return False
self.log.warn('does not support multi-value PTR records; will '
'use only %s for %s', record.value, record.fqdn)
return True
def plan(self, desired, processors=[]):
self.log.info('plan: desired=%s', desired.name)
@@ -63,7 +93,7 @@ class BaseProvider(BaseSource):
# allow the provider to filter out false positives
before = len(changes)
changes = [c for c in changes if self._include_change(c)]
changes = [c for c in changes if self._process_change(c)]
after = len(changes)
if before != after:
self.log.info('plan: filtered out %s changes', before - after)