From 464ab3d7273317507fe42fe1ef03ac3e08d0bd86 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Mon, 15 Jun 2015 23:06:06 -0400 Subject: [PATCH] Add a method specifically for service name validation. Signed-off-by: Dan O'Reilly --- compose/project.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compose/project.py b/compose/project.py index e6ec6d676..d7d350611 100644 --- a/compose/project.py +++ b/compose/project.py @@ -99,6 +99,16 @@ class Project(object): raise NoSuchService(name) + def validate_service_names(self, service_names): + """ + Validate that the given list of service names only contains valid + services. Raises NoSuchService if one of the names is invalid. + """ + valid_names = self.service_names + for name in service_names: + if name not in valid_names: + raise NoSuchService(name) + def get_services(self, service_names=None, include_deps=False): """ Returns a list of this project's services filtered @@ -275,8 +285,7 @@ class Project(object): def containers(self, service_names=None, stopped=False, one_off=False): if service_names: - # Will raise NoSuchService if one of the names is invalid - self.get_services(service_names) + self.validate_service_names(service_names) containers = [ Container.from_ps(self.client, container) for container in self.client.containers(