@@ -83,7 +83,6 @@ def delete(self, *args, **kwargs):
8383 self .owner .publish ()
8484
8585
86- @python_2_unicode_compatible
8786class ProviderManager (models .Manager ):
8887 """Manage database interactions for :class:`Provider`."""
8988
@@ -126,7 +125,6 @@ def __str__(self):
126125 return "{}-{}" .format (self .id , self .get_type_display ())
127126
128127
129- @python_2_unicode_compatible
130128class FlavorManager (models .Manager ):
131129 """Manage database interactions for :class:`Flavor`."""
132130
@@ -187,19 +185,33 @@ def flat(self):
187185 'nodes' : self .nodes }
188186
189187 def build (self ):
190- tasks . build_formation . delay ( self ). wait ()
188+ return
191189
192190 def destroy (self , * args , ** kwargs ):
193- tasks .destroy_formation .delay (self ).wait ()
191+ app_tasks = [tasks .destroy_app .si (a ) for a in self .app_set .all ()]
192+ node_tasks = [tasks .destroy_node .si (n ) for n in self .node_set .all ()]
193+ layer_tasks = [tasks .destroy_layer .si (l ) for l in self .layer_set .all ()]
194+ group (app_tasks + node_tasks ).apply_async ().join ()
195+ group (layer_tasks ).apply_async ().join ()
196+ CM .purge_formation (self .flat ())
197+ self .delete ()
198+ tasks .converge_controller .apply_async ().wait ()
194199
195200 def publish (self ):
196201 data = self .calculate ()
197202 CM .publish_formation (self .flat (), data )
198203 return data
199204
200- def converge (self , ** kwargs ):
205+ def converge (self , controller = False , ** kwargs ):
201206 databag = self .publish ()
202- tasks .converge_formation .delay (self ).wait ()
207+ nodes = self .node_set .all ()
208+ subtasks = []
209+ for n in nodes :
210+ subtask = tasks .converge_node .si (n )
211+ subtasks .append (subtask )
212+ if controller is True :
213+ subtasks .append (tasks .converge_controller .si ())
214+ group (* subtasks ).apply_async ().join ()
203215 return databag
204216
205217 def calculate (self ):
@@ -292,7 +304,6 @@ def destroy(self):
292304 return tasks .destroy_layer .delay (self ).wait ()
293305
294306
295- @python_2_unicode_compatible
296307class NodeManager (models .Manager ):
297308
298309 def new (self , formation , layer , fqdn = None ):
@@ -462,10 +473,11 @@ def build(self):
462473 Release .objects .create (
463474 version = 1 , owner = self .owner , app = self , config = config , build = build )
464475 self .formation .publish ()
465- tasks .build_app .delay (self ).wait ()
466476
467477 def destroy (self ):
468- tasks .destroy_app .delay (self ).wait ()
478+ CM .purge_app (self .flat ())
479+ self .delete ()
480+ self .formation .publish ()
469481
470482 def publish (self ):
471483 """Publish the application to configuration management"""
@@ -519,6 +531,7 @@ def logs(self):
519531
520532 def run (self , command ):
521533 """Run a one-off command in an ephemeral app container."""
534+ # TODO: add support for interactive shell
522535 nodes = self .formation .node_set .filter (layer__runtime = True ).order_by ('?' )
523536 if not nodes :
524537 raise EnvironmentError ('No nodes available to run command' )
@@ -527,17 +540,13 @@ def run(self, command):
527540 # prepare ssh command
528541 version = release .version
529542 docker_args = ' ' .join (
530- ['-v' ,
531- '/opt/deis/runtime/slugs/{app_id}-{version}/app:/app' .format (** locals ()),
532- release .build .image ])
533- base_cmd = "export HOME=/app; cd /app && for profile in " \
534- "`find /app/.profile.d/*.sh -type f`; do . $profile; done"
535- command = "/bin/sh -c '{base_cmd} && {command}'" .format (** locals ())
543+ ['-a' , 'stdout' , '-a' , 'stderr' ,
544+ '-v' , '/opt/deis/runtime/slugs/{app_id}-v{version}:/app' .format (** locals ()),
545+ 'deis/slugrunner' ])
536546 command = "sudo docker run {docker_args} {command}" .format (** locals ())
537547 return node .run (command )
538548
539549
540- @python_2_unicode_compatible
541550class ContainerManager (models .Manager ):
542551
543552 def scale (self , app , structure , ** kwargs ):
@@ -733,7 +742,7 @@ def push(cls, push):
733742 # create the build
734743 new_build = cls .objects .create (** push )
735744 # send a release signal
736- release_signal .send (sender = push , build = new_build , app = app , user = user )
745+ release_signal .send (sender = user , build = new_build , app = app , user = user )
737746 # see if we need to scale an initial web container
738747 if len (app .formation .node_set .filter (layer__runtime = True )) > 0 and \
739748 len (app .container_set .filter (type = 'web' )) < 1 :
0 commit comments