Merge "support pep8 check"
[doctor.git] / tests / clean.py
1 ##############################################################################
2 # Copyright (c) 2016 NEC Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import argparse
11 import json
12 import os
13
14 import novaclient.client as novaclient
15
16
17 nova_api_version = '2.11'
18
19 def enable_compute_host(hostname):
20     self.nova = novaclient.Client(self.nova_api_version,
21                                   os.environ['OS_USERNAME'],
22                                   os.environ['OS_PASSWORD'],
23                                   os.environ['OS_TENANT_NAME'],
24                                   os.environ['OS_AUTH_URL'],
25                                   connection_pool=True)
26     opts = {'all_tenants': True, 'host': hostname}
27     for server in self.nova.servers.list(detailed=False, search_opts=opts):
28         self.nova.servers.reset_state(server, 'active')
29     self.nova.services.force_down(hostname, 'nova-compute', False)
30
31
32 def get_args():
33     parser = argparse.ArgumentParser(description='Doctor Test Cleaner')
34     parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
35                         help='a hostname to be re-enable')
36     return parser.parse_args()
37
38
39 def main():
40     args = get_args()
41     enable_compute_host(args.hostname)
42
43
44 if __name__ == '__main__':
45     main()