https://fedorahosted.org/freeipa/ticket/5181

--
Martin^3 Babinsky
From 118d0755142b7e801e87439ef1c84f476fd8f825 Mon Sep 17 00:00:00 2001
From: Martin Babinsky <mbabi...@redhat.com>
Date: Thu, 22 Oct 2015 10:26:41 +0200
Subject: [PATCH] show optionally configured components in server-find/show
 command output

https://fedorahosted.org/freeipa/ticket/5181
---
 ipalib/plugins/server.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/ipalib/plugins/server.py b/ipalib/plugins/server.py
index 5808c9c5ea78fce4a15cd2e49740fbe20bca8358..d2c53ffbc08f3fcae7003eb09c09a443dafe621d 100644
--- a/ipalib/plugins/server.py
+++ b/ipalib/plugins/server.py
@@ -28,6 +28,16 @@ EXAMPLES:
 
 register = Registry()
 
+OPTIONAL_SERVICES = {
+    'DNS',
+    'CA',
+    'KRA',
+    'ADTRUST',
+    'EXTID',
+    'DNSKeyExporter',
+    'DNSSEC',
+    'DNSKeySync',
+}
 
 @register()
 class server(LDAPObject):
@@ -72,8 +82,26 @@ class server(LDAPObject):
             doc=_('Maximum domain level'),
             flags={'no_create', 'no_update'},
         ),
+        Str(
+            'ipaoptionalcomponents*',
+            cli_name='components',
+            label=_('Optional components'),
+            doc=_('Optional components running on the server'),
+            flags={'no_create', 'no_update', 'no_search', 'virtual_attribute'}
+        )
     )
 
+    def get_optional_components(self, ldap, dn, entry_attrs):
+        search_filter=('(&(objectclass=ipaConfigObject)'
+                       '(ipaConfigString=enabledService))')
+        result = ldap.find_entries(filter=search_filter, base_dn=dn,
+                                   attrs_list=['cn'])[0]
+        opt_components = [
+            r['cn'][0] for r in result if r['cn'][0] in OPTIONAL_SERVICES
+        ]
+
+        entry_attrs['ipaoptionalcomponents'] = opt_components
+
 
 @register()
 class server_find(LDAPSearch):
@@ -84,11 +112,21 @@ class server_find(LDAPSearch):
         '%(count)d IPA servers matched', 0
     )
 
+    def post_callback(self, ldap, entries, truncated, *args, **options):
+        for entry in entries:
+            self.obj.get_optional_components(ldap, entry.dn, entry)
+
+        return super(server_find, self).post_callback(
+            ldap, entries, truncated, *args, **options)
+
 
 @register()
 class server_show(LDAPRetrieve):
     __doc__ = _('Show IPA server.')
 
+    def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+        self.obj.get_optional_components(ldap, dn, entry_attrs)
+        return dn
 
 @register()
 class server_del(LDAPDelete):
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to