File: update_subid_support.py

package info (click to toggle)
freeipa 4.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 367,240 kB
  • sloc: javascript: 562,763; python: 310,289; ansic: 49,809; sh: 7,176; makefile: 2,589; xml: 343; sed: 16
file content (45 lines) | stat: -rw-r--r-- 1,274 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# Copyright (C) 2025  FreeIPA Contributors see COPYING for license
#
import logging
from ipalib import Registry, Updater, errors
from ipaserver.install import ldapupdate
from ipaplatform.paths import paths
from ipapython.dn import DN

logger = logging.getLogger(__name__)

register = Registry()


@register()
class update_subid_support(Updater):
    """
    Conditionally add SubID ranges when subID support is enabled
    """

    dna_plugin_dn = DN(
        ('cn', 'Distributed Numeric Assignment Plugin'),
        ('cn', 'plugins'),
        ('cn', 'config')
    )

    def execute(self, **options):
        subid_disabled = self.api.Object.config.is_config_option_present(
            'SubID:Disable')
        if not subid_disabled:
            ld = ldapupdate.LDAPUpdate(api=self.api)
            ld.update([paths.SUBID_GENERATORS_ULDIF])
        else:
            # make sure to remove DNA configuration
            conn = self.api.Backend.ldap2
            try:
                subid_dna_config = DN(
                    ('cn', 'Subordinate IDs'), self.dna_plugin_dn
                )
                entry = conn.get_entry(subid_dna_config)
                conn.delete_entry(entry)
            except errors.NotFound:
                pass

        return False, []