From 835436df1549578932705f5722bc78ec985c2f69 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Jan 20 2011 01:23:42 +0000 Subject: Provide API to check if IPA DNS is enabled on some server Fixes: https://fedorahosted.org/freeipa/ticket/600 --- diff --git a/API.txt b/API.txt index 2fe5723..650c47a 100644 --- a/API.txt +++ b/API.txt @@ -467,6 +467,11 @@ option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) output: Output('summary', (, ), 'User-friendly description of action performed') output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: dns_is_enabled +args: 0,0,3 +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Output('result', , 'True means the operation was successful') +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") command: dns_resolve args: 1,0,3 arg: Str('hostname', label=Gettext('Hostname', domain='ipa', localedir=None)) diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index a2d0b8b..e1d9ce6 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -616,3 +616,28 @@ class dns_resolve(Command): return dict(result=True, value=query) api.register(dns_resolve) + +class dns_is_enabled(Command): + """ + Checks if any of the servers has the DNS service enabled. + """ + INTERNAL = True + has_output = output.standard_value + + base_dn = 'cn=master,cn=ipa,cn=etc,%s' % api.env.basedn + filter = '(&(objectClass=ipaConfigObject)(cn=DNS))' + + def execute(self, *args, **options): + ldap = self.api.Backend.ldap2 + dns_enabled = False + + try: + ent = ldap.find_entries(filter=filter, base_dn=base_dn) + if len(e): + dns_enabled = True + except Exception, e: + pass + + return dict(result=dns_enabled, value=u'') + +api.register(dns_is_enabled)