Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / landscape / lib / | server ip : 172.67.156.115 your ip : 172.69.130.140 H O M E |
Filename | /usr/lib/python2.7/dist-packages/landscape/lib/dns.py |
Size | 2.59 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 20-Feb-2014 23:01 |
Last accessed | 06-Jul-2025 23:36 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
"""DNS lookups for server autodiscovery."""
import logging
from twisted.names import dns
from twisted.names.client import Resolver
def discover_server(autodiscover_srv_query_string="",
autodiscover_a_query_string="", resolver=None):
"""
Look up the dns location of the landscape server.
@param autodiscover_srv_query_string: The query string to send to the DNS
server when making a SRV query.
@param autodiscover_a_query_string: The query string to send to the DNS
server when making a A query.
@type resolver: The resolver to use. If none is specified a resolver that
uses settings from /etc/resolv.conf will be created. (Testing only)
"""
if not resolver:
resolver = Resolver("/etc/resolv.conf")
d = _lookup_server_record(resolver, autodiscover_srv_query_string)
d.addErrback(_lookup_hostname, resolver, autodiscover_a_query_string)
return d
def _lookup_server_record(resolver, service_name):
"""
Do a DNS SRV record lookup for the location of the landscape server.
@type resolver: A resolver to use for DNS lookups
L{twisted.names.client.Resolver}.
@param service_name: The query string to send to the DNS server when
making a SRV query.
@return: A deferred containing either the hostname of the landscape server
if found or an empty string if not found.
"""
def lookup_done(result):
name = ""
for item in result:
for row in item:
if row.type == dns.SRV:
name = row.payload.target.name
break
return name
def lookup_failed(result):
logging.info("SRV lookup of %s failed." % service_name)
return result
d = resolver.lookupService(service_name)
d.addCallback(lookup_done)
d.addErrback(lookup_failed)
return d
def _lookup_hostname(result, resolver, hostname):
"""
Do a DNS name lookup for the location of the landscape server.
@param result: The result from a call to lookup_server_record.
@param resolver: The resolver to use for DNS lookups.
@param hostname: The query string to send to the DNS server when making
a A query.
@param return: A deferred containing the ip address of the landscape
server if found or None if not found.
"""
def lookup_done(result):
return result
def lookup_failed(result):
logging.info("Name lookup of %s failed." % hostname)
return result
d = resolver.getHostByName(hostname)
d.addCallback(lookup_done)
d.addErrback(lookup_failed)
return d
import logging
from twisted.names import dns
from twisted.names.client import Resolver
def discover_server(autodiscover_srv_query_string="",
autodiscover_a_query_string="", resolver=None):
"""
Look up the dns location of the landscape server.
@param autodiscover_srv_query_string: The query string to send to the DNS
server when making a SRV query.
@param autodiscover_a_query_string: The query string to send to the DNS
server when making a A query.
@type resolver: The resolver to use. If none is specified a resolver that
uses settings from /etc/resolv.conf will be created. (Testing only)
"""
if not resolver:
resolver = Resolver("/etc/resolv.conf")
d = _lookup_server_record(resolver, autodiscover_srv_query_string)
d.addErrback(_lookup_hostname, resolver, autodiscover_a_query_string)
return d
def _lookup_server_record(resolver, service_name):
"""
Do a DNS SRV record lookup for the location of the landscape server.
@type resolver: A resolver to use for DNS lookups
L{twisted.names.client.Resolver}.
@param service_name: The query string to send to the DNS server when
making a SRV query.
@return: A deferred containing either the hostname of the landscape server
if found or an empty string if not found.
"""
def lookup_done(result):
name = ""
for item in result:
for row in item:
if row.type == dns.SRV:
name = row.payload.target.name
break
return name
def lookup_failed(result):
logging.info("SRV lookup of %s failed." % service_name)
return result
d = resolver.lookupService(service_name)
d.addCallback(lookup_done)
d.addErrback(lookup_failed)
return d
def _lookup_hostname(result, resolver, hostname):
"""
Do a DNS name lookup for the location of the landscape server.
@param result: The result from a call to lookup_server_record.
@param resolver: The resolver to use for DNS lookups.
@param hostname: The query string to send to the DNS server when making
a A query.
@param return: A deferred containing the ip address of the landscape
server if found or None if not found.
"""
def lookup_done(result):
return result
def lookup_failed(result):
logging.info("Name lookup of %s failed." % hostname)
return result
d = resolver.getHostByName(hostname)
d.addCallback(lookup_done)
d.addErrback(lookup_failed)
return d