From b5cbe1eaeb3a8dc103d656b881107bcd12d9ebc1 Mon Sep 17 00:00:00 2001 From: Sergey Lukjanov Date: Fri, 1 Mar 2013 16:34:45 +0400 Subject: [PATCH] using conf files instead of hardcoded values --- .gitignore | 1 + eho/server/main.py | 14 ++++++++++---- eho/server/service/cluster_ops.py | 17 +++++++++-------- etc/{eho-api.cfg => default.cfg} | 2 +- etc/local.cfg-sample | 10 ++++++++++ 5 files changed, 31 insertions(+), 13 deletions(-) rename etc/{eho-api.cfg => default.cfg} (77%) create mode 100644 etc/local.cfg-sample diff --git a/.gitignore b/.gitignore index 5ee5ed14ac..e6c69c6817 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ doc/source/apidoc .coverage nosetests.xml pylint-report.txt +etc/local.cfg diff --git a/eho/server/main.py b/eho/server/main.py index 2e29d09857..741aadb02a 100644 --- a/eho/server/main.py +++ b/eho/server/main.py @@ -22,9 +22,15 @@ def make_app(**local_conf): Entry point for Elastic Hadoop on OpenStack REST API server """ app = Flask('eho.api') - # todo(slukjanov): is it needed? - app.config.from_pyfile('etc/eho-api.cfg', silent=True) - app.config.from_pyfile('../etc/eho-api.cfg', silent=True) + + # reading defaults + app.config.from_pyfile('etc/default.cfg', silent=True) + app.config.from_pyfile('../etc/default.cfg', silent=True) + + # read local conf + app.config.from_pyfile('etc/local.cfg', silent=True) + app.config.from_pyfile('../etc/local.cfg', silent=True) + app.config.from_envvar('EHO_API_CFG', silent=True) app.config.update(**local_conf) @@ -43,7 +49,7 @@ def make_app(**local_conf): setup_storage(app) setup_defaults(app) setup_scheduler(app) - setup_ops() + setup_ops(app) setup_api(app) def make_json_error(ex): diff --git a/eho/server/service/cluster_ops.py b/eho/server/service/cluster_ops.py index 346514b088..f9d1740dca 100644 --- a/eho/server/service/cluster_ops.py +++ b/eho/server/service/cluster_ops.py @@ -16,15 +16,16 @@ OPENSTACK_CONF = {} OPENSTACK_NODE_CONF = {} -def setup_ops(): - OPENSTACK_CONF['user'] = 'admin' - OPENSTACK_CONF['password'] = 'nova' - OPENSTACK_CONF['tenant'] = 'admin' - OPENSTACK_CONF['auth_url'] = 'http://172.18.79.139:5000/v2.0/' - OPENSTACK_CONF['vm_internal_net'] = "novanetwork" +def setup_ops(app): + OPENSTACK_CONF['user'] = app.config.get('OPENSTACK_USER') + OPENSTACK_CONF['password'] = app.config.get('OPENSTACK_PASSWORD') + OPENSTACK_CONF['tenant'] = app.config.get('OPENSTACK_TENANT') + OPENSTACK_CONF['auth_url'] = app.config.get('OPENSTACK_AUTH_URL') + OPENSTACK_CONF['vm_internal_net'] = \ + app.config.get('OPENSTACK_VM_INTERNAL_NET') - OPENSTACK_NODE_CONF['user'] = 'root' - OPENSTACK_NODE_CONF['password'] = 'swordfish' + OPENSTACK_NODE_CONF['user'] = app.config.get('NODE_USER') + OPENSTACK_NODE_CONF['password'] = app.config.get('NODE_PASSWORD') def _create_nova_client(): diff --git a/etc/eho-api.cfg b/etc/default.cfg similarity index 77% rename from etc/eho-api.cfg rename to etc/default.cfg index 192c7e68af..fbaa288321 100644 --- a/etc/eho-api.cfg +++ b/etc/default.cfg @@ -1,3 +1,3 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/eho-server.db' -SQLALCHEMY_ECHO = False +SQLALCHEMY_ECHO=False ALLOW_CLUSTER_OPS=False diff --git a/etc/local.cfg-sample b/etc/local.cfg-sample new file mode 100644 index 0000000000..5090e746c7 --- /dev/null +++ b/etc/local.cfg-sample @@ -0,0 +1,10 @@ +# OPENSTACK CONF +OPENSTACK_USER=admin +OPENSTACK_PASSWORD=nova +OPENSTACK_TENANT=admin +OPENSTACK_AUTH_URL=http://172.18.79.139:5000/v2.0/ +OPENSTACK_VM_INTERNAL_NET=novanetwork + +# NODE CONF +NODE_USER=root +NODE_PASSWORD=swordfish