[CORD-1358] Replacing config module in settings.py

Change-Id: I834e189ac7132f2164277785885ee01078a7aa84
diff --git a/lib/xos-config/tests/config_test.py b/lib/xos-config/tests/config_test.py
index c89ed47..a3e57db 100644
--- a/lib/xos-config/tests/config_test.py
+++ b/lib/xos-config/tests/config_test.py
@@ -126,6 +126,7 @@
         # not only from the one that has been used to initialize it
         res = Config2.get("database")
         self.assertEqual(res, {
+            "name": "xos",
             "username": "test",
             "password": "safe"
         })
diff --git a/lib/xos-config/tests/confs/basic_conf.yaml b/lib/xos-config/tests/confs/basic_conf.yaml
index 0f1d0b0..4337b6c 100644
--- a/lib/xos-config/tests/confs/basic_conf.yaml
+++ b/lib/xos-config/tests/confs/basic_conf.yaml
@@ -1,4 +1,5 @@
 name: test
 database:
+  name: xos
   username: test
   password: safe
\ No newline at end of file
diff --git a/lib/xos-config/tests/confs/sample_conf.yaml b/lib/xos-config/tests/confs/sample_conf.yaml
index b398b40..4d4c792 100644
--- a/lib/xos-config/tests/confs/sample_conf.yaml
+++ b/lib/xos-config/tests/confs/sample_conf.yaml
@@ -1,5 +1,6 @@
 name: xos-core
 database:
+  name: xos
   username: test
   password: safe
 logging:
diff --git a/lib/xos-config/xosconfig/config-schema.yaml b/lib/xos-config/xosconfig/config-schema.yaml
index 9a6f000..5d30b86 100644
--- a/lib/xos-config/xosconfig/config-schema.yaml
+++ b/lib/xos-config/xosconfig/config-schema.yaml
@@ -2,13 +2,20 @@
   name:
     type: str
     required: True
+  xos_dir:
+    type: str
   database:
     type: map
     map:
+      name:
+        type: str
+        required: True
       username:
         type: str
+        required: True
       password:
         type: str
+        required: True
   logging:
     type: map
     map:
diff --git a/lib/xos-config/xosconfig/config.py b/lib/xos-config/xosconfig/config.py
index e58477c..608beac 100644
--- a/lib/xos-config/xosconfig/config.py
+++ b/lib/xos-config/xosconfig/config.py
@@ -5,7 +5,7 @@
 import default
 from pykwalify.core import Core as PyKwalify
 
-DEFAULT_CONFIG_FILE = "/opt/xos/config.yaml"
+DEFAULT_CONFIG_FILE = "/opt/xos/xos_config.yaml"
 INITIALIZED = False
 CONFIG = {}
 
diff --git a/lib/xos-config/xosconfig/default.py b/lib/xos-config/xosconfig/default.py
index 221e0e8..eaea40a 100644
--- a/lib/xos-config/xosconfig/default.py
+++ b/lib/xos-config/xosconfig/default.py
@@ -1,4 +1,5 @@
 DEFAULT_VALUES = {
+    'xos_dir': '/opt/xos',
     'logging': {
         'level': 'info',
         'channels': ['file', 'console']
diff --git a/xos/coreapi/core_main.py b/xos/coreapi/core_main.py
index 6e25fcd..ada3222 100644
--- a/xos/coreapi/core_main.py
+++ b/xos/coreapi/core_main.py
@@ -12,6 +12,7 @@
 from xos.logger import Logger, logging
 logger = Logger(level=logging.DEBUG)
 
+
 if __name__ == '__main__':
     django.setup()
 
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index 2bba8a1..af91475 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -5,12 +5,12 @@
 import warnings
 from urlparse import urlparse
 
-# Django settings for XOS.
-from config import Config
-config = Config()
+# Initializing xosconfig module
+from xosconfig import Config
+Config.init()
 
 GEOIP_PATH = "/usr/share/GeoIP"
-XOS_DIR = "/opt/xos"
+XOS_DIR = Config.get('xos_dir')
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
@@ -27,15 +27,17 @@
 
 MANAGERS = ADMINS
 
+db_service = Config.get_service_info('xos-db')
+
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': config.db_name,                      # Or path to database file if using sqlite3.
+        'NAME': Config.get('database.name'),                      # Or path to database file if using sqlite3.
         # The following settings are not used with sqlite3:
-        'USER': config.db_user,
-        'PASSWORD': config.db_password,
-        'HOST': config.db_host,                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
-        'PORT': config.db_port,                      # Set to empty string for default.
+        'USER': Config.get('database.username'),
+        'PASSWORD': Config.get('database.password'),
+        'HOST': db_service['url'],                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
+        'PORT': db_service['port'],                      # Set to empty string for default.
     }
 }
 
@@ -229,22 +231,17 @@
     }
 }
 
-RESTAPI_HOSTNAME = getattr(config, "server_restapi_hostname", getattr(config, "server_hostname", socket.gethostname()))
-RESTAPI_PORT = int(getattr(config, "server_restapi_port", getattr(config, "server_port", "8000")))
+XOS_BRANDING_NAME = "OpenCloud"
+XOS_BRANDING_CSS = None
+XOS_BRANDING_ICON = "/static/logo.png"
+XOS_BRANDING_FAVICON = "/static/favicon.png"
+XOS_BRANDING_BG = "/static/bg.png"
 
-BIGQUERY_TABLE = getattr(config, "bigquery_table", "demoevents")
-
-XOS_BRANDING_NAME = getattr(config, "gui_branding_name", "OpenCloud")
-XOS_BRANDING_CSS = getattr(config, "gui_branding_css", None)
-XOS_BRANDING_ICON = getattr(config, "gui_branding_icon", "/static/logo.png")
-XOS_BRANDING_FAVICON = getattr(config, "gui_branding_favicon", "/static/favicon.png")
-XOS_BRANDING_BG = getattr(config, "gui_branding_bg", "/static/bg.png")
-
-DISABLE_MINIDASHBOARD = getattr(config, "gui_disable_minidashboard", False)
+DISABLE_MINIDASHBOARD = False
 ENCRYPTED_FIELDS_KEYDIR = XOS_DIR + '/private_keys'
 ENCRYPTED_FIELD_MODE = 'ENCRYPT'
 
-STATISTICS_DRIVER = getattr(config, "statistics_driver", "ceilometer")
+STATISTICS_DRIVER = "statistics_driver"
 
 # prevents warnings on django 1.7
 TEST_RUNNER = 'django.test.runner.DiscoverRunner'