+ def _add_base_dn(self, model):
+ using = router.db_for_write(model)
+ connection = connections[using]
+
+ rdn = model.base_dn.split(',')[0]
+ key, val = rdn.split('=')
+ attrs = [('objectClass', ['top', 'organizationalUnit']), (key, [val])]
+ try:
+ connection.add_s(model.base_dn, attrs)
+ except ldap.ALREADY_EXISTS:
+ pass
+
+ def _remove_base_dn(self, model):
+ using = router.db_for_write(model)
+ connection = connections[using]
+
+ try:
+ results = connection.search_s(model.base_dn, ldap.SCOPE_SUBTREE)
+ for dn, attrs in reversed(results):
+ connection.delete_s(dn)
+ except ldap.NO_SUCH_OBJECT:
+ pass
+