On 27.11.2015 15:57, Petr Vobornik wrote:
On 11/27/2015 02:50 PM, Martin Babinsky wrote:
On 11/20/2015 03:56 PM, Petr Vobornik wrote:




ACK

Pushed to master: c688954c27c219cb18aff968fc1f510afff93981

As we discussed offline, the server plugin should use topologysuffix name instead of the actual suffix DN for iparepltopomanagedsuffix. The attached patch fixes that.

Also the correct plural form of "suffix" is "suffixes", not "suffices" (<https://en.wiktionary.org/wiki/suffix#Noun>), I have fixed that in an additional patch.

--
Jan Cholasta
From 3f4d92ba335290e20810636ff6849290add457b9 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Mon, 30 Nov 2015 10:25:01 +0100
Subject: [PATCH 1/2] server: use topologysuffix name in
 iparepltopomanagedsuffix

---
 API.txt                  |  9 +++--
 VERSION                  |  4 +-
 ipalib/plugins/server.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 103 insertions(+), 7 deletions(-)

diff --git a/API.txt b/API.txt
index 4304887..1e6942d 100644
--- a/API.txt
+++ b/API.txt
@@ -3821,26 +3821,29 @@ output: Output('result', <type 'dict'>, None)
 output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
 output: ListOfPrimaryKeys('value', None, None)
 command: server_find
-args: 1,10,4
+args: 1,12,4
 arg: Str('criteria?', noextrawhitespace=False)
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
 option: Str('cn', attribute=True, autofill=False, cli_name='name', multivalue=False, primary_key=True, query=True, required=False)
 option: Int('ipamaxdomainlevel', attribute=True, autofill=False, cli_name='maxlevel', multivalue=False, query=True, required=False)
 option: Int('ipamindomainlevel', attribute=True, autofill=False, cli_name='minlevel', multivalue=False, query=True, required=False)
-option: Str('iparepltopomanagedsuffix', attribute=True, autofill=False, cli_name='suffix', multivalue=True, query=True, required=False)
+option: Flag('no_members', autofill=True, default=False, exclude='webui')
+option: Str('no_topologysuffix', cli_name='no_topologysuffixes', csv=True, multivalue=True, required=False)
 option: Flag('pkey_only?', autofill=True, default=False)
 option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
 option: Int('sizelimit?', autofill=False, minvalue=0)
 option: Int('timelimit?', autofill=False, minvalue=0)
+option: Str('topologysuffix', cli_name='topologysuffixes', csv=True, multivalue=True, required=False)
 option: Str('version?', exclude='webui')
 output: Output('count', <type 'int'>, None)
 output: ListOfEntries('result', (<type 'list'>, <type 'tuple'>), Gettext('A list of LDAP entries', domain='ipa', localedir=None))
 output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
 output: Output('truncated', <type 'bool'>, None)
 command: server_show
-args: 1,4,3
+args: 1,5,3
 arg: Str('cn', attribute=True, cli_name='name', multivalue=False, primary_key=True, query=True, required=True)
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
+option: Flag('no_members', autofill=True, default=False, exclude='webui')
 option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
 option: Flag('rights', autofill=True, default=False)
 option: Str('version?', exclude='webui')
diff --git a/VERSION b/VERSION
index 2c5979a..69a8a29 100644
--- a/VERSION
+++ b/VERSION
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
 #                                                      #
 ########################################################
 IPA_API_VERSION_MAJOR=2
-IPA_API_VERSION_MINOR=159
-# Last change: pvoborni - treat server's suffix as multivalued attribute in API
+IPA_API_VERSION_MINOR=160
+# Last change: jcholast - server: use topologysuffix name in iparepltopomanagedsuffix
diff --git a/ipalib/plugins/server.py b/ipalib/plugins/server.py
index af7f102..8284a58 100644
--- a/ipalib/plugins/server.py
+++ b/ipalib/plugins/server.py
@@ -45,6 +45,12 @@ class server(LDAPObject):
     ]
     label = _('IPA Servers')
     label_singular = _('IPA Server')
+    attribute_members = {
+        'iparepltopomanagedsuffix': ['topologysuffix'],
+    }
+    relationships = {
+        'iparepltopomanagedsuffix': ('Managed', '', 'no_'),
+    }
     takes_params = (
         Str(
             'cn',
@@ -55,8 +61,12 @@ class server(LDAPObject):
         ),
         Str(
             'iparepltopomanagedsuffix*',
-            cli_name='suffix',
-            label=_('Managed suffix'),
+            flags={'no_create', 'no_update', 'no_search'},
+        ),
+        Str(
+            'iparepltopomanagedsuffix_topologysuffix*',
+            label=_('Managed suffixes'),
+            flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
         ),
         Int(
             'ipamindomainlevel',
@@ -74,6 +84,22 @@ class server(LDAPObject):
         ),
     )
 
+    def _get_suffixes(self):
+        suffixes = self.api.Command.topologysuffix_find(
+            all=True, raw=True,
+        )['result']
+        suffixes = [(s['iparepltopoconfroot'][0], s['dn']) for s in suffixes]
+        return suffixes
+
+    def _apply_suffixes(self, entry, suffixes):
+        # change suffix DNs to topologysuffix entry DNs
+        # this fixes LDAPObject.convert_attribute_members() for suffixes
+        suffixes = dict(suffixes)
+        if 'iparepltopomanagedsuffix' in entry:
+            entry['iparepltopomanagedsuffix'] = [
+                suffixes.get(m, m) for m in entry['iparepltopomanagedsuffix']
+            ]
+
 
 @register()
 class server_find(LDAPSearch):
@@ -83,12 +109,79 @@ class server_find(LDAPSearch):
         '%(count)d IPA server matched',
         '%(count)d IPA servers matched', 0
     )
+    member_attributes = ['iparepltopomanagedsuffix']
+
+    def get_options(self):
+        for option in super(server_find, self).get_options():
+            if option.name == 'topologysuffix':
+                option = option.clone(cli_name='topologysuffixes')
+            elif option.name == 'no_topologysuffix':
+                option = option.clone(cli_name='no_topologysuffixes')
+            yield option
+
+    def get_member_filter(self, ldap, **options):
+        options.pop('topologysuffix', None)
+        options.pop('no_topologysuffix', None)
+
+        return super(server_find, self).get_member_filter(ldap, **options)
+
+    def pre_callback(self, ldap, filters, attrs_list, base_dn, scope,
+                     *args, **options):
+        included = options.get('topologysuffix')
+        excluded = options.get('no_topologysuffix')
+
+        if included or excluded:
+            topologysuffix = self.api.Object.topologysuffix
+            suffixes = self.obj._get_suffixes()
+            suffixes = {s[1]: s[0] for s in suffixes}
+
+            if included:
+                included = [topologysuffix.get_dn(pk) for pk in included]
+                try:
+                    included = [suffixes[dn] for dn in included]
+                except KeyError:
+                    # force empty result
+                    filter = '(!(objectclass=*))'
+                else:
+                    filter = ldap.make_filter_from_attr(
+                        'iparepltopomanagedsuffix', included, ldap.MATCH_ALL
+                    )
+                filters = ldap.combine_filters(
+                    (filters, filter), ldap.MATCH_ALL
+                )
+
+            if excluded:
+                excluded = [topologysuffix.get_dn(pk) for pk in excluded]
+                excluded = [suffixes[dn] for dn in excluded if dn in suffixes]
+                filter = ldap.make_filter_from_attr(
+                    'iparepltopomanagedsuffix', excluded, ldap.MATCH_NONE
+                )
+                filters = ldap.combine_filters(
+                    (filters, filter), ldap.MATCH_ALL
+                )
+
+        return (filters, base_dn, scope)
+
+    def post_callback(self, ldap, entries, truncated, *args, **options):
+        if not options.get('raw', False):
+            suffixes = self.obj._get_suffixes()
+            for entry in entries:
+                self.obj._apply_suffixes(entry, suffixes)
+
+        return truncated
 
 
 @register()
 class server_show(LDAPRetrieve):
     __doc__ = _('Show IPA server.')
 
+    def post_callback(self, ldap, dn, entry, *keys, **options):
+        if not options.get('raw', False):
+            suffixes = self.obj._get_suffixes()
+            self.obj._apply_suffixes(entry, suffixes)
+
+        return dn
+
 
 @register()
 class server_del(LDAPDelete):
-- 
2.4.3

From b3f09614602e5f932a879e5663255d486f5c9cd8 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Fri, 27 Nov 2015 08:07:57 +0100
Subject: [PATCH 2/2] topology: replace "suffices" with "suffixes"

---
 ipalib/plugins/topology.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ipalib/plugins/topology.py b/ipalib/plugins/topology.py
index 2c43758..2c54bbc 100644
--- a/ipalib/plugins/topology.py
+++ b/ipalib/plugins/topology.py
@@ -328,11 +328,11 @@ class topologysuffix(LDAPObject):
     """
     container_dn = api.env.container_topology
     object_name = _('suffix')
-    object_name_plural = _('suffices')
+    object_name_plural = _('suffixes')
     object_class = ['iparepltopoconf']
     default_attributes = ['cn', 'ipaReplTopoConfRoot']
     search_display_attributes = ['cn', 'ipaReplTopoConfRoot']
-    label = _('Topology suffices')
+    label = _('Topology suffixes')
     label_singular = _('Topology suffix')
 
     takes_params = (
@@ -354,11 +354,11 @@ class topologysuffix(LDAPObject):
 
 @register()
 class topologysuffix_find(LDAPSearch):
-    __doc__ = _('Search for topology suffices.')
+    __doc__ = _('Search for topology suffixes.')
 
     msg_summary = ngettext(
         '%(count)d topology suffix matched',
-        '%(count)d topology suffices matched', 0
+        '%(count)d topology suffixes matched', 0
     )
 
 
-- 
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