mirror of
https://git.steelants.cz/JonatanRek/PY_DOCKER_DASHBOARD.git
synced 2026-10-11 09:05:40 +00:00
first commit
This commit is contained in:
commit
aa51255715
4 files changed
+163
No files matched your search
@@ -0,0 +1,53 @@
|
||||
from flask import Flask, render_template
|
||||
from flask_apscheduler import APScheduler
|
||||
import docker
|
||||
from pprint import pprint
|
||||
import time
|
||||
|
||||
client = docker.from_env()
|
||||
app = Flask(__name__)
|
||||
scheduler = APScheduler()
|
||||
|
||||
|
||||
@app.route("/", methods=['GET'])
|
||||
def index():
|
||||
containers = client.containers.list(all=True)
|
||||
return render_template("index.html", title="test", containers_len=len(containers), containers=containers)
|
||||
|
||||
@app.route("/parts/modal/container/<container_id>", methods=['GET'])
|
||||
def parts_container_modal(container_id):
|
||||
container = client.containers.get(container_id)
|
||||
|
||||
project = ''
|
||||
if('com.docker.compose.project' in container.attrs['Config']['Labels']):
|
||||
project = container.attrs['Config']['Labels']['com.docker.compose.project']
|
||||
|
||||
return render_template("container_modal.html", name=container.name, project=project, ports=container.attrs['NetworkSettings']['Ports'], status=container.status)
|
||||
|
||||
@app.route("/api/<container_id>/<action>", methods=['DELETE', 'POST'])
|
||||
def api_stop_container(container_id, action):
|
||||
container = client.containers.get(container_id)
|
||||
#pprint(vars(container))
|
||||
try:
|
||||
match action:
|
||||
case 'stop':
|
||||
container.stop()
|
||||
case 'start':
|
||||
container.start()
|
||||
case _:
|
||||
return 'False'
|
||||
|
||||
container = client.containers.get(container_id)
|
||||
return container.status
|
||||
except:
|
||||
return 'False'
|
||||
|
||||
|
||||
|
||||
def scheduleTasks():
|
||||
print("This test runs every 3 seconds")
|
||||
|
||||
if __name__ == '__main__':
|
||||
#scheduler.add_job(id = 'scheduled_tasks', func=scheduleTasks, trigger="interval", seconds=3)
|
||||
#scheduler.start()
|
||||
app.run(host="0.0.0.0", port=99, debug=True)
|
||||
Reference in new issue
Block a user