当前位置: 首页>>代码示例>>Python>>正文


Python dns.rdatatype方法代码示例

本文整理汇总了Python中dns.rdatatype方法的典型用法代码示例。如果您正苦于以下问题:Python dns.rdatatype方法的具体用法?Python dns.rdatatype怎么用?Python dns.rdatatype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dns的用法示例。


在下文中一共展示了dns.rdatatype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_dns_message

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def _make_dns_message(self, zone_name, notify=False):
        """
        This constructs a SOA query or a dns NOTIFY message.
        :param zone_name: The zone name for which a SOA/NOTIFY needs to be
            sent.
        :param notify: If true, a notify message is constructed else a SOA
            message is constructed.
        :return: The constructed message.
        """
        dns_message = dns.message.make_query(zone_name, dns.rdatatype.SOA)
        dns_message.flags = 0
        if notify:
            dns_message.set_opcode(dns.opcode.NOTIFY)
            dns_message.flags |= dns.flags.AA
        else:
            # Setting the flags to RD causes BIND9 to respond with a NXDOMAIN.
            dns_message.set_opcode(dns.opcode.QUERY)
            dns_message.flags |= dns.flags.RD

        return dns_message 
开发者ID:openstack,项目名称:designate,代码行数:22,代码来源:notify.py

示例2: test_limit_notify_middleware

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def test_limit_notify_middleware(self):
        self.CONF.set_override('notify_delay', 0.1, 'service:agent')

        # Initialize the middlware
        placeholder_app = None
        middleware = dnsutils.LimitNotifyMiddleware(placeholder_app)

        # Prepare a NOTIFY
        zone_name = 'example.com.'
        notify = dns.message.make_query(zone_name, dns.rdatatype.SOA)
        notify.flags = 0
        notify.set_opcode(dns.opcode.NOTIFY)
        notify.flags |= dns.flags.AA

        # Send the NOTIFY through the middleware
        # No problem, middleware should return None to pass it on
        self.assertIsNone(middleware.process_request(notify)) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_dnsutils.py

示例3: test_limit_notify_middleware_no_acquire

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def test_limit_notify_middleware_no_acquire(self, mock_acquire):
        self.CONF.set_override('notify_delay', 0.1, 'service:agent')

        # Initialize the middlware
        placeholder_app = None
        middleware = dnsutils.LimitNotifyMiddleware(placeholder_app)

        # Prepare a NOTIFY
        zone_name = 'example.com.'
        notify = dns.message.make_query(zone_name, dns.rdatatype.SOA)
        notify.flags = 0
        notify.set_opcode(dns.opcode.NOTIFY)
        notify.flags |= dns.flags.AA

        # Make a response object to match the middleware's return
        response = dns.message.make_response(notify)
        # Provide an authoritative answer
        response.flags |= dns.flags.AA

        # Send the NOTIFY through the middleware
        # Lock can't be acquired, a NOTIFY is already being worked on
        # so just return what would have come back for a successful NOTIFY
        # This needs to be a one item tuple for the serialization middleware
        self.assertEqual(middleware.process_request(notify), (response,)) 
开发者ID:openstack,项目名称:designate,代码行数:26,代码来源:test_dnsutils.py

示例4: test_get_serial_number_nxdomain_deleted_zone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def test_get_serial_number_nxdomain_deleted_zone(self, mock_sleep):
        # The zone is not found and it's not was supposed be there
        response = RoObject(
            answer=[RoObject(
                rdclass=dns.rdataclass.IN,
                rdtype=dns.rdatatype.SOA
            )],
            rcode=mock.Mock(return_value=dns.rcode.NXDOMAIN)
        )
        zone = RoObject(name='zn', serial=0, action='DELETE')
        self.notify._make_and_send_dns_message = mock.Mock(
            return_value=(response, 1)
        )

        out = self.notify.get_serial_number(
            'c', zone, 'h', 1234, 1, 2, 3, 4
        )

        self.assertEqual(('NO_ZONE', 0, 3), out) 
开发者ID:openstack,项目名称:designate,代码行数:21,代码来源:test_notify.py

示例5: test_get_serial_number_ok

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def test_get_serial_number_ok(self, mock_sleep):
        zone = RoObject(name='zn', serial=314)
        ds = RoObject(items=[zone])
        response = RoObject(
            answer=[RoObject(
                name='zn',
                rdclass=dns.rdataclass.IN,
                rdtype=dns.rdatatype.SOA,
                to_rdataset=mock.Mock(return_value=ds)
            )],
            rcode=mock.Mock(return_value=dns.rcode.NOERROR)
        )
        self.notify._make_and_send_dns_message = mock.Mock(
            return_value=(response, 1)
        )

        out = self.notify.get_serial_number(
            'c', zone, 'h', 1234, 1, 2, 3, 4
        )

        self.assertEqual(('SUCCESS', 314, 3), out) 
开发者ID:openstack,项目名称:designate,代码行数:23,代码来源:test_notify.py

示例6: test_get_serial_number_too_many_retries

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def test_get_serial_number_too_many_retries(self, mock_sleep):
        zone = RoObject(name='zn', serial=314)
        ds = RoObject(items=[RoObject(serial=310)])
        response = RoObject(
            answer=[RoObject(
                name='zn',
                rdclass=dns.rdataclass.IN,
                rdtype=dns.rdatatype.SOA,
                to_rdataset=mock.Mock(return_value=ds)
            )],
            rcode=mock.Mock(return_value=dns.rcode.NOERROR)
        )
        self.notify._make_and_send_dns_message = mock.Mock(
            return_value=(response, 1)
        )

        out = self.notify.get_serial_number(
            'c', zone, 'h', 1234, 1, 2, 3, 4
        )

        self.assertEqual(('ERROR', 310, 0), out) 
开发者ID:openstack,项目名称:designate,代码行数:23,代码来源:test_notify.py

示例7: find_zone_serial

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def find_zone_serial(self, zone_name):
        LOG.debug("Finding %s", zone_name)

        zone_name = zone_name.rstrip('.')
        output = self.denominator.get_record(
            zone=zone_name,
            type='SOA',
            name=zone_name)
        try:
            text = ' '.join(output.split()[3:])
            rdata = dns.rdata.from_text(dns.rdataclass.IN,
                                        dns.rdatatype.SOA,
                                        text)
        except Exception:
            return None
        return rdata.serial 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:impl_denominator.py

示例8: iterate_rdatas

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def iterate_rdatas(self, rdtype=dns.rdatatype.ANY,
                       covers=dns.rdatatype.NONE):
        """Return a generator which yields (name, ttl, rdata) tuples for
        all rdatas in the zone which have the specified I{rdtype}
        and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
        then all rdatas will be matched.

        @param rdtype: int or string
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        """

        if isinstance(rdtype, string_types):
            rdtype = dns.rdatatype.from_text(rdtype)
        if isinstance(covers, string_types):
            covers = dns.rdatatype.from_text(covers)
        for (name, node) in self.iteritems():
            for rds in node:
                if rdtype == dns.rdatatype.ANY or \
                   (rds.rdtype == rdtype and rds.covers == covers):
                    for rdata in rds:
                        yield (name, rds.ttl, rdata) 
开发者ID:elgatito,项目名称:script.elementum.burst,代码行数:25,代码来源:zone.py

示例9: iterate_rdatas

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def iterate_rdatas(self, rdtype=dns.rdatatype.ANY,
                       covers=dns.rdatatype.NONE):
        """Return a generator which yields (name, ttl, rdata) tuples for
        all rdatas in the zone which have the specified I{rdtype}
        and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
        then all rdatas will be matched.

        @param rdtype: int or string
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        """

        if isinstance(rdtype, (str, unicode)):
            rdtype = dns.rdatatype.from_text(rdtype)
        if isinstance(covers, (str, unicode)):
            covers = dns.rdatatype.from_text(covers)
        for (name, node) in self.iteritems():
            for rds in node:
                if rdtype == dns.rdatatype.ANY or \
                   (rds.rdtype == rdtype and rds.covers == covers):
                    for rdata in rds:
                        yield (name, rds.ttl, rdata) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:zone.py

示例10: _build_resource_to_address_map

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def _build_resource_to_address_map(answer):
    """Return a dictionary that maps resource name to address.
    The response from any DNS query is a list of answer records and
    a list of additional records that may be useful.  In the case of
    SRV queries, the answer section contains SRV records which contain
    the service weighting information and a DNS resource name which
    requires further resolution.  The additional records segment may
    contain A records for the resources.  This function collects them
    into a dictionary that maps resource name to an array of addresses.
    :rtype: dict
    """
    mapping = collections.defaultdict(list)
    for resource in answer.response.additional:
        target = resource.name.to_text()
        mapping[target].extend(record.address
                               for record in resource.items
                               if record.rdtype == dns.rdatatype.A)
    return mapping 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:20,代码来源:dnsutils.py

示例11: __call__

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def __call__(self, request):
        """
        :param request: DNS Request Message
        :return: DNS Response Message
        """
        if request.opcode() == dns.opcode.QUERY:
            # Currently we expect exactly 1 question in the section
            # TSIG places the pseudo records into the additional section.
            if (len(request.question) != 1 or
                    request.question[0].rdclass != dns.rdataclass.IN):
                LOG.debug('Refusing due to numbers of questions or rdclass')
                yield self._handle_query_error(request, dns.rcode.REFUSED)
                return

            q_rrset = request.question[0]
            # Handle AXFR and IXFR requests with an AXFR responses for now.
            # It is permissible for a server to send an AXFR response when
            # receiving an IXFR request.
            if q_rrset.rdtype in (dns.rdatatype.AXFR, dns.rdatatype.IXFR):
                for response in self._handle_axfr(request):
                    yield response
                return

            else:
                for response in self._handle_record_query(request):
                    yield response
                return

        elif request.opcode() == dns.opcode.NOTIFY:
            for response in self._handle_notify(request):
                yield response
            return

        else:
            # Unhandled OpCode's include STATUS, IQUERY, UPDATE
            LOG.debug('Refusing unhandled opcode')
            yield self._handle_query_error(request, dns.rcode.REFUSED)
            return 
开发者ID:openstack,项目名称:designate,代码行数:40,代码来源:handler.py

示例12: _get_soa_answer

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def _get_soa_answer(self, serial):
        text = "\n".join(ANSWER) % {"serial": str(serial)}
        msg = dns.message.from_text(text)
        name = dns.name.from_text('example.com.')
        answer = dns.resolver.Answer(name, dns.rdatatype.SOA,
                                     dns.rdataclass.IN, msg)
        return answer 
开发者ID:openstack,项目名称:designate,代码行数:9,代码来源:test_handler.py

示例13: create_zone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def create_zone(self, zone):
        LOG.debug("Creating %s", zone.origin.to_text())
        zone_name = zone.origin.to_text(omit_final_dot=True)
        if six.PY3 and isinstance(zone_name, bytes):
            zone_name = zone_name.decode('utf-8')

        # Use SOA TTL as zone default TTL
        soa_record = zone.find_rrset(zone.origin, dns.rdatatype.SOA)
        rname = soa_record.items[0].rname.derelativize(origin=zone.origin)

        # Lock zone to prevent concurrent changes.
        with self._sync_zone(zone.origin):
            # NOTE: If zone already exists, denominator will update it with
            #       new values, in other a duplicate zone will be created if
            #       provider supports such functionality.
            self.denominator.create_zone(
                name=zone_name,
                ttl=soa_record.ttl,
                email=rname)

            # Add records one by one.
            for name, ttl, rtype, data in self._iterate_records(zone):
                # Some providers do not support creation of SOA record.
                rdatatype = dns.rdatatype.from_text(rtype)
                if rdatatype == dns.rdatatype.SOA:
                    continue

                self.denominator.create_record(
                    zone=zone_name,
                    name=name,
                    type=rtype,
                    ttl=ttl,
                    data=data) 
开发者ID:openstack,项目名称:designate,代码行数:35,代码来源:impl_denominator.py

示例14: _iterate_records

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def _iterate_records(self, zone):
        for rname, ttl, rdata in zone.iterate_rdatas():
            name = rname.derelativize(origin=zone.origin)
            name = name.to_text(omit_final_dot=True)
            if six.PY3 and isinstance(name, bytes):
                name = name.decode('utf-8')

            data = rdata.to_text(origin=zone.origin, relativize=False)
            yield name, ttl, dns.rdatatype.to_text(rdata.rdtype), data 
开发者ID:openstack,项目名称:designate,代码行数:11,代码来源:impl_denominator.py

示例15: _make_dns_message

# 需要导入模块: import dns [as 别名]
# 或者: from dns import rdatatype [as 别名]
def _make_dns_message(self, zone_name, opcode, rdatatype, rdclass):
        dns_message = dns.message.make_query(zone_name, rdatatype,
                                             rdclass=rdclass)
        dns_message.flags = 0

        dns_message.set_opcode(opcode)
        dns_message.flags |= dns.flags.AA

        return dns_message 
开发者ID:openstack,项目名称:designate,代码行数:11,代码来源:agent.py


注:本文中的dns.rdatatype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。