@@ -101,15 +101,12 @@ def _get_machines(self):
101101
102102 # container api
103103
104- def create (self , name , image , command = '' , template = None , use_announcer = True , ** kwargs ):
104+ def create (self , name , image , command = '' , template = None , ** kwargs ):
105105 """Create a container"""
106106 self ._create_container (name , image , command ,
107107 template or copy .deepcopy (CONTAINER_TEMPLATE ), ** kwargs )
108108 self ._create_log (name , image , command , copy .deepcopy (LOG_TEMPLATE ))
109109
110- if use_announcer :
111- self ._create_announcer (name , image , command , copy .deepcopy (ANNOUNCE_TEMPLATE ))
112-
113110 def _create_container (self , name , image , command , unit , ** kwargs ):
114111 l = locals ().copy ()
115112 l .update (re .match (MATCH , name ).groupdict ())
@@ -146,22 +143,10 @@ def _create_log(self, name, image, command, unit):
146143 # post unit to fleet
147144 self ._put_unit (name + '-log' , {"desiredState" : "launched" , "options" : unit })
148145
149- def _create_announcer (self , name , image , command , unit ):
150- l = locals ().copy ()
151- l .update (re .match (MATCH , name ).groupdict ())
152- # construct unit from template
153- for f in unit :
154- f ['value' ] = f ['value' ].format (** l )
155- # post unit to fleet
156- self ._put_unit (name + '-announce' , {"desiredState" : "launched" , "options" : unit })
157-
158- def start (self , name , use_announcer = True ):
146+ def start (self , name ):
159147 """Start a container"""
160148 self ._wait_for_container (name )
161149
162- if use_announcer :
163- self ._wait_for_announcer (name )
164-
165150 def _wait_for_container (self , name ):
166151 # we bump to 20 minutes here to match the timeout on the router and in the app unit files
167152 for _ in range (1200 ):
@@ -177,24 +162,6 @@ def _wait_for_container(self, name):
177162 else :
178163 raise RuntimeError ('container failed to start' )
179164
180- def _wait_for_announcer (self , name ):
181- # wait a bit for the announcer to come up, otherwise we may have hit
182- # https://github.com/docker/docker/issues/8022
183- for _ in range (30 ):
184- states = self ._get_state (name )
185- if states and len (states .get ('states' , [])) == 1 :
186- state = states .get ('states' )[0 ]
187- subState = state .get ('systemdSubState' )
188- if subState == 'running' :
189- # wait for the router to be reconfigured
190- time .sleep (10 )
191- break
192- elif subState == 'failed' :
193- raise RuntimeError ('announcer failed to start' )
194- time .sleep (1 )
195- else :
196- raise RuntimeError ('announcer timeout on start' )
197-
198165 def _wait_for_destroy (self , name ):
199166 for _ in range (30 ):
200167 states = self ._get_state (name )
@@ -204,15 +171,13 @@ def _wait_for_destroy(self, name):
204171 else :
205172 raise RuntimeError ('timeout on container destroy' )
206173
207- def stop (self , name , use_announcer = True ):
174+ def stop (self , name ):
208175 """Stop a container"""
209176 raise NotImplementedError
210177
211- def destroy (self , name , use_announcer = True ):
178+ def destroy (self , name ):
212179 """Destroy a container"""
213180 funcs = []
214- if use_announcer :
215- funcs .append (functools .partial (self ._destroy_announcer , name ))
216181 funcs .append (functools .partial (self ._destroy_container , name ))
217182 funcs .append (functools .partial (self ._destroy_log , name ))
218183 # call all destroy functions, ignoring any errors
@@ -226,9 +191,6 @@ def destroy(self, name, use_announcer=True):
226191 def _destroy_container (self , name ):
227192 return self ._delete_unit (name )
228193
229- def _destroy_announcer (self , name ):
230- return self ._delete_unit (name + '-announce' )
231-
232194 def _destroy_log (self , name ):
233195 return self ._delete_unit (name + '-log' )
234196
@@ -350,18 +312,6 @@ def attach(self, name):
350312]
351313
352314
353- ANNOUNCE_TEMPLATE = [
354- {"section" : "Unit" , "name" : "Description" , "value" : "{name} announce" },
355- {"section" : "Unit" , "name" : "BindsTo" , "value" : "{name}.service" },
356- {"section" : "Service" , "name" : "EnvironmentFile" , "value" : "/etc/environment" },
357- {"section" : "Service" , "name" : "ExecStartPre" , "value" : '''/bin/sh -c "until docker inspect -f '{{{{range $i, $e := .NetworkSettings.Ports }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name} >/dev/null 2>&1; do sleep 2; done; port=$(docker inspect -f '{{{{range $i, $e := .NetworkSettings.Ports }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); if [[ -z $port ]]; then echo We have no port...; exit 1; fi; echo Waiting for $port/tcp...; until netstat -lnt | grep :$port >/dev/null; do sleep 1; done"''' }, # noqa
358- {"section" : "Service" , "name" : "ExecStart" , "value" : '''/bin/sh -c "port=$(docker inspect -f '{{{{range $i, $e := .NetworkSettings.Ports }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); echo Connected to $COREOS_PRIVATE_IPV4:$port/tcp, publishing to etcd...; while netstat -lnt | grep :$port >/dev/null; do etcdctl set /deis/services/{app}/{name} $COREOS_PRIVATE_IPV4:$port --ttl 60 >/dev/null; sleep 45; done"''' }, # noqa
359- {"section" : "Service" , "name" : "ExecStop" , "value" : "/usr/bin/etcdctl rm --recursive /deis/services/{app}/{name}" }, # noqa
360- {"section" : "Service" , "name" : "TimeoutStartSec" , "value" : "20m" },
361- {"section" : "X-Fleet" , "name" : "MachineOf" , "value" : "{name}.service" },
362- ]
363-
364-
365315RUN_TEMPLATE = [
366316 {"section" : "Unit" , "name" : "Description" , "value" : "{name} admin command" },
367317 {"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