From 11fcd6be74b5782b5bc206becc3cce6d0b7c17ff Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 17 Aug 2016 17:24:17 +0200 Subject: Server/Plugins/Ldap: Module should be importable without the python-ldap --- src/lib/Bcfg2/Server/Plugins/Ldap.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Plugins/Ldap.py b/src/lib/Bcfg2/Server/Plugins/Ldap.py index 895c6380f..757150300 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ldap.py +++ b/src/lib/Bcfg2/Server/Plugins/Ldap.py @@ -119,22 +119,27 @@ class Ldap(Bcfg2.Server.Plugin.Plugin, class LdapConnection(Debuggable): """ Connection to an LDAP server. """ - __scopes__ = { - 'base': ldap.SCOPE_BASE, - 'one': ldap.SCOPE_ONELEVEL, - 'sub': ldap.SCOPE_SUBTREE, - } - def __init__(self, host="localhost", port=389, binddn=None, bindpw=None): Debuggable.__init__(self) + if HAS_LDAP: + msg = "Python ldap module is required for Ldap plugin" + self.logger.error(msg) + raise Bcfg2.Server.Plugin.PluginInitError(msg) + self.host = host self.port = port self.binddn = binddn self.bindpw = bindpw self.conn = None + self.__scopes__ = { + 'base': ldap.SCOPE_BASE, + 'one': ldap.SCOPE_ONELEVEL, + 'sub': ldap.SCOPE_SUBTREE, + } + def __del__(self): """ Disconnection if the instance is destroyed. """ self.disconnect() -- cgit v1.2.3-1-g7c22