Better sorting links names

pull/1/head
Christophe Mehay 8 years ago
parent ef6e4cad38
commit 091e623c70

@ -36,7 +36,6 @@ class DockerLinks(object):
def _get_links(self):
self.all_links = {}
# nb_args = len(args)
# Read hosts file
with open('/etc/hosts') as hosts:
for line in hosts:
@ -48,8 +47,6 @@ class DockerLinks(object):
link_name_env = split[1].upper().replace('-', '_')
link_names = split[1:]
env_var = "{link_name}_NAME".format(link_name=link_name_env)
# if nb_args and link_name not in args:
# continue
# Check if ip is already in dict
if link_ip in self.all_links:
names = self.all_links[link_ip]["names"]
@ -64,8 +61,19 @@ class DockerLinks(object):
}
def _sort_names(self):
def test_split(name):
"Select key found in env"
return bool([key for key in os.environ
if key.startswith(name.upper().replace('-', '_'))])
for _, item in self.all_links.items():
item["names"].sort()
names = [name for name in item["names"] if test_split(name)]
hexa = [name for name in item["names"] if not test_split(name)]
names.sort()
hexa.sort()
item["names"] = names + hexa
def links(self, *args):
"Return dictionnary of links in container"

@ -97,6 +97,9 @@ def test_containers():
if 'test4' in ctn.names:
assert len(ctn.links) == 0
# Test sorted names
int(ctn.names[-1], base=16)
def test_templates():
entry = Entrypoint(conf='configs/base.yml')

Loading…
Cancel
Save