Refactor recreate_containers() in preparation for smart name-preserving logic

This commit is contained in:
Aanand Prasad 2014-01-15 16:15:46 +00:00
parent 8a0071d9c1
commit 3956d85a8c

View File

@ -78,19 +78,30 @@ class Service(object):
If a container for this service doesn't exist, create one. If there are If a container for this service doesn't exist, create one. If there are
any, stop them and create new ones. Does not remove the old containers. any, stop them and create new ones. Does not remove the old containers.
""" """
old_containers = self.containers(stopped=True) containers = self.containers(stopped=True)
if len(old_containers) == 0:
if len(containers) == 0:
return ([], [self.create_container(**override_options)]) return ([], [self.create_container(**override_options)])
else: else:
old_containers = []
new_containers = [] new_containers = []
for old_container in old_containers:
if old_container.is_running: for c in containers:
old_container.stop(timeout=1) (old_container, new_container) = self.recreate_container(c, **override_options)
options = dict(override_options) old_containers.append(old_container)
options['volumes_from'] = old_container.id new_containers.append(new_container)
new_containers.append(self.create_container(**options))
return (old_containers, new_containers) return (old_containers, new_containers)
def recreate_container(self, container, **override_options):
if container.is_running:
container.stop(timeout=1)
options = dict(override_options)
options['volumes_from'] = container.id
return (container, self.create_container(**options))
def start_container(self, container=None, **override_options): def start_container(self, container=None, **override_options):
if container is None: if container is None:
container = self.create_container(**override_options) container = self.create_container(**override_options)