• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2# 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
6import argparse
7import sys
8
9import common
10import time
11
12from autotest_lib.server import frontend
13
14def GetParser():
15    """Creates the argparse parser."""
16    parser = argparse.ArgumentParser(description=__doc__)
17    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:]))
47