diff options
Diffstat (limited to 'commands/sssd/lmi')
-rw-r--r-- | commands/sssd/lmi/__init__.py | 30 | ||||
-rw-r--r-- | commands/sssd/lmi/scripts/__init__.py | 1 | ||||
-rw-r--r-- | commands/sssd/lmi/scripts/sssd/__init__.py | 192 | ||||
-rw-r--r-- | commands/sssd/lmi/scripts/sssd/domains_cmd.py | 114 | ||||
-rw-r--r-- | commands/sssd/lmi/scripts/sssd/services_cmd.py | 94 | ||||
-rw-r--r-- | commands/sssd/lmi/scripts/sssd/sssd_cmd.py | 123 |
6 files changed, 554 insertions, 0 deletions
diff --git a/commands/sssd/lmi/__init__.py b/commands/sssd/lmi/__init__.py new file mode 100644 index 0000000..ca65877 --- /dev/null +++ b/commands/sssd/lmi/__init__.py @@ -0,0 +1,30 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +# +# Authors: Michal Minar <miminar@redhat.com> +# +__import__('pkg_resources').declare_namespace(__name__) diff --git a/commands/sssd/lmi/scripts/__init__.py b/commands/sssd/lmi/scripts/__init__.py new file mode 100644 index 0000000..de40ea7 --- /dev/null +++ b/commands/sssd/lmi/scripts/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/commands/sssd/lmi/scripts/sssd/__init__.py b/commands/sssd/lmi/scripts/sssd/__init__.py new file mode 100644 index 0000000..07ecd5b --- /dev/null +++ b/commands/sssd/lmi/scripts/sssd/__init__.py @@ -0,0 +1,192 @@ +# SSSD Providers +# +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +# +# +# Authors: Pavel Brezina <pbrezina@redhat.com> +# +""" +LMI SSSD provider client library. + +This set of functions can list and manage SSSD's responders and domains. +""" + +from lmi.scripts.common.errors import LmiFailed +from lmi.shell.LMIInstanceName import LMIInstanceName +from lmi.scripts.common import get_computer_system +from lmi.scripts.common import get_logger +import pywbem +import lmi.scripts.common + +LOG = get_logger(__name__) + +def debug_level(level): + """ + Return hexadecimal representation of debug level. + + :type level: int + :param level: Debug level. + :rtype: string + """ + return "%#.4x" % level + +# +# SSSD +# + +def set_debug_level(ns, level, until_restart, components): + rval = 0 + for component in ns.LMI_SSSDComponent.instances(): + found = False + if components is not None and len(components) > 0: + for name in components: + if component.Name == name: + found = True + continue + if not found: + continue + if until_restart: + (rval, _, msg) = component.SetDebugLevelTemporarily({'debug_level' : int(level, 16)}) + else: + (rval, _, msg) = component.SetDebugLevelPermanently({'debug_level' : int(level, 16)}) + if rval == 0: + LOG().info('Debug level of "%s" changed to "%#.4x".', + component.Name, level) + elif msg: + LOG().error('Operation failed on "%s": %s.', + component.Name, errorstr) + return rval + +# +# Services +# + +def list_services(ns, kind='all'): + for svc in ns.LMI_SSSDResponder.instances(): + if kind == 'disabled' and svc.IsEnabled == True: + continue + if kind == 'enabled' and svc.IsEnabled == False: + continue + yield svc + +def get_service(ns, service): + keys = {'Name': service} + try: + inst = ns.LMI_SSSDResponder.new_instance_name(keys).to_instance() + except pywbem.CIMError, err: + if err[0] == pywbem.CIM_ERR_NOT_FOUND: + raise LmiFailed("Cannot find the service: %s" % service) + raise + return inst + +def enable_service(ns, service): + instance = get_service(ns, service) + (rval, _, msg) = instance.Enable() + if rval == 0: + LOG().info('Service "%s" enabled', service) + elif msg: + LOG().error('Operation failed on "%s": %s.', service, errorstr) + return rval + +def disable_service(ns, service): + instance = get_service(ns, service) + (rval, _, msg) = instance.Disable() + if rval == 0: + LOG().info('Service "%s" disabled', service) + elif msg: + LOG().error('Operation failed on "%s": %s.', service, errorstr) + return rval + +# +# Domains +# + +def list_backends(ns, kind='all'): + for backend in ns.LMI_SSSDBackend.instances(): + if kind == 'disabled' and backend.IsEnabled == True: + continue + if kind == 'enabled' and backend.IsEnabled == False: + continue + yield backend + +def get_provider(ns, type, backend): + for provider in backend.associators(AssocClass="LMI_SSSDBackendProvider"): + if provider.Type == type: + return provider.Module + return 'ldap' + +def get_domain(ns, domain): + keys = {'Name': domain} + try: + inst = ns.LMI_SSSDDomain.new_instance_name(keys).to_instance() + except pywbem.CIMError, err: + if err[0] == pywbem.CIM_ERR_NOT_FOUND: + raise LmiFailed("Cannot find the domain: %s" % service) + raise + return inst + +def get_backend(ns, domain): + keys = {'Name': domain} + try: + inst = ns.LMI_SSSDBackend.new_instance_name(keys).to_instance() + except pywbem.CIMError, err: + if err[0] == pywbem.CIM_ERR_NOT_FOUND: + raise LmiFailed("Cannot find the backend: %s" % service) + raise + return inst + +def enable_backend(ns, domain): + instance = get_backend(ns, domain) + (rval, _, msg) = instance.Enable() + if rval == 0: + LOG().info('Domain "%s" enabled', domain) + elif msg: + LOG().error('Operation failed on "%s": %s.', domain, errorstr) + return rval + +def disable_backend(ns, domain): + instance = get_backend(ns, domain) + (rval, _, msg) = instance.Disable() + if rval == 0: + LOG().info('Domain "%s" disabled', domain) + elif msg: + LOG().error('Operation failed on "%s": %s.', domain, errorstr) + return rval + +# +# Subdomains +# + +def list_subdomains_names(ns, domain): + subdomains = domain.associators(AssocClass="LMI_SSSDDomainSubdomain", + ResultRole="Subdomain") + + for subdomain in subdomains: + yield subdomain.Name + +def list_subdomains_comma_separated(ns, domain): + return ', '.join(list_subdomains_names(ns, domain)) diff --git a/commands/sssd/lmi/scripts/sssd/domains_cmd.py b/commands/sssd/lmi/scripts/sssd/domains_cmd.py new file mode 100644 index 0000000..5d5a84b --- /dev/null +++ b/commands/sssd/lmi/scripts/sssd/domains_cmd.py @@ -0,0 +1,114 @@ +# SSSD Providers +# +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +# +# Authors: Pavel Brezina <pbrezina@redhat.com> +# +""" +SSSD service management. + +Usage: + %(cmd)s list [(--enabled | --disabled)] + %(cmd)s show <domain> + %(cmd)s enable <domain> + %(cmd)s disable <domain> + + +Commands: + list Prints all domains managed by SSSD. + show Prints information about provided domain. + enable Enable domain in SSSD. + disable Disable domain in SSSD. + +List options: + --enabled List only enabled domains. + --disabled List only disabled domains. +""" + +from lmi.scripts.common import command +from lmi.scripts import sssd + +class List(command.LmiLister): + COLUMNS = ('Name', 'Enabled', 'Debug Level', 'ID Provider') + + def execute(self, ns, _enabled, _disabled): + kind = 'all' + if _enabled: + kind = 'enabled' + elif _disabled: + kind = 'disabled' + + for s in sorted(sssd.list_backends(ns, kind), key=lambda i: i.Name): + yield (s.Name, s.IsEnabled, sssd.debug_level(s.DebugLevel), + sssd.get_provider(ns, 'id_provider', s)) + +class Show(command.LmiShowInstance): + DYNAMIC_PROPERTIES = True + + def execute(self, ns, domain): + for backend in ns.LMI_SSSDBackend.instances(): + if backend.Name == domain and not backend.IsEnabled: + columns = ( + 'Name', + ('Enabled', 'IsEnabled')) + return columns, backend + + columns = ( + 'Name', + ('Enabled', lambda i: True), + ('ID Provider', 'Provider'), + ('Primary servers', lambda i: ', '.join(i.PrimaryServers)), + ('Backup servers', lambda i: ', '.join(i.BackupServers)), + ('Subdomains', lambda i: sssd. \ + list_subdomains_comma_separated(ns, i)), + ('Parent domain', 'ParentDomain'), + 'Realm', + 'Forest', + ('Enumerable', 'Enumerate'), + ('Minimum ID value', 'MinId'), + ('Maximum ID value', 'MaxId'), + ('Use fully qualified names', 'UseFullyQualifiedNames'), + ('Fully qualified name format', 'FullyQualifiedNameFormat'), + ('Login expression', 'LoginFormat')) + return columns, sssd.get_domain(ns, domain) + +class Enable(command.LmiCheckResult): + CALLABLE = sssd.enable_backend + EXPECT = 0 + +class Disable(command.LmiCheckResult): + CALLABLE = sssd.disable_backend + EXPECT = 0 + +class DomainCommands(command.LmiCommandMultiplexer): + COMMANDS = { + 'list' : List, + 'show' : Show, + 'enable' : Enable, + 'disable' : Disable + } + OWN_USAGE = __doc__ diff --git a/commands/sssd/lmi/scripts/sssd/services_cmd.py b/commands/sssd/lmi/scripts/sssd/services_cmd.py new file mode 100644 index 0000000..e166527 --- /dev/null +++ b/commands/sssd/lmi/scripts/sssd/services_cmd.py @@ -0,0 +1,94 @@ +# SSSD Providers +# +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +# +# Authors: Pavel Brezina <pbrezina@redhat.com> +# +""" +SSSD service management. + +Usage: + %(cmd)s list [(--enabled | --disabled)] + %(cmd)s show <service> + %(cmd)s enable <service> + %(cmd)s disable <service> + + +Commands: + list Prints all services supported by SSSD. + show Prints information about provided service. + enable Enable service in SSSD. + disable Disable service in SSSD. + +List options: + --enabled List only enabled services. + --disabled List only disabled services. +""" + +from lmi.scripts.common import command +from lmi.scripts import sssd + +class List(command.LmiLister): + COLUMNS = ('Name', "Enabled", "Debug Level") + + def execute(self, ns, _enabled, _disabled): + kind = 'all' + if _enabled: + kind = 'enabled' + elif _disabled: + kind = 'disabled' + + for s in sorted(sssd.list_services(ns, kind), key=lambda i: i.Name): + yield (s.Name, s.IsEnabled, sssd.debug_level(s.DebugLevel)) + +class Show(command.LmiShowInstance): + DYNAMIC_PROPERTIES = True + + def execute(self, ns, service): + columns = ( + 'Name', + ('Enabled', 'IsEnabled'), + ('Debug Level', lambda i: sssd.debug_level(i.DebugLevel))) + + return columns, sssd.get_service(ns, service) + +class Enable(command.LmiCheckResult): + CALLABLE = sssd.enable_service + EXPECT = 0 + +class Disable(command.LmiCheckResult): + CALLABLE = sssd.disable_service + EXPECT = 0 + +class ServiceCommands(command.LmiCommandMultiplexer): + COMMANDS = { + 'list' : List, + 'show' : Show, + 'enable' : Enable, + 'disable' : Disable + } + OWN_USAGE = __doc__ diff --git a/commands/sssd/lmi/scripts/sssd/sssd_cmd.py b/commands/sssd/lmi/scripts/sssd/sssd_cmd.py new file mode 100644 index 0000000..b3e6a6a --- /dev/null +++ b/commands/sssd/lmi/scripts/sssd/sssd_cmd.py @@ -0,0 +1,123 @@ +# SSSD Providers +# +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +# +# Authors: Pavel Brezina <pbrezina@redhat.com> +# +""" +SSSD system service management. + +Usage: + %(cmd)s status + %(cmd)s restart [--try] + %(cmd)s set-debug-level <level> [--until-restart] [options] + %(cmd)s domain (--help | <cmd> [<args> ...]) + %(cmd)s service (--help | <cmd> [<args> ...]) + + +Commands: + status Prints SSSD service's status. + restart Restarts the SSSD service. + set-debug-level Set debug level of selected (all by default) components. + service Manage supported services. + domain Manage SSSD domains. + +Restart options: + --try Whether to abandon the operation if the service + is not running. + +Set-debug-level options: + --until-restart + Set the debug level but switch it to original + value when SSSD is restarted. + --all Select all components (default) + --monitor Select the SSSD monitor. + --services=svc,... + Comma separated list of SSSD services. + --domains=dom,... + Comma separated list of SSSD domains. +""" + +from lmi.scripts.common import command +from lmi.scripts import service as srv +from lmi.scripts import sssd +from lmi.scripts.sssd.services_cmd import ServiceCommands +from lmi.scripts.sssd.domains_cmd import DomainCommands + +class Status(command.LmiShowInstance): + + DYNAMIC_PROPERTIES = True + + def execute(self, ns): + columns = ( + ('Name', lambda i: srv.RE_SUFFIX.sub('', i.Name)), + 'Caption', + ('Enabled', lambda i: srv.get_enabled_string(ns, i)), + ('Status', lambda i: srv.get_status_string(ns, i))) + + return columns, srv.get_service(ns, 'sssd') + +class Restart(command.LmiCheckResult): + CALLABLE = srv.restart_service + EXPECT = 0 + + def transform_options(self, options): + """ + ``try`` is a keyword argument in python, let's rename it to + ``just-try`` which will be transformed into ``just_try``. + """ + options['just-try'] = options.pop('--try') + options['service'] = 'sssd' + +class SetDebugLevel(command.LmiCheckResult): + OPT_NO_UNDERSCORES = True + EXPECT = 0 + + def execute(self, ns, level, + until_restart=False, + all=True, + monitor=False, + services=None, + domains=None): + components = [] + if services is not None: + components.extend(services.split(',')) + if domains is not None: + components.extend(domains.split(',')) + if monitor: + components.append('monitor') + return sssd.set_debug_level(ns, level, until_restart, components) + +SSSD = command.register_subcommands( + 'SSSD', __doc__, + { 'status' : Status + , 'restart' : Restart + , 'set-debug-level' : SetDebugLevel + , 'service' : ServiceCommands + , 'domain' : DomainCommands + }, + ) |