|
1 | 1 | import cStringIO |
2 | 2 | import base64 |
3 | 3 | import copy |
4 | | -import functools |
5 | 4 | import json |
6 | 5 | import httplib |
7 | 6 | import paramiko |
@@ -105,7 +104,6 @@ def create(self, name, image, command='', template=None, **kwargs): |
105 | 104 | """Create a container""" |
106 | 105 | self._create_container(name, image, command, |
107 | 106 | template or copy.deepcopy(CONTAINER_TEMPLATE), **kwargs) |
108 | | - self._create_log(name, image, command, copy.deepcopy(LOG_TEMPLATE)) |
109 | 107 |
|
110 | 108 | def _create_container(self, name, image, command, unit, **kwargs): |
111 | 109 | l = locals().copy() |
@@ -138,15 +136,6 @@ def _create_container(self, name, image, command, unit, **kwargs): |
138 | 136 | # post unit to fleet |
139 | 137 | self._put_unit(name, {"desiredState": "launched", "options": unit}) |
140 | 138 |
|
141 | | - def _create_log(self, name, image, command, unit): |
142 | | - l = locals().copy() |
143 | | - l.update(re.match(MATCH, name).groupdict()) |
144 | | - # construct unit from template |
145 | | - for f in unit: |
146 | | - f['value'] = f['value'].format(**l) |
147 | | - # post unit to fleet |
148 | | - self._put_unit(name+'-log', {"desiredState": "launched", "options": unit}) |
149 | | - |
150 | 139 | def start(self, name): |
151 | 140 | """Start a container""" |
152 | 141 | self._wait_for_container(name) |
@@ -181,23 +170,16 @@ def stop(self, name): |
181 | 170 |
|
182 | 171 | def destroy(self, name): |
183 | 172 | """Destroy a container""" |
184 | | - funcs = [] |
185 | | - funcs.append(functools.partial(self._destroy_container, name)) |
186 | | - funcs.append(functools.partial(self._destroy_log, name)) |
187 | 173 | # call all destroy functions, ignoring any errors |
188 | | - for f in funcs: |
189 | | - try: |
190 | | - f() |
191 | | - except: |
192 | | - pass |
| 174 | + try: |
| 175 | + self._destroy_container(name) |
| 176 | + except: |
| 177 | + pass |
193 | 178 | self._wait_for_destroy(name) |
194 | 179 |
|
195 | 180 | def _destroy_container(self, name): |
196 | 181 | return self._delete_unit(name) |
197 | 182 |
|
198 | | - def _destroy_log(self, name): |
199 | | - return self._delete_unit(name+'-log') |
200 | | - |
201 | 183 | def run(self, name, image, entrypoint, command): # noqa |
202 | 184 | """Run a one-off command""" |
203 | 185 | self._create_container(name, image, command, copy.deepcopy(RUN_TEMPLATE), |
@@ -307,16 +289,6 @@ def attach(self, name): |
307 | 289 | ] |
308 | 290 |
|
309 | 291 |
|
310 | | -LOG_TEMPLATE = [ |
311 | | - {"section": "Unit", "name": "Description", "value": "{name} log"}, |
312 | | - {"section": "Unit", "name": "BindsTo", "value": "{name}.service"}, |
313 | | - {"section": "Service", "name": "ExecStartPre", "value": '''/bin/sh -c "until docker inspect {name} >/dev/null 2>&1; do sleep 1; done"'''}, # noqa |
314 | | - {"section": "Service", "name": "ExecStart", "value": '''/bin/sh -c "docker logs -f {name} 2>&1 | logger -p local0.info -t {app}[{c_type}.{c_num}] --udp --server $(etcdctl get /deis/logs/host) --port $(etcdctl get /deis/logs/port)"'''}, # noqa |
315 | | - {"section": "Service", "name": "TimeoutStartSec", "value": "20m"}, |
316 | | - {"section": "X-Fleet", "name": "MachineOf", "value": "{name}.service"}, |
317 | | -] |
318 | | - |
319 | | - |
320 | 292 | RUN_TEMPLATE = [ |
321 | 293 | {"section": "Unit", "name": "Description", "value": "{name} admin command"}, |
322 | 294 | {"section": "Service", "name": "ExecStartPre", "value": '''/bin/sh -c "IMAGE=$(etcdctl get /deis/registry/host 2>&1):$(etcdctl get /deis/registry/port 2>&1)/{image}; docker pull $IMAGE"'''}, # noqa |
|
0 commit comments