1 ##############################################################################
2 # Copyright (c) 2016 NEC Corporation and others.
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 ##############################################################################
14 from keystoneclient.v2_0 import client
18 def force_down(hostname, force_down=True):
19 keystone = client.Client(username=os.environ['OS_USERNAME'],
20 password=os.environ['OS_PASSWORD'],
21 tenant_name=os.environ['OS_TENANT_NAME'],
22 auth_url=os.environ['OS_AUTH_URL'])
24 for service in keystone.auth_ref['serviceCatalog']:
25 if service['type'] == 'compute':
26 base_url = service['endpoints'][0]['internalURL']
29 url = '%s/os-services/force-down' % base_url.replace('/v2/', '/v2.1/')
31 'forced_down': force_down,
32 'binary': 'nova-compute',
36 'Content-Type': 'application/json',
37 'Accept': 'application/json',
38 'X-Auth-Token': keystone.auth_ref['token']['id'],
39 'X-OpenStack-Nova-API-Version': '2.11',
42 print requests.put(url, data=json.dumps(data), headers=headers)
46 parser = argparse.ArgumentParser(description='Doctor Test Cleaner')
47 parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
48 help='a nova-compute hostname to force down')
49 parser.add_argument('--unset', action='store_true', default=False,
50 help='unset force_down flag')
51 return parser.parse_args()
56 force_down(args.hostname, not(args.unset))
59 if __name__ == '__main__':