Skip to content

Commit 14aa7e4

Browse files
author
Gabriel Monroy
committed
use layer to define run_list and initial attributes
1 parent 1206fe6 commit 14aa7e4

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

api/models.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def scale_layers(self, **kwargs):
265265
job = [func() for func in funcs ]
266266
# balance containers
267267
containers_balanced = self._balance_containers()
268-
# launch/terminate backends and proxies in parallel
268+
# launch/terminate nodes in parallel
269269
if job:
270270
group(*job).apply_async().join()
271271
# once nodes are in place, recalculate the formation and update the data bag
@@ -327,14 +327,14 @@ def balance(self, **kwargs):
327327
def _balance_containers(self, **kwargs):
328328
runtime_nodes = self.node_set.filter(layer__id='runtime').order_by('created')
329329
if len(runtime_nodes) < 2:
330-
return # there's nothing to balance with 1 backend
330+
return # there's nothing to balance with 1 runtime node
331331
all_containers = Container.objects.filter(formation=self).order_by('-created')
332332
# get the next container number (e.g. web.19)
333333
container_num = 1 if not all_containers else all_containers[0].num + 1
334334
changed = False
335335
# iterate by unique container type
336336
for container_type in set([c.type for c in all_containers]):
337-
# map backend container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
337+
# map node container counts => { 2: [b3, b4], 3: [ b1, b2 ] }
338338
n_map = {}
339339
for node in runtime_nodes:
340340
ct = len(node.container_set.filter(type=container_type))
@@ -418,13 +418,8 @@ def converge(self, databag):
418418
# call a celery task to update the formation data bag
419419
if settings.CHEF_ENABLED:
420420
controller.update_formation.delay(self.id, databag).wait() # @UndefinedVariable
421-
# converge all backends
422-
backend_nodes = [ b.node for b in self.backend_set.all() ]
423-
job = group(*[ n.converge() for n in backend_nodes ])
424-
_results = job.apply_async().join()
425-
# converge all proxies
426-
proxy_nodes = [ b.node for b in self.proxy_set.all() ]
427-
job = group(*[ n.converge() for n in proxy_nodes ])
421+
nodes = [ node for node in self.node_set.all() ]
422+
job = group(*[ n.converge() for n in nodes ])
428423
_results = job.apply_async().join()
429424
return databag
430425

@@ -531,17 +526,9 @@ def _prepare_launch_args(self):
531526
chef['validation_name'] = settings.CHEF_VALIDATION_NAME
532527
chef['validation_key'] = settings.CHEF_VALIDATION_KEY
533528
chef['node_name'] = self.id
534-
# append to the default run_list
535-
run_list = chef.setdefault('run_list', [])
536-
attrs = chef['initial_attributes'] = {}
537-
if self.type == 'backend':
538-
run_list.append('role[deis-backend]')
539-
attrs.setdefault('deis', {}).setdefault(
540-
'runtime', {}).setdefault('formations', [ self.formation.id ])
541-
elif self.type == 'proxy':
542-
run_list.append('role[deis-proxy]')
543-
attrs.setdefault('deis', {}).setdefault(
544-
'proxy', {}).setdefault('formations', [ self.formation.id ])
529+
# use the layer's run list
530+
chef['run_list'] = self.layer.run_list
531+
chef['initial_attributes'] = self.layer.initial_attributes
545532
# add the formation's ssh pubkey
546533
init.setdefault('ssh_authorized_keys', []).append(
547534
self.formation.ssh_public_key)

0 commit comments

Comments
 (0)