-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoattach.py
executable file
·35 lines (25 loc) · 1.09 KB
/
autoattach.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
#!/usr/bin/env python3
"""
Print all currently unbound user and device entries from the OMM.
If there is exactly one unbound user and one unbound device, attach them to
each other.
"""
import sys
import configparser
from OMMClient.OMMClient import OMMClient
config = configparser.ConfigParser()
config.read('pmu.ini')
omm_ip = config['DEFAULT'].get('omm_ip')
omm_port = config['DEFAULT'].getint('omm_port', 12622)
omm_username = config['DEFAULT'].get('omm_username', 'omm')
omm_password = config['DEFAULT'].get('omm_password')
client = OMMClient(omm_ip, omm_port)
client.login(omm_username, omm_password, ommsync=True)
ub_users = list(client.find_users({'ppn': '0'}))
print('Unbound users:', [u.num + ' (' + u.uid + ')' for u in ub_users])
ub_devs = list(client.find_devices({'relType': 'Unbound'}))
print('Unbound devices:', [d.ipei + ' (' + d.ppn + ')' for d in ub_devs])
if len(ub_users) == 1 and len(ub_devs) == 1:
print('success' if client.attach_user_device(int(ub_users[0].uid), int(ub_devs[0].ppn)) else 'failure')
else:
print('No unique user-device pair, please run attach.py manually.')