Scaling down removes containers

Squashed version of #162.
Closes #121.
This commit is contained in:
sebastianneubauer 2014-03-21 19:34:19 +01:00 • committed by Aanand Prasad
commit 352ad7a38c
4 changed files with 60 additions and 8 deletions

View file

@ -85,6 +85,14 @@ class Service(object):
c.kill(**options)
def scale(self, desired_num):
"""
Adjusts the number of containers to the specified number and ensures they are running.
- creates containers until there are at least `desired_num`
- stops containers until there are at most `desired_num` running
- starts containers until there are at least `desired_num` running
- removes all stopped containers
"""
if not self.can_be_scaled():
raise CannotBeScaledError()
@ -117,6 +125,8 @@ class Service(object):
self.start_container(c)
running_containers.append(c)
self.remove_stopped()
def remove_stopped(self, **options):
for c in self.containers(stopped=True):