Exemple #1
0
    def render(self, session, service, protocol, dns_domain, target,
               dns_environment, **kwargs):
        name = "_%s._%s" % (service.strip().lower(), protocol.strip().lower())
        dbfqdn = Fqdn.get_unique(session, name=name, dns_domain=dns_domain,
                                 dns_environment=dns_environment)
        if target:
            dbtarget = Fqdn.get_unique(session, target, compel=True)
        else:
            dbtarget = None

        rrs = []
        if dbfqdn:
            for rr in dbfqdn.dns_records:
                if not isinstance(rr, SrvRecord):  # pragma: no cover
                    # This case can't happen right now. Maybe one day if we
                    # add support for DNSSEC...
                    continue
                if dbtarget and rr.target != dbtarget:
                    continue
                rrs.append(rr)

        if not rrs:
            if dbtarget:
                msg = ", with target %s" % dbtarget.fqdn
            else:
                msg = ""
            raise NotFoundException("%s for service %s, protocol %s in DNS "
                                    "domain %s%s not found." %
                                    (SrvRecord._get_class_label(), service,
                                     protocol, dns_domain, msg))

        map(delete_dns_record, rrs)
        session.flush()

        return
Exemple #2
0
    def render(self, session, service, protocol, dns_domain, priority, weight,
               target, port, dns_environment, comments, **kwargs):
        dbdns_env = DnsEnvironment.get_unique_or_default(
            session, dns_environment)
        dbdns_domain = DnsDomain.get_unique(session, dns_domain, compel=True)
        if dbdns_domain.restricted:
            raise ArgumentError(
                "{0} is restricted, SRV records are not allowed.".format(
                    dbdns_domain))

        # TODO: we could try looking up the port based on the service, but there
        # are some caveats:
        # - the protocol name used in SRV record may not match the name used in
        #   /etc/services
        # - socket.getservent() may return bogus information (like it does for
        #   e.g. 'kerberos')

        service = service.strip().lower()
        target = target.strip().lower()

        dbtarget = Fqdn.get_unique(session, target, compel=True)
        dbsrv_rec = SrvRecord(service=service,
                              protocol=protocol,
                              priority=priority,
                              weight=weight,
                              target=dbtarget,
                              port=port,
                              dns_domain=dbdns_domain,
                              dns_environment=dbdns_env,
                              comments=comments)
        session.add(dbsrv_rec)

        session.flush()

        return
Exemple #3
0
    def render(self, session, service, protocol, dns_domain, target,
               priority, weight, port, comments, dns_environment, **kwargs):
        name = "_%s._%s" % (service.strip().lower(), protocol.strip().lower())
        dbsrv_rec = SrvRecord.get_unique(session, name=name,
                                         dns_domain=dns_domain,
                                         dns_environment=dns_environment,
                                         target=target, compel=True)

        if priority:
            dbsrv_rec.priority = priority
        if weight:
            dbsrv_rec.weight = weight
        if port:
            dbsrv_rec.port = port
        if comments is not None:
            dbsrv_rec.comments = comments

        session.flush()
        return
Exemple #4
0
    def render(self, session, service, protocol, dns_domain, dns_environment,
               **kwargs):
        dbdns_env = DnsEnvironment.get_unique_or_default(session,
                                                         dns_environment)
        dbdns_domain = DnsDomain.get_unique(session, dns_domain, compel=True)

        name = "_%s._%s" % (service.strip().lower(), protocol.strip().lower())

        q = session.query(SrvRecord)
        q = q.join((Fqdn, SrvRecord.fqdn_id == Fqdn.id))
        q = q.options(contains_eager('fqdn'))
        q = q.filter_by(dns_domain=dbdns_domain)
        q = q.filter_by(name=name)
        q = q.filter_by(dns_environment=dbdns_env)
        result = q.all()
        if not result:
            raise NotFoundException("%s for service %s, protocol %s in DNS "
                                    "domain %s not found." %
                                    (SrvRecord._get_class_label(), service,
                                     protocol, dns_domain))
        return result
Exemple #5
0
    def render(self, session, service, protocol, dns_domain, dns_environment,
               **kwargs):
        dbdns_env = DnsEnvironment.get_unique_or_default(
            session, dns_environment)
        dbdns_domain = DnsDomain.get_unique(session, dns_domain, compel=True)

        name = "_%s._%s" % (service.strip().lower(), protocol.strip().lower())

        q = session.query(SrvRecord)
        q = q.join((Fqdn, SrvRecord.fqdn_id == Fqdn.id))
        q = q.options(contains_eager('fqdn'))
        q = q.filter_by(dns_domain=dbdns_domain)
        q = q.filter_by(name=name)
        q = q.filter_by(dns_environment=dbdns_env)
        result = q.all()
        if not result:
            raise NotFoundException(
                "%s for service %s, protocol %s in DNS "
                "domain %s not found." %
                (SrvRecord._get_class_label(), service, protocol, dns_domain))
        return result
Exemple #6
0
    def render(self, session, service, protocol, dns_domain, target,
               dns_environment, **kwargs):
        name = "_%s._%s" % (service.strip().lower(), protocol.strip().lower())
        dbfqdn = Fqdn.get_unique(session,
                                 name=name,
                                 dns_domain=dns_domain,
                                 dns_environment=dns_environment)
        if target:
            dbtarget = Fqdn.get_unique(session, target, compel=True)
        else:
            dbtarget = None

        rrs = []
        if dbfqdn:
            for rr in dbfqdn.dns_records:
                if not isinstance(rr, SrvRecord):  # pragma: no cover
                    # This case can't happen right now. Maybe one day if we
                    # add support for DNSSEC...
                    continue
                if dbtarget and rr.target != dbtarget:
                    continue
                rrs.append(rr)

        if not rrs:
            if dbtarget:
                msg = ", with target %s" % dbtarget.fqdn
            else:
                msg = ""
            raise NotFoundException("%s for service %s, protocol %s in DNS "
                                    "domain %s%s not found." %
                                    (SrvRecord._get_class_label(), service,
                                     protocol, dns_domain, msg))

        map(delete_dns_record, rrs)
        session.flush()

        return