1919from rest_framework .authtoken .models import Token
2020
2121from api import fields
22- from celerytasks import chef , controller
22+ from celerytasks import controller
2323from celery .canvas import group
2424
2525
@@ -235,7 +235,7 @@ class Formation(UuidAuditedModel):
235235 ssh_username = models .CharField (max_length = 64 , default = 'ubuntu' )
236236 ssh_private_key = models .TextField ()
237237 ssh_public_key = models .TextField ()
238-
238+
239239 class Meta :
240240 unique_together = (('owner' , 'id' ),)
241241
@@ -350,7 +350,7 @@ def balance(self, **kwargs):
350350 if containers_balanced :
351351 self .converge (databag )
352352 return databag
353-
353+
354354 def _balance_containers (self , ** kwargs ):
355355 backends = self .backend_set .all ().order_by ('created' )
356356 if len (backends ) < 2 :
@@ -361,10 +361,10 @@ def _balance_containers(self, **kwargs):
361361 changed = False
362362 # iterate by unique container type
363363 for container_type in set ([c .type for c in all_containers ]):
364- # map backend container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
364+ # map backend container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
365365 b_map = {}
366366 for b in backends :
367- ct = len (b .node .container_set .filter (type = container_type ))
367+ ct = len (b .node .container_set .filter (type = container_type ))
368368 b_map .setdefault (ct , []).append (b )
369369 # loop until diff between min and max is 1 or 0
370370 while max (b_map .keys ()) - min (b_map .keys ()) > 1 :
@@ -394,7 +394,7 @@ def _balance_containers(self, **kwargs):
394394 b_map .setdefault (ct , []).append (b )
395395 changed = True
396396 return changed
397-
397+
398398 def __str__ (self ):
399399 return self .id
400400
@@ -403,7 +403,7 @@ def prepare_provider(self, *args, **kwargs):
403403 args = (self .id , self .flavor .provider .creds .copy (),
404404 self .flavor .params .copy ())
405405 return tasks .prepare_formation .subtask (args )
406-
406+
407407 def calculate (self ):
408408 "Return a Chef data bag item for this formation"
409409 release = self .release_set .all ().order_by ('-created' )[0 ]
@@ -448,12 +448,12 @@ def converge(self, databag):
448448 if settings .CHEF_ENABLED :
449449 controller .update_formation .delay (self .id , databag ).wait () # @UndefinedVariable
450450 # converge all backends
451- backend_nodes = [ b .node for b in self .backend_set .all () ]
452- job = group (* [ n .converge () for n in backend_nodes ])
451+ backend_nodes = [b .node for b in self .backend_set .all ()]
452+ job = group (* [n .converge () for n in backend_nodes ])
453453 _results = job .apply_async ().join ()
454454 # converge all proxies
455- proxy_nodes = [ b .node for b in self .proxy_set .all () ]
456- job = group (* [ n .converge () for n in proxy_nodes ])
455+ proxy_nodes = [b .node for b in self .proxy_set .all ()]
456+ job = group (* [n .converge () for n in proxy_nodes ])
457457 _results = job .apply_async ().join ()
458458 return databag
459459
@@ -464,8 +464,8 @@ def destroy(self):
464464 if settings .CHEF_ENABLED :
465465 subtasks .extend ([controller .destroy_formation .s (self .id )]) # @UndefinedVariable
466466 # create subtasks to terminate all nodes in parallel
467- subtasks .extend ([ b .node .terminate () for b in self .backend_set .all () ])
468- subtasks .extend ([ p .node .terminate () for p in self .proxy_set .all () ])
467+ subtasks .extend ([b .node .terminate () for b in self .backend_set .all ()])
468+ subtasks .extend ([p .node .terminate () for p in self .proxy_set .all ()])
469469 job = group (* subtasks )
470470 job .apply_async ().join () # block for termination
471471 # purge other hosting provider infrastructure
@@ -500,7 +500,7 @@ class Node(UuidAuditedModel):
500500 List of nodes available as `formation.nodes`
501501 """
502502 objects = NodeManager ()
503-
503+
504504 NODE_TYPES = (
505505 ('backend' , 'Backend' ),
506506 ('proxy' , 'Proxy' ),
@@ -693,7 +693,7 @@ class Config(UuidAuditedModel):
693693 owner = models .ForeignKey (settings .AUTH_USER_MODEL )
694694 formation = models .ForeignKey ('Formation' )
695695 version = models .PositiveIntegerField (default = 1 )
696-
696+
697697 values = fields .EnvVarsField (default = '{}' , blank = True )
698698
699699 class Meta :
@@ -714,7 +714,7 @@ class Build(UuidAuditedModel):
714714 owner = models .ForeignKey (settings .AUTH_USER_MODEL )
715715 formation = models .ForeignKey ('Formation' )
716716 version = models .PositiveIntegerField (default = 1 )
717-
717+
718718 sha = models .CharField ('SHA' , max_length = 255 , blank = True )
719719 output = models .TextField (blank = True )
720720 # metadata
@@ -743,7 +743,7 @@ class Release(UuidAuditedModel):
743743 owner = models .ForeignKey (settings .AUTH_USER_MODEL )
744744 formation = models .ForeignKey ('Formation' )
745745 version = models .PositiveIntegerField (default = 1 )
746-
746+
747747 config = models .ForeignKey ('Config' )
748748 image = models .CharField (max_length = 256 , default = 'ubuntu' )
749749 # build only required for heroku-style apps
@@ -757,7 +757,7 @@ class Meta:
757757
758758 def __str__ (self ):
759759 return '{0}-v{1}' .format (self .formation .id , self .version )
760-
760+
761761 def rollback (self ):
762762 # create a rollback log entry
763763 # call run
@@ -787,7 +787,7 @@ def new_release(sender, **kwargs):
787787 owner = user , formation = formation , values = new_values )
788788 # create new release and auto-increment version
789789 new_version = last_release .version + 1
790- release = Release .objects .create (owner = user , formation = formation ,
790+ release = Release .objects .create (owner = user , formation = formation ,
791791 image = image , config = config , build = build , args = args , command = command ,
792792 version = new_version )
793793 return release
0 commit comments