From 89d2280a79579d1e1b438a7aac2fda77eac2e79b Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Mon, 20 Sep 2010 11:57:53 -0400 Subject: Add command to resolve a hostname. Returns True or raises NotFound. Note that this doesn't rely on IPA having a configured DNS server. It passes the host name to the resolver and doesn't try to do a lookup within the IPA DNS directly (e.g. no internal LDAP search). Tries to determine if a domain is included and if not then the IPA domain is added. This won't do the right thing if there are multiple configured subdomains. ticket 106 --- ipalib/plugins/dns.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'ipalib/plugins') diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index b154b5df..85a0d822 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -56,6 +56,12 @@ EXAMPLES: Delete zone example.com with all resource records: ipa dns-delete example.com + + Resolve a host name to see if it exists (will add default IPA domain + if one is not included): + ipa dns-resolve www.example.com + ipa dns-resolve www + """ # A few notes about the LDAP schema to make this plugin more understandable: @@ -71,6 +77,7 @@ from ipalib import Object, Command from ipalib import Flag, Int, Str, StrEnum from ipalib import _, ngettext from ipalib.output import Output, standard_entry, standard_list_of_entries +from ipapython import dnsclient # parent DN _zone_container_dn = api.env.container_dns @@ -833,3 +840,32 @@ class dns_show_rr(Command): textui.print_entry(entry_attrs) api.register(dns_show_rr) + + +class dns_resolve(Command): + """ + Resolve a host name in DNS + """ + has_output = output.standard_value + msg_summary = _('Found \'%(value)s\'') + + takes_args = ( + Str('hostname', + label=_('Hostname'), + ), + ) + + def execute(self, *args, **options): + query=args[0] + if query.find(api.env.domain) == -1 and query.find('.') == -1: + query = '%s.%s.' % (query, api.env.domain) + if query[-1] != '.': + query = query + '.' + rr = dnsclient.query(query, dnsclient.DNS_C_IN, dnsclient.DNS_T_A) + self.log.debug('%s' % rr) + if len(rr) == 0: + raise errors.NotFound(reason=_('Host \'%(host)s\' not found' % {'host':query})) + + return dict(result=True, value=query) + +api.register(dns_resolve) -- cgit