blob: c7a21caf3ab48d983a2826ac4d2ea2136cd5d996 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
C Shapirof9c62c42019-07-03 09:17:32 -06002# Takes a list of hostnames (via file) and schedules host repair
3# jobs based on the delay specified in order to throttle the jobs
4# and not overwhelm the system.
5
Mike Frysingere5fe6722020-02-06 15:18:45 -05006import argparse
C Shapirof9c62c42019-07-03 09:17:32 -06007import sys
8
9import common
10import time
11
12from autotest_lib.server import frontend
C Shapirof9c62c42019-07-03 09:17:32 -060013
14def GetParser():
15 """Creates the argparse parser."""
Mike Frysingere5fe6722020-02-06 15:18:45 -050016 parser = argparse.ArgumentParser(description=__doc__)
C Shapirof9c62c42019-07-03 09:17:32 -060017 parser.add_argument('--input', type=str, action='store',
18 help='File with hostnames to repair')
19 parser.add_argument('--delay_seconds', type=int, action='store', default=5,
20 help='Delay between scheduling repair jobs')
21 return parser
22
23
24def main(argv):
25 parser = GetParser()
26 options = parser.parse_args(argv)
27
28 afe = frontend.AFE()
29
30 with open(options.input) as input:
31 hostnames = input.readlines()
32 remaining = len(hostnames)
33 delay = options.delay_seconds
34 print "Scheduling %d repairs with %s delay in seconds" \
35 % (remaining, delay)
36 for hostname in hostnames:
37 hostname = hostname.strip()
38 afe.repair_hosts([hostname])
39 remaining = remaining - 1
40 print "%s host repair scheduled with %d remaining" \
41 % (hostname, remaining)
42 time.sleep(delay)
43
44
45if __name__ == '__main__':
46 sys.exit(main(sys.argv[1:]))