Move keep_old check up into Project
Signed-off-by: Chris Corbyn <chris@w3style.co.uk>
This commit is contained in:
parent
a04143e2a7
commit
ab1fbc96c3
4 changed files with 48 additions and 54 deletions
|
|
@ -139,13 +139,17 @@ class Project(object):
|
|||
log.info('%s uses an image, skipping' % service.name)
|
||||
|
||||
def up(self, service_names=None, start_links=True, keep_old=False):
|
||||
new_containers = []
|
||||
running_containers = []
|
||||
|
||||
for service in self.get_services(service_names, include_links=start_links):
|
||||
for (_, new) in service.recreate_containers(keep_old):
|
||||
new_containers.append(new)
|
||||
if keep_old:
|
||||
for container in service.start_or_create_containers():
|
||||
running_containers.append(container)
|
||||
else:
|
||||
for (_, container) in service.recreate_containers():
|
||||
running_containers.append(container)
|
||||
|
||||
return new_containers
|
||||
return running_containers
|
||||
|
||||
def remove_stopped(self, service_names=None, **options):
|
||||
for service in self.get_services(service_names):
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class Service(object):
|
|||
return Container.create(self.client, **container_options)
|
||||
raise
|
||||
|
||||
def recreate_containers(self, keep_old=False, **override_options):
|
||||
def recreate_containers(self, **override_options):
|
||||
"""
|
||||
If a container for this service doesn't exist, create and start one. If there are
|
||||
any, stop them, create+start new ones, and remove the old containers.
|
||||
|
|
@ -166,8 +166,6 @@ class Service(object):
|
|||
container = self.create_container(**override_options)
|
||||
self.start_container(container)
|
||||
return [(None, container)]
|
||||
elif keep_old:
|
||||
return [(None, self.start_container_if_stopped(c)) for c in containers]
|
||||
else:
|
||||
tuples = []
|
||||
|
||||
|
|
@ -249,6 +247,16 @@ class Service(object):
|
|||
)
|
||||
return container
|
||||
|
||||
def start_or_create_containers(self):
|
||||
containers = self.containers(stopped=True)
|
||||
|
||||
if len(containers) == 0:
|
||||
log.info("Creating %s..." % self.next_container_name())
|
||||
new_container = self.create_container()
|
||||
return [self.start_container(new_container)]
|
||||
else:
|
||||
return [self.start_container_if_stopped(c) for c in containers]
|
||||
|
||||
def get_linked_names(self):
|
||||
return [s.name for (s, _) in self.links]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue