1 from consul.base import Timeout
2 from consul.tornado import Consul
4 from osdf.logging.osdf_logging import debug_log
5 from tornado.gen import coroutine
6 from tornado.ioloop import IOLoop
10 def __init__(self, loop, osdf_final_config):
11 self.config = osdf_final_config
12 osdf_config = self.config['osdf_config']
13 self.consul = Consul(host=osdf_config['consulHost'], port=osdf_config['consulPort'],
14 scheme=osdf_config['consulScheme'], verify=osdf_config['consulVerify'],
15 cert=osdf_config['consulCert'])
16 result = json.dumps(self.config)
17 self.consul.kv.put("osdfconfiguration", result)
18 loop.add_callback(self.watch)
25 index, data = yield self.consul.kv.get('osdfconfiguration', index=index)
27 self.update_config(data)
30 except Exception as e:
31 debug_log.debug('Exception Encountered {}'.format(e))
33 def update_config(self, data):
34 new_config = json.loads(data['Value'].decode('utf-8'))
35 osdf_deployment = new_config['osdf_config']
36 osdf_core = new_config['common_config']
37 self.config['osdf_config'].update(osdf_deployment)
38 self.config['common_config'].update(osdf_core)
39 debug_log.debug("updated config {}".format(new_config))
40 debug_log.debug("value changed")
43 def call_consul_kv(osdf_config):
45 'osdf_config': osdf_config.deployment,
46 'common_config': osdf_config.core
49 io_loop.make_current()
50 IOLoop.current(instance=False)
51 _ = Config(io_loop, osdf_final_config)