1 #!/usr/bin/python 2 3 # change_protection_level.py "No protection" machine1 machine2 machine3 4 5 import sys, optparse, traceback, pwd, os 6 import common 7 from autotest_lib.cli import rpc, host 8 9 usage = 'usage: %prog [options] new_protection_level machine1 machine2 ...' 10 parser = optparse.OptionParser(usage=usage) 11 parser.add_option('-w', '--web', 12 help='Autotest server to use (i.e. "autotest")') 13 14 options, leftover_args = parser.parse_args() 15 assert len(leftover_args) > 1, 'Must pass protection level and hosts' 16 protection_level = leftover_args[0] 17 18 user = pwd.getpwuid(os.getuid())[0] 19 autotest_host = rpc.get_autotest_server(options.web) 20 afe_proxy = rpc.afe_comm(autotest_host, '/afe/server/noauth/rpc/') 21 22 hosts = afe_proxy.run('get_hosts', hostname__in=leftover_args[1:]) 23 for host in hosts: 24 try: 25 afe_proxy.run('modify_host', host['id'], protection=protection_level) 26 except Exception, exc: 27 print 'For host %s:', host['hostname'] 28 traceback.print_exc() 29 else: 30 print 'Host %s succeeded' % host['hostname'] 31 32 print 'Invalid hosts:' 33 print ','.join(set(leftover_args[1:]) - set(host['hostname'] for host in hosts)) 34