Skip to content

Instantly share code, notes, and snippets.

@sochotnicky
Created November 7, 2017 09:25
Show Gist options
  • Save sochotnicky/4b73300339c2a890a31a1b1380032579 to your computer and use it in GitHub Desktop.
Save sochotnicky/4b73300339c2a890a31a1b1380032579 to your computer and use it in GitHub Desktop.
/home/w0rm/bin/brno_devops.py
import sys
import ldap
l = ldap.initialize('ldap://ldap.corp.redhat.com')
groups = l.search_s('dc=redhat,dc=com', ldap.SCOPE_SUBTREE,
'cn=%s' % sys.argv[1])
no_keys = []
all_users = []
for group in groups:
query = '(|(uid=%s))' % ')(uid='.join(group[1]['memberUid'])
users = l.search_s('dc=redhat,dc=com', ldap.SCOPE_SUBTREE,
query)
all_users.extend([uid['uid'][0] for _,uid in users])
for cn, user in users:
if 'Brno' in user['rhatLocation'][0]:
print user['uid'][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment