summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/dns.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2010-09-20 11:57:53 -0400
committerRob Crittenden <rcritten@redhat.com>2010-09-23 11:50:16 -0400
commit89d2280a79579d1e1b438a7aac2fda77eac2e79b (patch)
tree48fefc25d63c8d4d36935e96e965ff8575391fdc /ipalib/plugins/dns.py
parent4f2f016dd56beaeadf441d73502e8c0f475b6968 (diff)
downloadfreeipa-89d2280a79579d1e1b438a7aac2fda77eac2e79b.tar.gz
freeipa-89d2280a79579d1e1b438a7aac2fda77eac2e79b.tar.xz
freeipa-89d2280a79579d1e1b438a7aac2fda77eac2e79b.zip
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
Diffstat (limited to 'ipalib/plugins/dns.py')
-rw-r--r--ipalib/plugins/dns.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index b154b5dff..85a0d8225 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)