Mike Frysinger | d03e6b5 | 2019-08-03 12:49:01 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2 |
C Shapiro | f9c62c4 | 2019-07-03 09:17:32 -0600 | [diff] [blame] | 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 | |
| 6 | import sys |
| 7 | |
| 8 | import common |
| 9 | import time |
| 10 | |
| 11 | from autotest_lib.server import frontend |
| 12 | from chromite.lib import commandline |
| 13 | |
| 14 | def GetParser(): |
| 15 | """Creates the argparse parser.""" |
| 16 | parser = commandline.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 | |
| 24 | def 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 | |
| 45 | if __name__ == '__main__': |
| 46 | sys.exit(main(sys.argv[1:])) |