-
Notifications
You must be signed in to change notification settings - Fork 63
/
keystone_update_ad_schema.py
62 lines (47 loc) · 1.91 KB
/
keystone_update_ad_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2015 Cloudbase Solutions Srl
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ldap
from ldap import modlist
ldap_server = "ldap://localhost"
ldap_domain = "DC=osdemo,DC=local"
ldap_user = "OSDEMO\\Administrator"
ldap_password = "Passw0rd"
ldap_base_ou_dn = "OU=OpenStack,%s" % ldap_domain
ldap_users_ou_dn = "OU=Users,OU=OpenStack,%s" % ldap_domain
ldap_tenants_ou_dn = "OU=Tenants,OU=OpenStack,%s" % ldap_domain
ldap_roles_ou_dn = "OU=Roles,OU=OpenStack,%s" % ldap_domain
def update_schema(l, ldap_domain):
dn = "CN=Organizational-Role,CN=Schema,CN=Configuration,%s" % ldap_domain
org_role = l.search_s(dn, ldap.SCOPE_BASE)[0]
if "groupOfNames" not in org_role[1].get("possSuperiors", []):
l.modify_s(dn, [(ldap.MOD_ADD, 'possSuperiors', 'groupOfNames')])
def create_organizational_unit(l, ou_dn):
try:
ou = l.search_s(ou_dn, ldap.SCOPE_BASE)
# ou exists
return
except ldap.NO_SUCH_OBJECT:
pass
attrs = {}
attrs['objectclass'] = ['top', 'organizationalUnit']
ldif = modlist.addModlist(attrs)
l.add_s(ou_dn, ldif)
l = ldap.initialize(ldap_server)
l.simple_bind_s(ldap_user, ldap_password)
update_schema(l, ldap_domain)
create_organizational_unit(l, ldap_base_ou_dn)
create_organizational_unit(l, ldap_users_ou_dn)
create_organizational_unit(l, ldap_tenants_ou_dn)
create_organizational_unit(l, ldap_roles_ou_dn)
l.unbind_s()