aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfig/osdf_config.yaml8
-rw-r--r--osdf/config/base.py10
-rw-r--r--osdf/config/consulconfig.py52
-rw-r--r--requirements.txt2
-rwxr-xr-xtest/config/osdf_config.yaml8
-rwxr-xr-xtest/functest/simulators/simulated-config/osdf_config.yaml8
6 files changed, 86 insertions, 2 deletions
diff --git a/config/osdf_config.yaml b/config/osdf_config.yaml
index 1800ce5..3459939 100755
--- a/config/osdf_config.yaml
+++ b/config/osdf_config.yaml
@@ -72,3 +72,11 @@ pciHMSPassword: passwd
#key
#appkey: os35@rrtky400fdntc#001t5
+
+#consulconfig
+consulHost: '127.0.0.1'
+consulPort: 8500
+consulScheme: 'http'
+consulVerify: True
+consulCert: None
+activateConsulConfig: False
diff --git a/osdf/config/base.py b/osdf/config/base.py
index 2393642..be693cb 100644
--- a/osdf/config/base.py
+++ b/osdf/config/base.py
@@ -18,10 +18,11 @@
#
import os
-
+from osdf.config.consulconfig import call_consul_kv
import osdf.config.credentials as creds
import osdf.config.loader as config_loader
from osdf.utils.programming_utils import DotDict
+from threading import Thread
config_spec = {
"deployment": os.environ.get("OSDF_CONFIG_FILE", "config/osdf_config.yaml"),
@@ -39,3 +40,10 @@ http_basic_auth_credentials = creds.load_credentials(osdf_config)
dmaap_creds = creds.dmaap_creds()
creds_prefixes = {"so": "so", "cm": "cmPortal", "pcih": "pciHMS"}
+
+osdf_config_deployment = osdf_config.deployment
+
+
+if osdf_config.deployment.get('activateConsulConfig'):
+ consulthread = Thread(target=call_consul_kv, args=(osdf_config,))
+ consulthread.start()
diff --git a/osdf/config/consulconfig.py b/osdf/config/consulconfig.py
new file mode 100644
index 0000000..fc5b3fe
--- /dev/null
+++ b/osdf/config/consulconfig.py
@@ -0,0 +1,52 @@
+from consul.base import Timeout
+from consul.tornado import Consul
+import json
+from osdf.logging.osdf_logging import debug_log
+from tornado.gen import coroutine
+from tornado.ioloop import IOLoop
+
+
+class Config(object):
+ def __init__(self, loop, osdf_final_config):
+ self.config = osdf_final_config
+ osdf_config = self.config['osdf_config']
+ self.consul = Consul(host=osdf_config['consulHost'], port=osdf_config['consulPort'],
+ scheme=osdf_config['consulScheme'], verify=osdf_config['consulVerify'],
+ cert=osdf_config['consulCert'])
+ result = json.dumps(self.config)
+ self.consul.kv.put("osdfconfiguration", result)
+ loop.add_callback(self.watch)
+
+ @coroutine
+ def watch(self):
+ index = None
+ while True:
+ try:
+ index, data = yield self.consul.kv.get('osdfconfiguration', index=index)
+ if data is not None:
+ self.update_config(data)
+ except Timeout:
+ pass
+ except Exception as e:
+ debug_log.debug('Exception Encountered {}'.format(e))
+
+ def update_config(self, data):
+ new_config = json.loads(data['Value'].decode('utf-8'))
+ osdf_deployment = new_config['osdf_config']
+ osdf_core = new_config['common_config']
+ self.config['osdf_config'].update(osdf_deployment)
+ self.config['common_config'].update(osdf_core)
+ debug_log.debug("updated config {}".format(new_config))
+ debug_log.debug("value changed")
+
+
+def call_consul_kv(osdf_config):
+ osdf_final_config = {
+ 'osdf_config': osdf_config.deployment,
+ 'common_config': osdf_config.core
+ }
+ io_loop = IOLoop()
+ io_loop.make_current()
+ IOLoop.current(instance=False)
+ _ = Config(io_loop, osdf_final_config)
+ io_loop.start()
diff --git a/requirements.txt b/requirements.txt
index c3749e8..033c65c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -15,3 +15,5 @@ pymzn>=0.18.3
onappylog>=1.0.9
pathtools>=0.1.2
pycryptodome>=3.9.6
+python-consul>=1.1.0
+tornado>=6.1
diff --git a/test/config/osdf_config.yaml b/test/config/osdf_config.yaml
index ef73d4c..793de63 100755
--- a/test/config/osdf_config.yaml
+++ b/test/config/osdf_config.yaml
@@ -79,3 +79,11 @@ desHeaders:
Content-Type: application/json
desUsername:
desPassword:
+
+#consulconfig
+consulHost: '127.0.0.1'
+consulPort: 8500
+consulScheme: 'http'
+consulVerify: True
+consulCert: None
+activateConsulConfig: False \ No newline at end of file
diff --git a/test/functest/simulators/simulated-config/osdf_config.yaml b/test/functest/simulators/simulated-config/osdf_config.yaml
index d4d20c9..2f03d99 100755
--- a/test/functest/simulators/simulated-config/osdf_config.yaml
+++ b/test/functest/simulators/simulated-config/osdf_config.yaml
@@ -77,4 +77,10 @@ aaiGetControllersUrl: /aai/v19/external-system/esr-thirdparty-sdnc-list
controllerQueryUrl: /aai/v19/query?format=resource
aaiGetInterDomainLinksUrl: /aai/v19/network/logical-links?link-type=inter-domain&operational-status=up
-
+#consulconfig
+consulHost: '127.0.0.1'
+consulPort: 8500
+consulScheme: 'http'
+consulVerify: True
+consulCert: None
+activateConsulConfig: False