Exemplo n.º 1
0
    def find_dns_owners(self, dns_owner_id, only_type=True):
        """Return information about entries using this dns_owner.  If
        only_type=True, returns a list of owner_type.  Otherwise
        returns a list of (owner_type, owner_id) tuples"""

        ret = []
        arecord = ARecord.ARecord(self._db)
        for row in arecord.list_ext(dns_owner_id=dns_owner_id):
            ret.append((dns.A_RECORD, row['a_record_id']))
        aaaarecord = AAAARecord.AAAARecord(self._db)
        for row in aaaarecord.list_ext(dns_owner_id=dns_owner_id):
            ret.append((dns.AAAA_RECORD, row['aaaa_record_id']))
        hi = HostInfo.HostInfo(self._db)
        try:
            hi.find_by_dns_owner_id(dns_owner_id)
            ret.append((dns.HOST_INFO, hi.entity_id))
        except Errors.NotFoundError:
            pass
        dns_owner = DnsOwner.DnsOwner(self._db)
        for row in dns_owner.list_srv_records(owner_id=dns_owner_id):
            ret.append((dns.SRV_OWNER, row['service_owner_id']))
        for row in dns_owner.list_general_dns_records(
                dns_owner_id=dns_owner_id):
            ret.append((dns.GENERAL_DNS_RECORD, row['dns_owner_id']))
        cn = CNameRecord.CNameRecord(self._db)
        for row in cn.list_ext(cname_owner=dns_owner_id):
            ret.append((dns.CNAME_OWNER, row['cname_id']))
        if only_type:
            return [x[0] for x in ret]
        return ret
Exemplo n.º 2
0
    def _get_zone_data(self, zone):
        # ARecord has key=a_record_id
        # HostInfo, SrvRecord has key=dns_owner_id
        # CnameRecords key=target_owner_id
        # entity2txt, entity2note has_key=entity_id
        for row in ARecord.ARecord(db).list_ext(zone=zone):
            id = int(row['dns_owner_id'])
            if self.a_records_by_dns_owner.has_key(id):
                self.a_records_by_dns_owner[id] += [row]
            else:
                self.a_records_by_dns_owner[id] = [row]

            # Following dict is populated to support HostFile
            self.a_records[int(row['a_record_id'])] = row
        logger.debug("... arecords")

        for row in AAAARecord.AAAARecord(db).list_ext(zone=zone):
            id = int(row['dns_owner_id'])
            if self.aaaa_records_by_dns_owner.has_key(id):
                self.aaaa_records_by_dns_owner[id] += [row]
            else:
                self.aaaa_records_by_dns_owner[id] = [row]
            # Following dict is populated to support HostFile
            self.aaaa_records[int(row['aaaa_record_id'])] = row
        logger.debug("... aaaarecords")

        for row in HostInfo.HostInfo(db).list(zone=zone):
            # Unique constraint on dns_owner_id
            self.hosts[int(row['dns_owner_id'])] = row

        logger.debug("... hosts")
        for row in CNameRecord.CNameRecord(db).list_ext(zone=zone):
            # TBD:  skal vi ha unique constraint på dns_owner?
            self.cnames.setdefault(int(row['target_owner_id']), []).append(row)
        logger.debug("... cnames")

        # From mix-in classes
        for row in DnsOwner.MXSet(db).list_mx_sets():
            self.mx_sets.setdefault(int(row['mx_set_id']), []).append(row)

        logger.debug("... mx_sets")
        for row in DnsOwner.DnsOwner(db).list(zone=zone):
            self.owner_id2mx_set[int(row['dns_owner_id'])] = int(
                row['mx_set_id'] or 0)

        logger.debug("... mx_set owners")

        for row in DnsOwner.DnsOwner(db).list_general_dns_records(
                field_type=co.field_type_txt, zone=zone):
            self.dnsowner2txt_record[int(row['dns_owner_id'])] = row
        logger.debug("... txt reocrds")

        for row in DnsOwner.DnsOwner(db).list_srv_records(zone=zone):
            # We want them listed in the same place
            # TODO: while doing that, we want it below the first target_owner_id
            self.srv_records.setdefault(int(row['service_owner_id']),
                                        []).append(row)
        logger.debug("... srv records")
Exemplo n.º 3
0
 def remove_cname(self, dns_owner_id, try_dns_remove=False):
     c = CNameRecord.CNameRecord(self._db)
     try:
         c.find_by_cname_owner_id(dns_owner_id)
     except Errors.NotFoundError:
         return  # No deletion needed
     c._delete()
     if try_dns_remove:
         self.remove_dns_owner(dns.entity_id)
Exemplo n.º 4
0
 def __init__(self, db, default_zone):
     self._db = db
     self._arecord = ARecord.ARecord(self._db)
     self._ip_number = IPNumber.IPNumber(self._db)
     self._dns_owner = DnsOwner.DnsOwner(self._db)
     self._mx_set = DnsOwner.MXSet(self._db)
     self._host = HostInfo.HostInfo(self._db)
     self._cname = CNameRecord.CNameRecord(self._db)
     self._default_zone = default_zone
Exemplo n.º 5
0
 def __init__(self, db, default_zone):
     self._db = db
     self._ip_number = IPNumber.IPNumber(db)
     self._ipv6_number = IPv6Number.IPv6Number(db)
     self._arecord = ARecord.ARecord(db)
     self._aaaarecord = AAAARecord.AAAARecord(db)
     self._dns_owner = DnsOwner.DnsOwner(db)
     self._mx_set = DnsOwner.MXSet(db)
     self._host = HostInfo.HostInfo(db)
     self._cname = CNameRecord.CNameRecord(db)
     self._dns_parser = DnsParser(db, default_zone)
Exemplo n.º 6
0
    def set_ttl(self, owner_id, ttl):
        """Set TTL entries for this dns_owner"""

        # TODO: Currently we do this by updating the TTL in all
        # tables.  It has been decided to move ttl-information into
        # dns_owner.  However, we will not do this until after we have
        # gone into production to avoid a huge diff when comparing
        # autogenerated zone files to the original ones.

        dns_owner = DnsOwner.DnsOwner(self.db)
        dns_owner.find(owner_id)

        arecord = ARecord.ARecord(self.db)
        for row in arecord.list_ext(dns_owner_id=owner_id):
            arecord.clear()
            arecord.find(row['a_record_id'])
            arecord.ttl = ttl
            arecord.write_db()

        aaaarecord = AAAARecord.AAAARecord(self.db)
        for row in aaaarecord.list_ext(dns_owner_id=owner_id):
            aaaarecord.clear()
            aaaarecord.find(row['aaaa_record_id'])
            aaaarecord.ttl = ttl
            aaaarecord.write_db()

        host = HostInfo.HostInfo(self.db)
        try:
            host.find_by_dns_owner_id(owner_id)
        except Errors.NotFoundError:
            pass
        else:
            host.ttl = ttl
            host.write_db()

        for row in dns_owner.list_general_dns_records(dns_owner_id=owner_id):
            dns_owner.update_general_dns_record(owner_id, row['field_type'],
                                                ttl, row['data'])

        mx_set = DnsOwner.MXSet(self.db)
        for row in mx_set.list_mx_sets(target_id=owner_id):
            mx_set.clear()
            mx_set.find(row['mx_set_id'])
            mx_set.update_mx_set_member(ttl, row['pri'], row['target_id'])
        cname = CNameRecord.CNameRecord(self.db)
        for row in cname.list_ext(cname_owner=owner_id):
            cname.clear()
            cname.find(row['cname_id'])
            cname.ttl = ttl
            cname.write_db()

        for row in dns_owner.list_srv_records(owner_id=owner_id):
            dns_owner.update_srv_record_ttl(owner_id, ttl)
Exemplo n.º 7
0
 def __init__(self, db, logger, default_zone):
     self.logger = logger
     self.db = db
     self.const = Factory.get('Constants')(self.db)
     # TBD: This pre-allocating may interfere with multi-threaded bofhd
     self._arecord = ARecord.ARecord(self.db)
     self._aaaarecord = AAAARecord.AAAARecord(self.db)
     self._host = HostInfo.HostInfo(self.db)
     self._dns_owner = DnsOwner.DnsOwner(self.db)
     self._ip_number = IPNumber.IPNumber(self.db)
     self._ipv6_number = IPv6Number.IPv6Number(self.db)
     self._cname = CNameRecord.CNameRecord(self.db)
     self._validator = IntegrityHelper.Validator(self.db, default_zone)
     self._update_helper = IntegrityHelper.Updater(self.db)
     self._mx_set = DnsOwner.MXSet(self.db)
     self.default_zone = default_zone
     self._find = Utils.Find(self.db, default_zone)
     self._parser = Utils.DnsParser(self.db, default_zone)
Exemplo n.º 8
0
    def find_referers(self, ip_number_id=None, dns_owner_id=None,
                      only_type=True, ip_type=dns.IP_NUMBER):
        """Return information about registrations that point to this
        ip-number/dns-owner. If only_type=True, returns a list of
        owner_type.  Otherwise returns a list of (owner_type,
        owner_id) tuples"""

        # We choose classes and record type depending on the ip_type
        # parameter. This is a bit dirty, but reduces the amount of
        # functions required.
        ip_class = IPNumber.IPNumber if (
            ip_type == dns.IP_NUMBER
        ) else IPv6Number.IPv6Number
        record_class = ARecord.ARecord if (
            ip_type == dns.IP_NUMBER
        ) else AAAARecord.AAAARecord
        record_type = dns.A_RECORD if (
            ip_type == dns.IP_NUMBER
        ) else dns.AAAA_RECORD

        ip_key = 'ip_number_id' if (
            ip_type == dns.IP_NUMBER
        ) else 'ipv6_number_id'
        record_key = 'a_record_id' if (
            ip_type == dns.IP_NUMBER
        ) else 'aaaa_record_id'

        # Not including entity-note
        assert not (ip_number_id and dns_owner_id)
        ret = []

        if ip_number_id and ip_type == dns.REV_IP_NUMBER:
            for ipn, key in [
                    (IPNumber.IPNumber(self._db), 'ip_number_id'),
                    (IPv6Number.IPv6Number(self._db), 'ipv6_number_id')]:
                for row in ipn.list_override(ip_number_id=ip_number_id):
                    ret.append((dns.REV_IP_NUMBER, row[key]))

            if only_type:
                return [x[0] for x in ret]
            return ret

        if ip_number_id:
            ipnumber = ip_class(self._db)
            for row in ipnumber.list_override(ip_number_id=ip_number_id):
                ret.append((dns.REV_IP_NUMBER, row[ip_key]))
            arecord = record_class(self._db)
            for row in arecord.list_ext(ip_number_id=ip_number_id):
                ret.append((record_type, row[record_key]))
            if only_type:
                return [x[0] for x in ret]
            return ret
        mx = DnsOwner.MXSet(self._db)
        for row in mx.list_mx_sets(target_id=dns_owner_id):
            ret.append((dns.MX_SET, row['mx_set_id']))
        dns_owner = DnsOwner.DnsOwner(self._db)
        for row in dns_owner.list_srv_records(target_owner_id=dns_owner_id):
            ret.append((dns.SRV_TARGET, row['service_owner_id']))
        cn = CNameRecord.CNameRecord(self._db)
        for row in cn.list_ext(target_owner=dns_owner_id):
            ret.append((dns.CNAME_TARGET, row['cname_id']))
        arecord = record_class(self._db)
        for row in arecord.list_ext(dns_owner_id=dns_owner_id):
            ret.append((record_type, row[record_key]))
        hi = HostInfo.HostInfo(self._db)
        for row in hi.list_ext(dns_owner_id=dns_owner_id):
            ret.append((dns.HOST_INFO, row['host_id'],))
        if only_type:
            return [x[0] for x in ret]
        return ret
Exemplo n.º 9
0
from Cerebrum.modules.dns import ARecord
from Cerebrum.modules.dns import CNameRecord
from Cerebrum.modules.dns import DnsOwner
from Cerebrum.modules.dns import HostInfo
from Cerebrum.modules.dns import IPNumber
from Cerebrum.modules.dns import Utils

sys.argv.extend(["--logger-level", "DEBUG"])
logger = Factory.get_logger("cronjob")
db = Factory.get('Database')()
db.cl_init(change_program='import_dns')
co = Factory.get('Constants')(db)
ipnumber = IPNumber.IPNumber(db)
arecord = ARecord.ARecord(db)
cname = CNameRecord.CNameRecord(db)
dnsowner = DnsOwner.DnsOwner(db)
host = HostInfo.HostInfo(db)
mx_set = DnsOwner.MXSet(db)

# logger.setLevel(logger.debug)
header_splitter = r'^; AUTOGENERATED: do not edit below this line'

class Netgroups(object):
    class MergeRestart(Exception): pass

    def __init__(self, fname, default_zone):
        self._fname = fname
        self._default_zone = default_zone
        self._import_netgroups()