def update_catalog(self, delete=False): return _pdns_patch( NSMASTER, '/zones/' + pdns_id(settings.CATALOG_ZONE), { 'rrsets': [ construct_catalog_rrset(zone=self.domain_name, delete=delete) ] })
def handle(self, *args, **options): catalog_zone_id = pdns_id(settings.CATALOG_ZONE) # Fetch zones from NSLORD response = _pdns_get(NSLORD, '/zones').json() zones = {zone['name'] for zone in response} # Retrieve catalog zone serial (later reused for recreating the catalog zone, for allow for smooth rollover) try: response = _pdns_get(NSMASTER, f'/zones/{catalog_zone_id}') serial = response.json()['serial'] except PDNSException as e: if e.response.status_code == 404: serial = None else: raise e # Purge catalog zone if exists try: _pdns_delete(NSMASTER, f'/zones/{catalog_zone_id}') except PDNSException as e: if e.response.status_code != 404: raise e # Create new catalog zone rrsets = [ construct_catalog_rrset(subname='', qtype='NS', rdata='invalid.'), # as per the specification construct_catalog_rrset(subname='version', qtype='TXT', rdata='"2"'), # as per the specification *(construct_catalog_rrset(zone=zone) for zone in zones) ] data = { 'name': settings.CATALOG_ZONE + '.', 'kind': 'MASTER', 'dnssec': False, # as per the specification 'nameservers': [], 'rrsets': rrsets, } if serial is not None: data['serial'] = serial + 1 # actually, pdns does increase this as well, but let's not rely on this _pdns_post(NSMASTER, '/zones?rrsets=false', data) print(f'Aligned catalog zone ({len(zones)} member zones).')
def update_catalog(self, delete=False): content = _pdns_patch( NSMASTER, '/zones/' + pdns_id(settings.CATALOG_ZONE), { 'rrsets': [ construct_catalog_rrset(zone=self.domain_name, delete=delete) ] }) metrics.get('desecapi_pdns_catalog_updated').inc() return content