mirror of https://github.com/docker/compose.git
Extract link names into a function.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
187ad4ce26
commit
db9f577ad6
|
@ -326,7 +326,7 @@ class TopLevelCommand(Command):
|
|||
log.warn(INSECURE_SSL_WARNING)
|
||||
|
||||
if not options['--no-deps']:
|
||||
deps = service.get_linked_names()
|
||||
deps = service.get_linked_service_names()
|
||||
|
||||
if len(deps) > 0:
|
||||
project.up(
|
||||
|
|
|
@ -488,19 +488,22 @@ class Service(object):
|
|||
return {
|
||||
'options': self.options,
|
||||
'image_id': self.image()['Id'],
|
||||
'links': [(service.name, alias) for service, alias in self.links],
|
||||
'links': self.get_link_names(),
|
||||
'net': self.net.id,
|
||||
'volumes_from': self.get_volumes_from_names(),
|
||||
}
|
||||
|
||||
def get_dependency_names(self):
|
||||
net_name = self.net.service_name
|
||||
return (self.get_linked_names() +
|
||||
return (self.get_linked_service_names() +
|
||||
self.get_volumes_from_names() +
|
||||
([net_name] if net_name else []))
|
||||
|
||||
def get_linked_names(self):
|
||||
return [s.name for (s, _) in self.links]
|
||||
def get_linked_service_names(self):
|
||||
return [service.name for (service, _) in self.links]
|
||||
|
||||
def get_link_names(self):
|
||||
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)]
|
||||
|
@ -784,7 +787,7 @@ class Net(object):
|
|||
|
||||
|
||||
class ContainerNet(object):
|
||||
"""A network mode that uses a containers network stack."""
|
||||
"""A network mode that uses a container's network stack."""
|
||||
|
||||
service_name = None
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
|
||||
web = project.get_service('web')
|
||||
net = project.get_service('net')
|
||||
self.assertEqual(web._get_net(), 'container:' + net.containers()[0].id)
|
||||
self.assertEqual(web.net.mode, 'container:' + net.containers()[0].id)
|
||||
|
||||
def test_net_from_container(self):
|
||||
net_container = Container.create(
|
||||
|
@ -138,7 +138,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
project.up()
|
||||
|
||||
web = project.get_service('web')
|
||||
self.assertEqual(web._get_net(), 'container:' + net_container.id)
|
||||
self.assertEqual(web.net.mode, 'container:' + net_container.id)
|
||||
|
||||
def test_start_pause_unpause_stop_kill_remove(self):
|
||||
web = self.create_service('web')
|
||||
|
|
|
@ -22,6 +22,7 @@ from compose.container import Container
|
|||
from compose.service import build_extra_hosts
|
||||
from compose.service import ConfigError
|
||||
from compose.service import ConvergencePlan
|
||||
from compose.service import Net
|
||||
from compose.service import Service
|
||||
|
||||
|
||||
|
@ -707,17 +708,17 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp'])
|
||||
|
||||
def test_network_mode_none(self):
|
||||
service = self.create_service('web', net='none')
|
||||
service = self.create_service('web', net=Net('none'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'none')
|
||||
|
||||
def test_network_mode_bridged(self):
|
||||
service = self.create_service('web', net='bridge')
|
||||
service = self.create_service('web', net=Net('bridge'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'bridge')
|
||||
|
||||
def test_network_mode_host(self):
|
||||
service = self.create_service('web', net='host')
|
||||
service = self.create_service('web', net=Net('host'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'host')
|
||||
|
||||
|
|
Loading…
Reference in New Issue