Change ipa-compat-manage to work on older python versions too. Break try,except,finally into a try,try,finally,except Add also checks for LDAPError, errors.

This commit is contained in:
Simo Sorce 2008-12-03 09:00:23 -05:00
parent b3b4435d0e
commit 80cc2c3715

View File

@ -94,46 +94,57 @@ def main():
else: else:
dirman_password = get_dirman_password() dirman_password = get_dirman_password()
if args[0] == "enable": try:
try: try:
conn = ipaldap.IPAdmin(installutils.get_fqdn()) conn = ipaldap.IPAdmin(installutils.get_fqdn())
conn.do_simple_bind(bindpw=dirman_password) conn.do_simple_bind(bindpw=dirman_password)
conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config", except ldap.LDAPError, e:
ldap.SCOPE_BASE, "(objectclass=*)") print "An error occurred while connecting to the server."
print "Plugin already Enabled" print "%s" % e[0]['desc']
retval = 2 return 1
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
print "Enabling plugin" if args[0] == "enable":
finally: try:
if conn: conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
conn.unbind() ldap.SCOPE_BASE, "(objectclass=*)")
print "Plugin already Enabled"
retval = 2
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
print "Enabling plugin"
except ldap.LDAPError, e:
print "An error occurred while talking to the server."
print "%s" % e[0]['desc']
retval = 1
if retval == 0:
ld = LDAPUpdate(dm_password=dirman_password, sub_dict={})
retval = ld.update(files)
if retval == 0: if retval == 0:
print "This setting will not take effect until you restart Directory Server." ld = LDAPUpdate(dm_password=dirman_password, sub_dict={})
retval = ld.update(files)
if retval == 0:
print "This setting will not take effect until you restart Directory Server."
elif args[0] == "disable": elif args[0] == "disable":
# Make a quick hack foir now, directly delete the entries by name, # Make a quick hack foir now, directly delete the entries by name,
# In future we should add delete capabilites to LDAPUpdate # In future we should add delete capabilites to LDAPUpdate
try: try:
conn = ipaldap.IPAdmin(installutils.get_fqdn()) conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
conn.do_simple_bind(bindpw=dirman_password) ldap.SCOPE_BASE, "(objectclass=*)")
conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config", conn.deleteEntry("cn=groups,cn=Schema Compatibility,cn=plugins,cn=config")
ldap.SCOPE_BASE, "(objectclass=*)") conn.deleteEntry("cn=users,cn=Schema Compatibility,cn=plugins,cn=config")
conn.deleteEntry("cn=groups,cn=Schema Compatibility,cn=plugins,cn=config") conn.deleteEntry("cn=Schema Compatibility,cn=plugins,cn=config")
conn.deleteEntry("cn=users,cn=Schema Compatibility,cn=plugins,cn=config") except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
conn.deleteEntry("cn=Schema Compatibility,cn=plugins,cn=config") print "Plugin is already disabled"
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): retval = 2
print "Plugin is already disabled" except ldap.LDAPError, e:
retval = 2 print "An error occurred while talking to the server."
finally: print "%s" % e[0]['desc']
if conn: retval = 1
conn.unbind()
else: else:
retval = 1 retval = 1
finally:
if conn:
conn.unbind()
return retval return retval
@ -155,3 +166,6 @@ except config.IPAConfigError, e:
print "An IPA server to update cannot be found. Has one been configured yet?" print "An IPA server to update cannot be found. Has one been configured yet?"
print "The error was: %s" % e print "The error was: %s" % e
sys.exit(1) sys.exit(1)
except ipaerror, e:
print "An error occurred while performing operations: %s" % e
sys.exit(1)