Detect when DNS is not configured and return an error message

It would be nicer if we disabled the command altogether but this would require
checking the server to see every time the ipa command is executed (which would
be bad). We can't store this in a configuration file because it is possible
to add a DNS post-install (and it would require adding this to every single
client install).

ticket 147
This commit is contained in:
Rob Crittenden 2010-10-11 10:50:07 -04:00
parent 0197ebbb7b
commit 16931cfe2d

View File

@ -126,6 +126,18 @@ def _get_record_dn(ldap, zone, idnsname):
return ldap.make_dn_from_rdn(rdn, parent_dn) return ldap.make_dn_from_rdn(rdn, parent_dn)
def dns_container_exists(ldap):
"""
See if the dns container exists. If not raise an exception.
"""
basedn = 'cn=dns,%s' % api.env.basedn
try:
ret = ldap.find_entries('(objectclass=*)', None, basedn,
ldap.SCOPE_BASE)
except errors.NotFound:
raise errors.NotFound(reason=_('DNS is not configured'))
class dns(Object): class dns(Object):
"""DNS zone/SOA record object.""" """DNS zone/SOA record object."""
label = _('DNS') label = _('DNS')
@ -213,6 +225,8 @@ class dns_add(crud.Create):
ldap = self.Backend.ldap2 ldap = self.Backend.ldap2
idnsname = args[0] idnsname = args[0]
dns_container_exists(ldap)
# build entry attributes # build entry attributes
entry_attrs = self.args_options_2_entry(*args, **options) entry_attrs = self.args_options_2_entry(*args, **options)
@ -264,6 +278,8 @@ class dns_del(crud.Delete):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
idnsname = args[0] idnsname = args[0]
dns_container_exists(ldap)
# build zone entry DN # build zone entry DN
dn = _get_zone_dn(ldap, idnsname) dn = _get_zone_dn(ldap, idnsname)
# just check if zone exists for now # just check if zone exists for now
@ -299,6 +315,8 @@ class dns_mod(crud.Update):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
idnsname = args[0] idnsname = args[0]
dns_container_exists(ldap)
# build entry attributes, don't include idnsname! # build entry attributes, don't include idnsname!
entry_attrs = self.args_options_2_entry(*tuple(), **options) entry_attrs = self.args_options_2_entry(*tuple(), **options)
entry_attrs['idnsallowdynupdate'] = str( entry_attrs['idnsallowdynupdate'] = str(
@ -339,6 +357,8 @@ class dns_find(crud.Search):
def execute(self, term, **options): def execute(self, term, **options):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
dns_container_exists(ldap)
# build search filter # build search filter
filter = ldap.make_filter_from_attr('idnsname', term, exact=False) filter = ldap.make_filter_from_attr('idnsname', term, exact=False)
@ -391,6 +411,8 @@ class dns_show(crud.Retrieve):
def execute(self, idnsname, **options): def execute(self, idnsname, **options):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_zone_dn(ldap, idnsname) dn = _get_zone_dn(ldap, idnsname)
@ -433,6 +455,8 @@ class dns_enable(Command):
def execute(self, zone): def execute(self, zone):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_zone_dn(ldap, zone) dn = _get_zone_dn(ldap, zone)
@ -467,6 +491,8 @@ class dns_disable(Command):
def execute(self, zone): def execute(self, zone):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_zone_dn(ldap, zone) dn = _get_zone_dn(ldap, zone)
@ -531,6 +557,8 @@ class dns_add_rr(Command):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
attr = ('%srecord' % type).lower() attr = ('%srecord' % type).lower()
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_record_dn(ldap, zone, idnsname) dn = _get_record_dn(ldap, zone, idnsname)
@ -632,6 +660,8 @@ class dns_del_rr(Command):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
attr = ('%srecord' % type).lower() attr = ('%srecord' % type).lower()
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_record_dn(ldap, zone, idnsname) dn = _get_record_dn(ldap, zone, idnsname)
@ -725,6 +755,8 @@ class dns_find_rr(Command):
else: else:
attr = None attr = None
dns_container_exists(ldap)
# build base dn for search # build base dn for search
base_dn = _get_zone_dn(ldap, zone) base_dn = _get_zone_dn(ldap, zone)
@ -832,6 +864,8 @@ class dns_show_rr(Command):
# shows all records associated with resource # shows all records associated with resource
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
dns_container_exists(ldap)
# build entry DN # build entry DN
dn = _get_record_dn(ldap, zone, idnsname) dn = _get_record_dn(ldap, zone, idnsname)