virt.virt_utils: Get rid of create_report function
[autotest-zwu.git] / cli / change_protection_level.py
blob9ab7a6123351248dd3b800af955928f92c02dad8
1 #!/usr/bin/python
3 # change_protection_level.py "No protection" machine1 machine2 machine3
5 import sys, optparse, traceback, pwd, os
6 import common
7 from autotest_lib.cli import rpc, host
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")')
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]
18 user = pwd.getpwuid(os.getuid())[0]
19 autotest_host = rpc.get_autotest_server(options.web)
20 afe_proxy = rpc.afe_comm(autotest_host)
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']
32 print 'Invalid hosts:'
33 print ','.join(set(leftover_args[1:]) - set(host['hostname'] for host in hosts))