Skip to content

Commit

Permalink
Improve ceagle configurability (#10)
Browse files Browse the repository at this point in the history
* Automatically try to fetch config in json format from "/etc/ceagle/config.json"
* Allow to pass path to config file via CEAGLE_CONF env variable
* Add readme file that describes all config options
* Allow to specify name of portal
  • Loading branch information
boris-42 committed Oct 5, 2016
1 parent c38c3a1 commit c116ce3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
26 changes: 25 additions & 1 deletion ceagle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import json
import os

import flask

Expand All @@ -24,7 +26,6 @@
app.config.from_object(__name__)
app.config.update({"SECRET_KEY": "change_this_key_in_prod"})
app.config.from_envvar("CEAGLE_SETTINGS", silent=True)
app.config.from_pyfile('/etc/ceagle/config.cfg', silent=True)


@app.route("/", methods=["GET"])
Expand All @@ -49,7 +50,30 @@ def not_found(error):
app.register_blueprint(blueprint, url_prefix=url_prefix)


@app.context_processor
def inject_config():
return dict(cloud_status_conf=app.config["cloud_status"],
global_conf=app.config["global"])


def load_config(path="/etc/ceagle/config.json"):
try:
with open(path) as f:
config = json.load(f)
except IOError as e:
print("Config at '%s': %s" % (path, e))
config = {}

app.config.update(config.get("flask", {}))
app.config["cloud_status"] = config.get("cloud_status",
{"enabled": False})
app.config["global"] = config.get("global", {"portal_name": "Cloud Eagle"})


def main():

load_config(path=os.environ.get("CEAGLE_CONF", "/etc/ceagle/config.json"))

app.run(host=app.config.get("HOST", "0.0.0.0"),
port=app.config.get("PORT", 5000))

Expand Down
4 changes: 2 additions & 2 deletions ceagle/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="{{ url_for('static', filename='pics/favicon.ico') }}" type="image/x-icon" />
<title> Cloud Eagle - {{ title }} </title>
<title> {{ global_conf["portal_name"] }} - {{ title }} </title>

<link href="{{ url_for('static', filename='css/bootstrap.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/main.css') }}" rel="stylesheet">
Expand All @@ -29,7 +29,7 @@
<div class="navbar-header">
<a href="#">
<img src="{{ url_for('static', filename='pics/logo.png') }}" height="40px" />
<span>Cloud Eagle</span>
<span>{{ global_conf["portal_name"] }}</span>
</a>
</div>
</nav>
Expand Down
30 changes: 30 additions & 0 deletions etc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Ceagle Portal Configuration
===========================

Placement
---------

config.json should be placed to /etc/ceagle/config.json


Configuration File Description
------------------------------

Configuration file is plain json document with 3 top level keys:

* flask - Flask configuration arguments with Host and Port options added.
* global - All global settings (e.g. cloud portal name)
* cloud_status - cloud_status pages configuration


Configuration Of cloud_status In Nuts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* enabled - If True initialize /cloud_status/ API and "Cloud status" menu
* enabled_dashboards - initializes sub API /cloud_status/availability and /cloud_status/health with sub menus
* regions - list of regions that should be displayed
** region - displayed name of region
** health - dict with 2 items connection URL to Elastic Search & index from what to query health data production by
https://github.com/ceagle/health
** availability - dict with single argument "graphite" that is used to specify connection string to graphite that stores metrics.

37 changes: 37 additions & 0 deletions etc/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"flask": {
"PORT": 5000,
"HOST": "0.0.0.0"
},

"global": {
"portal_name": "Cloud Eagle"
},

"cloud_status": {
"enabled": true,
"enabled_dashboards": ["availability", "health"],
"regions": [
{
"region": "west-1.hooli.net",
"health": {
"elastic": "<elastic_connection_string>",
"elastic_index": "<index_with_data_in_required_format>"
},
"availability": {
"graphite": "<graphite_connection_string>"
}
},
{
"region": "west-2.hooli.net",
"health": {
"elastic": "<elastic_connection_string>",
"elastic_index": "<index_with_data_in_required_format>"
},
"availability": {
"graphite": "<graphite_connection_string>"
}
}
]
}
}
1 change: 1 addition & 0 deletions tests/unit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ def setUp(self):
super(TestCase, self).setUp()
self.addCleanup(mock.patch.stopall)

main.load_config()
main.app.config["TESTING"] = True
self.app = main.app.test_client()

0 comments on commit c116ce3

Please sign in to comment.