-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdcr
executable file
·165 lines (120 loc) · 3.63 KB
/
dcr
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
__author__ = 'thatcher'
import sys
from docker_container_runner import utils
from docker_container_runner.manager import Application, DockerDaemon, Hipache
# try:
# settingsfile = sys.argv[3]
# except:
def initialize():
"""
start it
"""
directives = utils.read_appconfig(sys.argv[1])
name, config = directives.items()[0]
release_name = config['release_name']
settingsfile = "settings.yml"
settings = utils.read_settings(settingsfile)
# Create the application
application = Application(release_name, config, settings)
# get (unitialized) containers
containers = application.get_containers()
for name, container in containers.items():
print container.status
return application
def create():
application = initialize()
application.create_containers()
def start():
application = initialize()
application.create_containers()
application.start_containers()
application.get_status()
def stop():
application = initialize()
application.stop_containers()
# setup the application from the config file
# applications = create_applications()
def print_usage():
print \
"""
usage:
dcr.py APP_CONFIGFILE [command]
each command will be executed on each host
options:
Managing the containers
-----------------------
status: show current status of the containers
create: create container
remove: remove container
start: start container
stop: stop container
pull: pull the container from the registry, will login automatically
login: login to the registry (test)
Hipache things
--------------
register: register the container on all known hipache gateways
unregister: remove this specific container from all existing gateways (container must be running)
unregister_all: remove all containers from this domain on all existing gateways
switch: remove existing gateways from back-end and register the new ones
"""
try:
stream = open(sys.argv[1])
except:
print_usage()
sys.exit(1)
directives = utils.read_appconfig(sys.argv[1])
try:
cmd = sys.argv[2]
except:
print_usage()
sys.exit("no command given")
if cmd == "status":
initialize()
elif cmd == "create":
create()
elif cmd == "remove":
application = initialize()
application.remove_containers()
elif cmd == "start":
start()
elif cmd == "stop":
stop()
elif cmd == "pull":
application = initialize()
application.login_registry()
application.pull_image()
elif cmd == "register":
try:
domain = sys.argv[3]
except BaseException as ex:
sys.exit("please provide a domain name to register")
application = initialize()
application.register(domain)
elif cmd == "unregister":
try:
domain = sys.argv[3]
except BaseException as ex:
sys.exit("please provide a domain name to register")
application = initialize()
application.unregister(domain)
elif cmd == "unregister_all":
try:
domain = sys.argv[3]
except BaseException as ex:
sys.exit("please provide a domain name to unregister everything from")
application = initialize()
application.unregister_all(domain)
elif cmd == "switch":
try:
domain = sys.argv[3]
except BaseException as ex:
sys.exit("please provide a domain name to register")
application = initialize()
application.switch_backends(domain)
elif cmd == "login":
application = initialize()
application.login_registry()
else:
print_usage()
sys.exit(1)