Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
fix bug with change flag in scale_containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Jul 26, 2013
1 parent d83c2c0 commit 663dc88
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,18 @@ def scale_containers(self, **kwargs):
all_containers = self.container_set.all().order_by('-created')
container_num = 1 if not all_containers else all_containers[0].num + 1
# iterate and scale by container type (web, worker, etc)
change = False
changed = False
for container_type in requested_containers.keys():
containers = list(self.container_set.filter(type=container_type).order_by('created'))
requested = requested_containers.pop(container_type)
diff = requested - len(containers)
change = 0
if diff == 0:
return change
continue
changed = True
while diff < 0:
c = containers.pop(0)
c.delete()
diff = requested - len(containers)
change -= 1
while diff > 0:
node = Formation.objects.next_container_node(self, container_type)
c = Container.objects.create(owner=self.owner,
Expand All @@ -314,10 +313,9 @@ def scale_containers(self, **kwargs):
containers.append(c)
container_num += 1
diff = requested - len(containers)
change +=1
# once nodes are in place, recalculate the formation and update the data bag
databag = self.calculate()
if change is True:
if changed is True:
self.converge(databag)
return databag

Expand Down

0 comments on commit 663dc88

Please sign in to comment.