Refactor network_mode logic out of Service.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-09-03 13:02:46 -04:00
commit 187ad4ce26
4 changed files with 116 additions and 37 deletions

View file

@ -14,7 +14,10 @@ from .const import LABEL_PROJECT
from .const import LABEL_SERVICE
from .container import Container
from .legacy import check_for_legacy_containers
from .service import ContainerNet
from .service import Net
from .service import Service
from .service import ServiceNet
from .utils import parallel_execute
@ -192,18 +195,18 @@ class Project(object):
def get_net(self, service_dict):
net = service_dict.pop('net', None)
if not net:
return
return Net(None)
net_name = get_service_name_from_net(net)
if not net_name:
return net
return Net(net)
try:
return self.get_service(net_name)
return ServiceNet(self.get_service(net_name))
except NoSuchService:
pass
try:
return Container.from_id(self.client, net_name)
return ContainerNet(Container.from_id(self.client, net_name))
except APIError:
raise ConfigurationError(
'Service "%s" is trying to use the network of "%s", '