Refactor parallel_execute.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
c4096525c2
commit
d1adbb9b25
6 changed files with 137 additions and 127 deletions
|
|
@ -7,6 +7,7 @@ from functools import reduce
|
|||
from docker.errors import APIError
|
||||
from docker.errors import NotFound
|
||||
|
||||
from . import container
|
||||
from .config import ConfigurationError
|
||||
from .config import get_service_name_from_net
|
||||
from .const import DEFAULT_TIMEOUT
|
||||
|
|
@ -22,7 +23,6 @@ from .service import parse_volume_from_spec
|
|||
from .service import Service
|
||||
from .service import ServiceNet
|
||||
from .service import VolumeFromSpec
|
||||
from .utils import parallel_execute
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -241,42 +241,22 @@ class Project(object):
|
|||
service.start(**options)
|
||||
|
||||
def stop(self, service_names=None, **options):
|
||||
parallel_execute(
|
||||
objects=self.containers(service_names),
|
||||
obj_callable=lambda c: c.stop(**options),
|
||||
msg_index=lambda c: c.name,
|
||||
msg="Stopping"
|
||||
)
|
||||
container.parallel_stop(self.containers(service_names), options)
|
||||
|
||||
def pause(self, service_names=None, **options):
|
||||
for service in reversed(self.get_services(service_names)):
|
||||
service.pause(**options)
|
||||
container.parallel_pause(reversed(self.containers(service_names)), options)
|
||||
|
||||
def unpause(self, service_names=None, **options):
|
||||
for service in self.get_services(service_names):
|
||||
service.unpause(**options)
|
||||
container.parallel_unpause(self.containers(service_names), options)
|
||||
|
||||
def kill(self, service_names=None, **options):
|
||||
parallel_execute(
|
||||
objects=self.containers(service_names),
|
||||
obj_callable=lambda c: c.kill(**options),
|
||||
msg_index=lambda c: c.name,
|
||||
msg="Killing"
|
||||
)
|
||||
container.parallel_kill(self.containers(service_names), options)
|
||||
|
||||
def remove_stopped(self, service_names=None, **options):
|
||||
all_containers = self.containers(service_names, stopped=True)
|
||||
stopped_containers = [c for c in all_containers if not c.is_running]
|
||||
parallel_execute(
|
||||
objects=stopped_containers,
|
||||
obj_callable=lambda c: c.remove(**options),
|
||||
msg_index=lambda c: c.name,
|
||||
msg="Removing"
|
||||
)
|
||||
container.parallel_remove(self.containers(service_names, stopped=True), options)
|
||||
|
||||
def restart(self, service_names=None, **options):
|
||||
for service in self.get_services(service_names):
|
||||
service.restart(**options)
|
||||
container.parallel_restart(self.containers(service_names, stopped=True), options)
|
||||
|
||||
def build(self, service_names=None, no_cache=False, pull=False, force_rm=False):
|
||||
for service in self.get_services(service_names):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue