Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions staff/acct/max-uid
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:
Copy link
Contributor

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?

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(
Copy link
Contributor

Choose a reason for hiding this comment

The 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer .format but this works as well



if __name__ == '__main__':
sys.exit(main())