diff options
author | Rob Crittenden <rcritten@redhat.com> | 2010-10-11 10:50:07 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2010-10-13 13:00:07 -0400 |
commit | 16931cfe2d984abc2d80687d5d1d7b4579f6dd33 (patch) | |
tree | 00b2c90ed66ffd921bea77ef494848fe97ca664e | |
parent | 0197ebbb7b20252eaa08d644c9cb5fcc7c715022 (diff) | |
download | freeipa-16931cfe2d984abc2d80687d5d1d7b4579f6dd33.tar.gz freeipa-16931cfe2d984abc2d80687d5d1d7b4579f6dd33.tar.xz freeipa-16931cfe2d984abc2d80687d5d1d7b4579f6dd33.zip |
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
-rw-r--r-- | ipalib/plugins/dns.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index 77bec45f1..a3e6c1eeb 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -126,6 +126,18 @@ def _get_record_dn(ldap, zone, idnsname): 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): """DNS zone/SOA record object.""" label = _('DNS') @@ -213,6 +225,8 @@ class dns_add(crud.Create): ldap = self.Backend.ldap2 idnsname = args[0] + dns_container_exists(ldap) + # build entry attributes entry_attrs = self.args_options_2_entry(*args, **options) @@ -264,6 +278,8 @@ class dns_del(crud.Delete): ldap = self.api.Backend.ldap2 idnsname = args[0] + dns_container_exists(ldap) + # build zone entry DN dn = _get_zone_dn(ldap, idnsname) # just check if zone exists for now @@ -299,6 +315,8 @@ class dns_mod(crud.Update): ldap = self.api.Backend.ldap2 idnsname = args[0] + dns_container_exists(ldap) + # build entry attributes, don't include idnsname! entry_attrs = self.args_options_2_entry(*tuple(), **options) entry_attrs['idnsallowdynupdate'] = str( @@ -339,6 +357,8 @@ class dns_find(crud.Search): def execute(self, term, **options): ldap = self.api.Backend.ldap2 + dns_container_exists(ldap) + # build search filter filter = ldap.make_filter_from_attr('idnsname', term, exact=False) @@ -391,6 +411,8 @@ class dns_show(crud.Retrieve): def execute(self, idnsname, **options): ldap = self.api.Backend.ldap2 + dns_container_exists(ldap) + # build entry DN dn = _get_zone_dn(ldap, idnsname) @@ -433,6 +455,8 @@ class dns_enable(Command): def execute(self, zone): ldap = self.api.Backend.ldap2 + dns_container_exists(ldap) + # build entry DN dn = _get_zone_dn(ldap, zone) @@ -467,6 +491,8 @@ class dns_disable(Command): def execute(self, zone): ldap = self.api.Backend.ldap2 + dns_container_exists(ldap) + # build entry DN dn = _get_zone_dn(ldap, zone) @@ -531,6 +557,8 @@ class dns_add_rr(Command): ldap = self.api.Backend.ldap2 attr = ('%srecord' % type).lower() + dns_container_exists(ldap) + # build entry DN dn = _get_record_dn(ldap, zone, idnsname) @@ -632,6 +660,8 @@ class dns_del_rr(Command): ldap = self.api.Backend.ldap2 attr = ('%srecord' % type).lower() + dns_container_exists(ldap) + # build entry DN dn = _get_record_dn(ldap, zone, idnsname) @@ -725,6 +755,8 @@ class dns_find_rr(Command): else: attr = None + dns_container_exists(ldap) + # build base dn for search base_dn = _get_zone_dn(ldap, zone) @@ -832,6 +864,8 @@ class dns_show_rr(Command): # shows all records associated with resource ldap = self.api.Backend.ldap2 + dns_container_exists(ldap) + # build entry DN dn = _get_record_dn(ldap, zone, idnsname) |