Cleanup some project logic.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2015-09-01 19:54:49 -04:00
parent e801981fed
commit 08ba857807
1 changed files with 26 additions and 24 deletions

View File

@ -87,8 +87,14 @@ class Project(object):
volumes_from = project.get_volumes_from(service_dict) volumes_from = project.get_volumes_from(service_dict)
net = project.get_net(service_dict) net = project.get_net(service_dict)
project.services.append(Service(client=client, project=name, links=links, net=net, project.services.append(
volumes_from=volumes_from, **service_dict)) Service(
client=client,
project=name,
links=links,
net=net,
volumes_from=volumes_from,
**service_dict))
return project return project
@property @property
@ -184,30 +190,26 @@ class Project(object):
return volumes_from return volumes_from
def get_net(self, service_dict): def get_net(self, service_dict):
if 'net' in service_dict: net = service_dict.pop('net', None)
net_name = get_service_name_from_net(service_dict.get('net')) if not net:
return
if net_name: net_name = get_service_name_from_net(net)
try: if not net_name:
net = self.get_service(net_name) return net
except NoSuchService:
try:
net = Container.from_id(self.client, net_name)
except APIError:
raise ConfigurationError(
'Service "%s" is trying to use the network of "%s", '
'which is not the name of a service or container.' % (
service_dict['name'],
net_name))
else:
net = service_dict['net']
del service_dict['net'] try:
return self.get_service(net_name)
else: except NoSuchService:
net = None pass
try:
return net return Container.from_id(self.client, net_name)
except APIError:
raise ConfigurationError(
'Service "%s" is trying to use the network of "%s", '
'which is not the name of a service or container.' % (
service_dict['name'],
net_name))
def start(self, service_names=None, **options): def start(self, service_names=None, **options):
for service in self.get_services(service_names): for service in self.get_services(service_names):