Add a basic service status page

master
Pierre Jaury 9 years ago
parent 3a4703b764
commit 85a9ae4361

@ -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')

@ -1 +1,30 @@
{% extends "working.html" %}
{% extends "base.html" %}
{% block title %}
Services status
{% endblock %}
{% block box %}
<table class="table table-bordered">
<tbody>
<tr>
<th>Service</th>
<th>Status</th>
<th>PID</th>
<th>Image</th>
<th>Started</th>
<th>Last update</th>
</tr>
{% for name, container in containers.items() %}
<tr>
<td>{{ name }}</td>
<td><span class="label label-{{ "success" if container['State']['Running'] else "danger" }}">{{ container['State']['Status'] }}</span></td>
<td>{{ container['State']['Pid'] }}</td>
<td>{{ container['Config']['Image'] }}</td>
<td>{{ container['State']['StartedAt'] }}</td>
<td>{{ container['Image']['Created'] }}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

@ -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'])

@ -6,3 +6,4 @@ flask_wtf
WTForms-Components
Flask-bootstrap
passlib
docker-py

Loading…
Cancel
Save