From 8bf6fb78636cd839ac3f6f09f287de3f48a294bc Mon Sep 17 00:00:00 2001
From: Vincent Fournier <v.fournier11@gmail.com>
Date: Wed, 27 May 2015 16:21:51 -0400
Subject: [PATCH] Load config from file

Change-Id: Ieb11d74efda7e51f16c2bf0aa1c1efb9680536c1
---
 Dockerfile              |  1 +
 etc/surveil/surveil.cfg |  4 ++++
 requirements.txt        |  1 +
 surveil/api/config.py   | 11 ++++++-----
 4 files changed, 12 insertions(+), 5 deletions(-)
 create mode 100644 etc/surveil/surveil.cfg

diff --git a/Dockerfile b/Dockerfile
index d319e1b..883ee21 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -35,6 +35,7 @@ ADD surveil /opt/surveil/surveil
 ENV PBR_VERSION=PROD
 
 # We are using develop so that the code can be mounted when in DEV.
+RUN pip install -U six
 RUN cd /opt/surveil && python setup.py develop
 
 #Set to 'surveil' or 'keystone'
diff --git a/etc/surveil/surveil.cfg b/etc/surveil/surveil.cfg
new file mode 100644
index 0000000..1f9cc5b
--- /dev/null
+++ b/etc/surveil/surveil.cfg
@@ -0,0 +1,4 @@
+[surveil]
+mongodb_uri= mongodb://mongo:27017
+ws_arbiter_url= http://alignak:7760
+influxdb_uri= influxdb://root:root@influxdb:8086/db
diff --git a/requirements.txt b/requirements.txt
index ce9068a..581bc56 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,3 +9,4 @@ oslo.policy>=0.3.0
 keystonemiddleware
 PasteDeploy
 influxdb==2.0.1
+six
diff --git a/surveil/api/config.py b/surveil/api/config.py
index c6d1c6e..6c78461 100644
--- a/surveil/api/config.py
+++ b/surveil/api/config.py
@@ -12,6 +12,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+from six.moves import configparser
 
 from surveil.api import hooks
 
@@ -21,13 +22,13 @@ server = {
     'host': '0.0.0.0'
 }
 
+config = configparser.ConfigParser()
+config.read("/etc/surveil/surveil.cfg")
 
-# In the future, surveil_api_config could be loaded from somewhere else,
-# as long as is it in the same format.
 surveil_api_config = {
-    "mongodb_uri": "mongodb://mongo:27017",
-    "ws_arbiter_url": "http://alignak:7760",
-    "influxdb_uri": "influxdb://root:root@influxdb:8086/db"
+    "mongodb_uri": config.get("surveil", "mongodb_uri"),
+    "ws_arbiter_url": config.get("surveil", "ws_arbiter_url"),
+    "influxdb_uri": config.get("surveil", "influxdb_uri")
 }
 
 app_hooks = [