mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-25 16:31:08 -06:00
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
This commit is contained in:
parent
4f2f016dd5
commit
89d2280a79
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user