From 8b4ed0c1a8c5da8d1bd650698049491d702684d9 Mon Sep 17 00:00:00 2001 From: d11wtq Date: Sat, 7 Jun 2014 08:22:27 +0000 Subject: [PATCH] Spike: Add 'auto_start' option to fig.yml Signed-off-by: Chris Corbyn --- fig/project.py | 12 +++++++++--- fig/service.py | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fig/project.py b/fig/project.py index b271a810..1f1571f0 100644 --- a/fig/project.py +++ b/fig/project.py @@ -64,7 +64,13 @@ class Project(object): raise ConfigurationError('Service "%s" has a link to service "%s" which does not exist.' % (service_dict['name'], service_name)) del service_dict['links'] - project.services.append(Service(client=client, project=name, links=links, **service_dict)) + + auto_start = True + if 'auto_start' in service_dict: + auto_start = service_dict.get('auto_start', True) + del service_dict['auto_start'] + + project.services.append(Service(auto_start=auto_start, client=client, project=name, links=links, **service_dict)) return project @classmethod @@ -88,7 +94,7 @@ class Project(object): raise NoSuchService(name) - def get_services(self, service_names=None): + def get_services(self, service_names=None, auto_start=True): """ Returns a list of this project's services filtered by the provided list of names, or all services if @@ -100,7 +106,7 @@ class Project(object): do not exist. """ if service_names is None or len(service_names) == 0: - return self.services + return filter(lambda srv: srv.auto_start == auto_start, self.services) else: unsorted = [self.get_service(name) for name in service_names] return [s for s in self.services if s in unsorted] diff --git a/fig/service.py b/fig/service.py index 21a3ea40..a954dc4a 100644 --- a/fig/service.py +++ b/fig/service.py @@ -37,7 +37,7 @@ class ConfigError(ValueError): class Service(object): - def __init__(self, name, client=None, project='default', links=[], **options): + def __init__(self, name, auto_start=True, client=None, project='default', links=[], **options): if not re.match('^[a-zA-Z0-9]+$', name): raise ConfigError('Invalid name: %s' % name) if not re.match('^[a-zA-Z0-9]+$', project): @@ -45,7 +45,7 @@ class Service(object): if 'image' in options and 'build' in options: raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name) - supported_options = DOCKER_CONFIG_KEYS + ['build', 'expose'] + supported_options = DOCKER_CONFIG_KEYS + ['auto_start', 'build', 'expose'] for k in options: if k not in supported_options: @@ -55,6 +55,7 @@ class Service(object): raise ConfigError(msg) self.name = name + self.auto_start = auto_start self.client = client self.project = project self.links = links or []