UI - basic read from docker API
This commit is contained in:
parent
002e3ed2ba
commit
e6b5f460c9
@ -2,8 +2,30 @@
|
|||||||
|
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
import wrappers
|
||||||
|
|
||||||
app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates")
|
app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates")
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
return render_template("home.html", title="Home")
|
check, instances = wrappers.get_instances()
|
||||||
|
if not check :
|
||||||
|
return render_template("error.html", title="Error", error=instances)
|
||||||
|
check, services = wrappers.get_services()
|
||||||
|
if not check :
|
||||||
|
return render_template("error.html", title="Error", error=services)
|
||||||
|
return render_template("home.html", title="Home", instances_number=len(instances), services_number=len(services))
|
||||||
|
|
||||||
|
@app.route('/instances')
|
||||||
|
def home():
|
||||||
|
check, instances = wrappers.get_instances()
|
||||||
|
if not check :
|
||||||
|
return render_template("error.html", title="Error", error=instances)
|
||||||
|
return render_template("instances.html", title="Instances", instances=instances)
|
||||||
|
|
||||||
|
@app.route('/services')
|
||||||
|
def home():
|
||||||
|
check, services = wrappers.get_services()
|
||||||
|
if not check :
|
||||||
|
return render_template("error.html", title="Error", error=services)
|
||||||
|
return render_template("services.html", title="Services", services=services)
|
||||||
|
|||||||
9
ui/templates/error.html
Normal file
9
ui/templates/error.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
Something went wrong.
|
||||||
|
|
||||||
|
Some information : {{ error }}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
Lorem ipsum.
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
{{ instances_number }} bunkerized-nginx instances
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{{ services_number }} web services
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
15
ui/templates/instances.html
Normal file
15
ui/templates/instances.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
{% for instance in instances %}
|
||||||
|
<div class="col row-cols-1 row-cols-md-3">
|
||||||
|
ID = {{ instance["id"] }}<br />
|
||||||
|
Name = {{ instance["name"] }}<br />
|
||||||
|
Status = {{ instance["status"] }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@ -11,7 +11,10 @@
|
|||||||
<a class="nav-link" href="/">Home</a>
|
<a class="nav-link" href="/">Home</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="#">Link</a>
|
<a class="nav-link" href="/instances">Instances</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/services">Services</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
15
ui/templates/services.html
Normal file
15
ui/templates/services.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
{% for service in services %}
|
||||||
|
<div class="col row-cols-1 row-cols-md-3">
|
||||||
|
ID = {{ instance["id"] }}<br />
|
||||||
|
Name = {{ instance["name"] }}<br />
|
||||||
|
Status = {{ instance["status"] }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
30
ui/wrappers.py
Normal file
30
ui/wrappers.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import utils, config
|
||||||
|
import docker, os, stat, sys
|
||||||
|
|
||||||
|
def get_client() :
|
||||||
|
endpoint = "/var/run/docker.sock"
|
||||||
|
if not os.path.exists(endpoint) or not stat.S_ISSOCK(os.stat(endpoint).st_mode) :
|
||||||
|
return False, "Can't connect to /var/run/docker.sock (is it mounted ?)"
|
||||||
|
try :
|
||||||
|
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')
|
||||||
|
except Exception as e :
|
||||||
|
return False, "Can't instantiate DockerClient : " + str(e)
|
||||||
|
return True, client
|
||||||
|
|
||||||
|
def get_containers(label) :
|
||||||
|
check, client = get_client()
|
||||||
|
if not check :
|
||||||
|
return check, client
|
||||||
|
try :
|
||||||
|
containers = client.containers.list(all=True, filters={"label" : "bunkerized-nginx." + label})
|
||||||
|
except docker.errors.APIError as e :
|
||||||
|
return False, "Docker API error " + str(e)
|
||||||
|
return True, containers
|
||||||
|
|
||||||
|
def get_instances() :
|
||||||
|
return get_containers("UI")
|
||||||
|
|
||||||
|
def get_services() :
|
||||||
|
return get_containers("SERVER_NAME")
|
||||||
Loading…
x
Reference in New Issue
Block a user