This patch implements the feature requested in ticket #600

The internal dns_is_enabled command returns whether the DNS service is
enable on at least one of the server in the domain.

The UI can use this command to determine whether to show the DNS
related configuration options.

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From a466f0bfdd7ecbd2220c8445df2116dd8a0b9292 Mon Sep 17 00:00:00 2001
From: Simo Sorce <sso...@redhat.com>
Date: Mon, 17 Jan 2011 12:28:24 -0500
Subject: [PATCH] Provide API to check if IPA DNS is enabled on some server

Fixes: https://fedorahosted.org/freeipa/ticket/600
---
 API.txt               |    5 +++++
 ipalib/plugins/dns.py |   25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/API.txt b/API.txt
index c53ecbd0d867dd529566a8335ae086ac58b4425f..844e9534c620858aeb4cc23e22b60fab48790dc0 100644
--- a/API.txt
+++ b/API.txt
@@ -467,6 +467,11 @@ option: Str('version?', exclude='webui', flags=['no_option', 'no_output'])
 output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly description of action performed')
 output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None))
 output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user")
+command: dns_is_enabled
+args: 0,0,3
+output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly description of action performed')
+output: Output('result', <type 'bool'>, 'True means the operation was successful')
+output: Output('value', <type 'unicode'>, "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 cf58098036f7056d20337b4d3b5f02b158b41360..e7dca5365a99ef34802d28a33c9ab0a4e811fe57 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -621,3 +621,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)
-- 
1.7.3.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to