diff --git a/admin/freeposte/__init__.py b/admin/freeposte/__init__.py index 96e6d564..64d8eade 100644 --- a/admin/freeposte/__init__.py +++ b/admin/freeposte/__init__.py @@ -4,6 +4,7 @@ from flask_bootstrap import Bootstrap from flask.ext import login as flask_login import os +import docker # Create application @@ -12,7 +13,8 @@ app = Flask(__name__) default_config = { 'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/freeposte.db', 'SQLALCHEMY_TRACK_MODIFICATIONS': False, - 'SECRET_KEY': "changeMe", + 'SECRET_KEY': 'changeMe', + 'DOCKER_SOCKET': 'unix:///var/run/docker.sock', 'DEBUG': False } @@ -26,6 +28,9 @@ db = SQLAlchemy(app) login_manager = flask_login.LoginManager() login_manager.init_app(app) +# Connect to the Docker socket +dockercli = docker.Client(base_url=app.config['DOCKER_SOCKET']) + # Finally setup the blueprint from freeposte import admin app.register_blueprint(admin.app, url_prefix='/admin') diff --git a/admin/freeposte/admin/templates/admin/status.html b/admin/freeposte/admin/templates/admin/status.html index a500fb36..749898db 100644 --- a/admin/freeposte/admin/templates/admin/status.html +++ b/admin/freeposte/admin/templates/admin/status.html @@ -1 +1,30 @@ -{% extends "working.html" %} +{% extends "base.html" %} + +{% block title %} +Services status +{% endblock %} + +{% block box %} + + + + + + + + + + + {% for name, container in containers.items() %} + + + + + + + + {% endfor %} + +
ServiceStatusPIDImageStartedLast update
{{ name }}{{ container['State']['Status'] }}{{ container['State']['Pid'] }}{{ container['Config']['Image'] }}{{ container['State']['StartedAt'] }}{{ container['Image']['Created'] }} +
+{% endblock %} diff --git a/admin/freeposte/admin/views/administrators.py b/admin/freeposte/admin/views/administrators.py index 950de45e..2570ca06 100644 --- a/admin/freeposte/admin/views/administrators.py +++ b/admin/freeposte/admin/views/administrators.py @@ -1,15 +1,26 @@ +from freeposte import dockercli from freeposte.admin import app, db, models, forms, utils from flask.ext import login as flask_login import os +import pprint import flask +import json @app.route('/status', methods=['GET']) @flask_login.login_required def status(): utils.require_global_admin() - return flask.render_template('admin/status.html') + containers = {} + for brief in dockercli.containers(all=True): + if brief['Image'].startswith('freeposte/'): + container = dockercli.inspect_container(brief['Id']) + container['Image'] = dockercli.inspect_image(container['Image']) + name = container['Config']['Labels']['com.docker.compose.service'] + containers[name] = container + pprint.pprint(container) + return flask.render_template('admin/status.html', containers=containers) @app.route('/admins', methods=['GET']) diff --git a/admin/requirements.txt b/admin/requirements.txt index b93d256e..9069ffa4 100644 --- a/admin/requirements.txt +++ b/admin/requirements.txt @@ -6,3 +6,4 @@ flask_wtf WTForms-Components Flask-bootstrap passlib +docker-py