-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find max OCF UID #178
base: master
Are you sure you want to change the base?
Find max OCF UID #178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
"""Find the highest non-excluded OCF UID.""" | ||
import sys | ||
|
||
from ocflib.account.creation import IGNORED_UID_RANGES | ||
from ocflib.account.creation import RESERVED_UID_RANGES | ||
from ocflib.infra.ldap import ldap_ocf | ||
from ocflib.infra.ldap import OCF_LDAP_PEOPLE | ||
|
||
|
||
INVALID_UID_RANGES = sorted(RESERVED_UID_RANGES + IGNORED_UID_RANGES) | ||
|
||
|
||
def is_valid_uid(uid): | ||
for start, end in IGNORED_UID_RANGES: | ||
if start <= uid <= end: | ||
return False | ||
return True | ||
|
||
|
||
def main(): | ||
print('Searching for maximum currently used OCF UID') | ||
with ldap_ocf() as c: | ||
c.search( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to what @cg505 said this is fine but indeed a little slow tbh; if we are not running this constantly I guess it's fine? |
||
OCF_LDAP_PEOPLE, | ||
'(uid=*)', | ||
attributes=['uidNumber'] | ||
) | ||
uids = [int(entry['attributes']['uidNumber']) for entry in c.response] | ||
uids = filter(is_valid_uid, uids) | ||
print('Max currently used OCF UID is: %s' % max(uids)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer |
||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
INVALID_UID_RANGES
?