blob: 0e6598d995eaff95267c66a0901847a2fa4b8f46 [file] [log] [blame]
mbligh7c8ea992009-06-22 19:03:08 +00001#!/usr/bin/python
mbligh43da0862008-11-20 17:53:32 +00002
3# change_protection_level.py "No protection" machine1 machine2 machine3
4
5import sys, optparse, traceback, pwd, os
6import common
7from autotest_lib.cli import rpc, host
8
9usage = 'usage: %prog [options] new_protection_level machine1 machine2 ...'
10parser = optparse.OptionParser(usage=usage)
11parser.add_option('-w', '--web',
12 help='Autotest server to use (i.e. "autotest")')
13
14options, leftover_args = parser.parse_args()
15assert len(leftover_args) > 1, 'Must pass protection level and hosts'
16protection_level = leftover_args[0]
17
18user = pwd.getpwuid(os.getuid())[0]
19autotest_host = rpc.get_autotest_server(options.web)
Scott Zawalski347aaf42012-04-03 16:33:00 -040020afe_proxy = rpc.afe_comm(autotest_host, '/afe/server/noauth/rpc/')
mbligh43da0862008-11-20 17:53:32 +000021
22hosts = afe_proxy.run('get_hosts', hostname__in=leftover_args[1:])
23for host in hosts:
mbligh1ef218d2009-08-03 16:57:56 +000024 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']
mbligh43da0862008-11-20 17:53:32 +000031
32print 'Invalid hosts:'
33print ','.join(set(leftover_args[1:]) - set(host['hostname'] for host in hosts))