-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_reset.py
executable file
·70 lines (60 loc) · 2.52 KB
/
account_reset.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
63
64
65
66
67
68
69
70
#!/usr/bin/env python
""" Load the disableable implementations then enqueue disabling activities."""
from celeryconfig import get_implementations
import disableables
import rt
from imp import find_module, load_module
from time import sleep
import logging
import yaml
IMPLEMENTATIONS = get_implementations('disableables', False)
def main():
"""Load a config, load modules, get tasks from RT dispatch disable tasks
for each of them."""
with open('./config.yaml', 'r') as config_file:
config = yaml.load(config_file)
logging.basicConfig(
format='[account-disable %(levelname)s] %(asctime)s: %(message)s',
level=config['log_level'],
)
credentials = dict()
credentials['user'] = config['rt_username']
credentials['pass'] = config['rt_password']
for module in IMPLEMENTATIONS:
parent = "disableables.{0}".format(module)
fhn, filename, description = find_module(module, disableables.__path__)
vars()[module] = load_module(parent, fhn, filename, description)
# get reset requests from rt
query, uri = (config['rt_query'], config['rt_uri'])
for reset in rt.get(query, credentials, uri):
ticket, uid = reset
logging.info('Working on ticket=%s for uid=%s', ticket, uid)
tasks = dict()
for module in IMPLEMENTATIONS:
instance = vars()[module]
instance_config = dict()
for key in instance.CONFIG:
instance_config[key] = config[key]
task = instance.disable.delay(ticket, uid, config)
tasks[ticket] = (uid, task)
print "RT#{0}: {1} is {2}".format(ticket, uid, task.status)
while True:
if len(tasks) < 1: break
done = list()
for ticket in tasks.iterkeys():
uid, task = tasks[ticket]
if task.successful():
comment = "RT#{0}: Success!\n{1}".format(ticket, task.get())
#rt.comment(ticket, comment, credentials, uri)
#rt.move(ticket, 'cis-windows', credentials, uri)
done.append(ticket)
print comment
if task.failed():
comment = "RT#{0}: Failed!\n{1}".format(ticket, task.get())
# but we don't do retry yet... so...
done.append(ticket)
# can't delete dict items during iteration, causes runtime error
for ticket in done:
del tasks[ticket]
if __name__ == '__main__':
main()