Using python-ldap, I want to delete an entire subtree of my LDAP tree.
I came up with :
def ldap_recursive_delete_s(con, base_dn):
search = con.search_s(base_dn, ldap.SCOPE_SUBTREE)
delete_list = [dn for dn, _ in search]
delete_list.reverse()
for dn in delete_list:
con.delete_s(dn)
I was wondering if there is any kind of "recursive" option like with the ldaprm CLI tool.
For those who might stumble on this question later, here's a quick and dirty piece I wrote for myself (Essentially what @navendu says):
def recursive_delete(conn, base_dn):
search = conn.search_s(base_dn, ldap.SCOPE_ONELEVEL)
for dn, _ in search:
recursive_delete(conn, dn)
print "Deleting: ", base_dn
conn.delete_s(base_dn)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With