Add support for ro option in volumes_from
Fixes #1188 Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
19271898de
commit
5b55a08846
7 changed files with 97 additions and 35 deletions
|
|
@ -6,7 +6,6 @@ import os
|
|||
import re
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from operator import attrgetter
|
||||
|
||||
import enum
|
||||
import six
|
||||
|
|
@ -82,6 +81,9 @@ class NoSuchImageError(Exception):
|
|||
VolumeSpec = namedtuple('VolumeSpec', 'external internal mode')
|
||||
|
||||
|
||||
VolumeFromSpec = namedtuple('VolumeFromSpec', 'source mode')
|
||||
|
||||
|
||||
ServiceName = namedtuple('ServiceName', 'project service number')
|
||||
|
||||
|
||||
|
|
@ -519,7 +521,7 @@ class Service(object):
|
|||
return [(service.name, alias) for service, alias in self.links]
|
||||
|
||||
def get_volumes_from_names(self):
|
||||
return [s.name for s in self.volumes_from if isinstance(s, Service)]
|
||||
return [s.source.name for s in self.volumes_from if isinstance(s.source, Service)]
|
||||
|
||||
def get_container_name(self, number, one_off=False):
|
||||
# TODO: Implement issue #652 here
|
||||
|
|
@ -559,16 +561,9 @@ class Service(object):
|
|||
|
||||
def _get_volumes_from(self):
|
||||
volumes_from = []
|
||||
for volume_source in self.volumes_from:
|
||||
if isinstance(volume_source, Service):
|
||||
containers = volume_source.containers(stopped=True)
|
||||
if not containers:
|
||||
volumes_from.append(volume_source.create_container().id)
|
||||
else:
|
||||
volumes_from.extend(map(attrgetter('id'), containers))
|
||||
|
||||
elif isinstance(volume_source, Container):
|
||||
volumes_from.append(volume_source.id)
|
||||
for volume_from_spec in self.volumes_from:
|
||||
volumes = build_volume_from(volume_from_spec)
|
||||
volumes_from.extend(volumes)
|
||||
|
||||
return volumes_from
|
||||
|
||||
|
|
@ -988,6 +983,39 @@ def parse_volume_spec(volume_config):
|
|||
|
||||
return VolumeSpec(external, internal, mode)
|
||||
|
||||
|
||||
def build_volume_from(volume_from_spec):
|
||||
volumes_from = []
|
||||
if isinstance(volume_from_spec.source, Service):
|
||||
containers = volume_from_spec.source.containers(stopped=True)
|
||||
if not containers:
|
||||
volumes_from = ["{}:{}".format(volume_from_spec.source.create_container().id, volume_from_spec.mode)]
|
||||
else:
|
||||
volumes_from = ["{}:{}".format(container.id, volume_from_spec.mode) for container in containers]
|
||||
elif isinstance(volume_from_spec.source, Container):
|
||||
volumes_from = ["{}:{}".format(volume_from_spec.source.id, volume_from_spec.mode)]
|
||||
return volumes_from
|
||||
|
||||
|
||||
def parse_volume_from_spec(volume_from_config):
|
||||
parts = volume_from_config.split(':')
|
||||
if len(parts) > 2:
|
||||
raise ConfigError("Volume %s has incorrect format, should be "
|
||||
"external:internal[:mode]" % volume_from_config)
|
||||
|
||||
if len(parts) == 1:
|
||||
source = parts[0]
|
||||
mode = 'rw'
|
||||
else:
|
||||
source, mode = parts
|
||||
|
||||
if mode not in ('rw', 'ro'):
|
||||
raise ConfigError("VolumeFrom %s has invalid mode (%s), should be "
|
||||
"one of: rw, ro." % (volume_from_config, mode))
|
||||
|
||||
return VolumeFromSpec(source, mode)
|
||||
|
||||
|
||||
# Labels
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue