pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
f65af0
From ef7fe9e24844f73a27650d4d2a4f118cc364caac Mon Sep 17 00:00:00 2001
979ee0
From: Christian Heimes <cheimes@redhat.com>
979ee0
Date: Thu, 5 Jul 2018 23:50:37 +0200
979ee0
Subject: [PATCH] Query for server role IPA master
979ee0
979ee0
server_find and server_role plugin were hiding IPA master role
979ee0
information. It's now possible to fetch IPA master role information and
979ee0
to filter by IPA master role, e.g. to ignore servers that have some
979ee0
services configured but not (yet) enabled.
979ee0
979ee0
See: https://pagure.io/freeipa/issue/7566
979ee0
Signed-off-by: Christian Heimes <cheimes@redhat.com>
979ee0
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
979ee0
---
979ee0
 API.txt                         |  3 ++-
979ee0
 ipaserver/plugins/server.py     |  9 +++++++--
979ee0
 ipaserver/plugins/serverrole.py | 18 +++++++++++++++---
979ee0
 3 files changed, 24 insertions(+), 6 deletions(-)
979ee0
979ee0
diff --git a/API.txt b/API.txt
f65af0
index 96c1548331750577e899f397f6f5a9a9d863248a..0e09e58a6ecaa4f724fb0c92b4faaf64df9fab5a 100644
979ee0
--- a/API.txt
979ee0
+++ b/API.txt
979ee0
@@ -4421,9 +4421,10 @@ output: Entry('result')
979ee0
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
979ee0
 output: PrimaryKey('value')
979ee0
 command: server_role_find/1
979ee0
-args: 1,8,4
979ee0
+args: 1,9,4
979ee0
 arg: Str('criteria?')
979ee0
 option: Flag('all', autofill=True, cli_name='all', default=False)
979ee0
+option: Flag('include_master', autofill=True, default=False)
979ee0
 option: Flag('raw', autofill=True, cli_name='raw', default=False)
979ee0
 option: Str('role_servrole?', autofill=False, cli_name='role')
979ee0
 option: Str('server_server?', autofill=False, cli_name='server')
979ee0
diff --git a/ipaserver/plugins/server.py b/ipaserver/plugins/server.py
f65af0
index 4ea6f5b4b458db701c6c041d1c05cf4a7c6bc8a4..e265883e3637938e3df5ecf132f4add62413a997 100644
979ee0
--- a/ipaserver/plugins/server.py
979ee0
+++ b/ipaserver/plugins/server.py
f65af0
@@ -205,7 +205,10 @@ class server(LDAPObject):
979ee0
             return
979ee0
 
979ee0
         enabled_roles = self.api.Command.server_role_find(
979ee0
-            server_server=entry_attrs['cn'][0], status=ENABLED)['result']
979ee0
+            server_server=entry_attrs['cn'][0],
979ee0
+            status=ENABLED,
979ee0
+            include_master=True,
979ee0
+        )['result']
979ee0
 
979ee0
         enabled_role_names = [r[u'role_servrole'] for r in enabled_roles]
979ee0
 
f65af0
@@ -339,7 +342,9 @@ class server_find(LDAPSearch):
979ee0
             role_status = self.api.Command.server_role_find(
979ee0
                 server_server=None,
979ee0
                 role_servrole=role,
979ee0
-                status=ENABLED)['result']
979ee0
+                status=ENABLED,
979ee0
+                include_master=True,
979ee0
+            )['result']
979ee0
 
979ee0
             return set(
979ee0
                 r[u'server_server'] for r in role_status)
979ee0
diff --git a/ipaserver/plugins/serverrole.py b/ipaserver/plugins/serverrole.py
f65af0
index 1b19c7e867a0223d1c2e72372d9f3dc65fc5f771..5b7ccfb342d0a54bfd6f2cdc53c7d31201ed5989 100644
979ee0
--- a/ipaserver/plugins/serverrole.py
979ee0
+++ b/ipaserver/plugins/serverrole.py
979ee0
@@ -5,7 +5,7 @@
979ee0
 from ipalib.crud import Retrieve, Search
979ee0
 from ipalib.errors import NotFound
979ee0
 from ipalib.frontend import Object
979ee0
-from ipalib.parameters import Int, Str, StrEnum
979ee0
+from ipalib.parameters import Flag, Int, Str, StrEnum
979ee0
 from ipalib.plugable import Registry
979ee0
 from ipalib import _, ngettext
979ee0
 
979ee0
@@ -129,6 +129,10 @@ class server_role_find(Search):
979ee0
             minvalue=0,
979ee0
             autofill=False,
979ee0
         ),
979ee0
+        Flag(
979ee0
+            'include_master',
979ee0
+            doc=_('Include IPA master entries'),
979ee0
+        )
979ee0
     )
979ee0
 
979ee0
     def execute(self, *keys, **options):
979ee0
@@ -151,8 +155,16 @@ class server_role_find(Search):
979ee0
             role_servrole=role_name,
979ee0
             status=status)
979ee0
 
979ee0
-        result = [
979ee0
-            r for r in role_status if r[u'role_servrole'] != "IPA master"]
979ee0
+        # Don't display "IPA master" information unless the role is
979ee0
+        # requested explicitly. All servers are considered IPA masters,
979ee0
+        # except for replicas during installation.
979ee0
+        if options.get('include_master') or role_name == "IPA master":
979ee0
+            result = role_status
979ee0
+        else:
979ee0
+            result = [
979ee0
+                r for r in role_status
979ee0
+                if r[u'role_servrole'] != "IPA master"
979ee0
+            ]
979ee0
         return dict(
979ee0
             result=result,
979ee0
             count=len(result),
979ee0
-- 
979ee0
2.17.1
979ee0