from flask import request
import json
import logger as doctor_log
-import os
import threading
import time
+from keystoneauth1 import session
import novaclient.client as novaclient
-import nova_force_down
+import identity_auth
LOG = doctor_log.Logger('doctor_inspector').getLogger()
class DoctorInspectorSample(object):
- NOVA_API_VERSION = '2.11'
+ NOVA_API_VERSION = '2.34'
NUMBER_OF_CLIENTS = 50
# TODO(tojuvone): This could be enhanced in future with dynamic
# reuse of self.novaclients when all threads in use and
def __init__(self):
self.servers = collections.defaultdict(list)
self.novaclients = list()
+ auth=identity_auth.get_identity_auth()
+ sess=session.Session(auth=auth)
# Pool of novaclients for redundant usage
for i in range(self.NUMBER_OF_CLIENTS):
- self.novaclients.append(novaclient.Client(self.NOVA_API_VERSION,
- os.environ['OS_USERNAME'],
- os.environ['OS_PASSWORD'],
- os.environ['OS_TENANT_NAME'],
- os.environ['OS_AUTH_URL'],
- connection_pool=True))
+ self.novaclients.append(
+ novaclient.Client(self.NOVA_API_VERSION, session=sess))
# Normally we use this client for non redundant API calls
self.nova=self.novaclients[0]
self.nova.servers.list(detailed=False)
threads.append(t)
for t in threads:
t.join()
- # NOTE: We use our own client here instead of this novaclient for a
- # workaround. Once keystone provides v2.1 nova api endpoint
- # in the service catalog which is configured by OpenStack
- # installer, we can use this:
- #
- # self.nova.services.force_down(hostname, 'nova-compute', True)
- #
- nova_force_down.force_down(hostname)
+ self.nova.services.force_down(hostname, 'nova-compute', True)
LOG.info('doctor mark host(%s) down at %s' % (hostname, time.time()))
def main():
args = get_args()
- app.run(port=args.port)
-
+ app.run(host='0.0.0.0', port=args.port)
if __name__ == '__main__':
main()