-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmanage.py
121 lines (94 loc) · 2.93 KB
/
manage.py
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from manager import Manager
from docker import Client
from docker.utils import kwargs_from_env
import DockerBackend
import dhbox
import os
from subprocess import call
import docker.errors
manager = Manager()
@manager.command
def new_seed():
"""Build new seed for DH Box"""
response = DockerBackend.build_dhbox()
return response
@manager.command
def start():
"""download seed for DH Box"""
response = DockerBackend.download_dhbox()
return response
@manager.command
def test():
"""Build new test DH Box"""
response = DockerBackend.setup_new_dhbox('test', 'password', '[email protected]')
return response
@manager.command
def start_over():
"""Delete and make a new test DH Box"""
cleanup()
response = DockerBackend.kill_dhbox('test')
response = DockerBackend.kill_dhbox('test_wp')
DockerBackend.setup_new_dhbox('test', 'password', '[email protected]')
return response
@manager.command
def clean_slate():
"""Delete all DH Boxes"""
cleanup()
response = DockerBackend.kill_dhbox('test')
DockerBackend.setup_new_dhbox('test', 'password', '[email protected]')
return response
@manager.command
def killctr(ctr_name):
"""Delete a container"""
print "killing container " + ctr_name
response = DockerBackend.kill_dhbox(ctr_name)
return response
@manager.command
def renew_admin():
"""Updates admin's DH Box to the new seed."""
DockerBackend.replace_admin_dhbox_image()
@manager.command
def build_database():
"""Builds website database and adds admin."""
if not os.path.exists('dhbox-docker.db'):
print "Creating DH Box database"
dhbox.db.create_all()
dhbox.create_user_and_role()
else:
print "Database exists."
@manager.command
def cleanup():
"""Delete ALL stopped containers, unnamed images"""
print "Deleting stopped containers"
call("docker ps -a | grep Exit | awk '{print $1}' | xargs docker rm", shell=True)
print "Deleting images"
delete_untagged()
@manager.command
def police():
"""check for boxes over their time limit, kill them"""
dhbox.police()
def delete_untagged():
"""Find the untagged images and remove them"""
images = c.images()
found = False
for image in images:
if image["RepoTags"] == ["<none>:<none>"]:
found = True
image_id = image["Id"]
print "Deleting untagged image\nhash=", image_id
try:
c.remove_image(image["Id"])
except docker.errors.APIError as error:
print "Failed to delete image\nhash={}\terror={}", image_id, error
if not found:
print "Didn't find any untagged images to delete!"
@manager.command
def check_users():
"""list all usernames and emails"""
users = dhbox.User.query.all()
for user in users:
print user.name
print user.email
c = DockerBackend.attach_to_docker_client()
if __name__ == '__main__':
manager.main()