This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·100 lines (60 loc) · 2.59 KB
/
Copy pathmain.py
File metadata and controls
executable file
·100 lines (60 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
import os
from flask import Flask, after_this_request, render_template, send_file
from src.http_util import HttpUtils
app = Flask(__name__)
base_url = 'http://localhost:2375'
http_utils = HttpUtils(base_url)
@app.route('/')
def index():
images = http_utils.get_json_from_endpoint("images/json")
containers = http_utils.get_json_from_endpoint("containers/json?all=true")
return render_template("index.html",images=images,containers=containers)
@app.route('/container/<container_id>')
def inspect_container(container_id):
# Fetch detailed data
endpoint = "containers/" + container_id + "/json"
container_data = http_utils.get_json_from_endpoint(endpoint)
# Fetch processes data
endpoint = "containers/" + container_id + "/top"
container_processes = http_utils.get_json_from_endpoint(endpoint)
# Fetch file system changes
endpoint = "containers/" + container_id + "/changes"
container_changes = http_utils.get_json_from_endpoint(endpoint)
return render_template('container_inspection.html', container_data=container_data, container_processes=container_processes, container_changes=container_changes)
@app.route('/container/<container_id>/json')
def inspect_container_raw(container_id):
# Fetch detailed data
endpoint = "containers/" + container_id + "/json"
container_data = http_utils.get_json_from_endpoint(endpoint)
return container_data
@app.route('/container/<container_id>/top')
def inspect_container_processes(container_id):
# Fetch detailed data
endpoint = "containers/" + container_id + "/top"
container_data = http_utils.get_json_from_endpoint(endpoint)
print(container_data)
return container_data
@app.route('/container/<container_id>/stats')
def inspect_container_stats(container_id):
# Fetch detailed data
endpoint = "containers/" + container_id + "/stats?stream=false"
container_data = http_utils.get_json_from_endpoint(endpoint)
return container_data
@app.route('/container/<container_id>/export')
def inspect_container_export(container_id):
# Fetch detailed data
endpoint = "containers/" + container_id + "/export"
container_data = http_utils.download_tar_file(endpoint,"temp_file.tar")
response = send_file("temp_file.tar", as_attachment=True)
#Remove the temporary file
@after_this_request
def remove_temp_file(response):
os.unlink("temp_file.tar")
return response
return response
# main driver function
if __name__ == '__main__':
# run() method of Flask class runs the application
# on the local development server.
app.run(host='0.0.0.0')