From 074a6f3e3e0adca556c2be9b7ffd90aa8c9cef26 Mon Sep 17 00:00:00 2001 From: Paul Myjavec Date: Tue, 10 Jun 2014 22:30:27 +1000 Subject: [PATCH] Docker links and required alias If no alias is passed one will now be created for you with the same name as the target link container, as per the documentation --- library/cloud/docker | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/cloud/docker b/library/cloud/docker index 509e5eb955..79c6145bc6 100644 --- a/library/cloud/docker +++ b/library/cloud/docker @@ -380,7 +380,7 @@ class DockerManager: self.links = None if self.module.params.get('links'): - self.links = dict(map(lambda x: x.split(':'), self.module.params.get('links'))) + self.links = self.get_links(self.module.params.get('links')) self.env = None if self.module.params.get('env'): @@ -391,6 +391,22 @@ class DockerManager: self.client = docker.Client(base_url=docker_url.geturl()) + def get_links(self, links): + """ + Parse the links passed, if a link is specified without an alias then just create the alias of the same name as the link + """ + processed_links = {} + + for link in links: + parsed_link = link.split(':', 1) + if(len(parsed_link) == 2): + processed_links[parsed_link[0]] = parsed_link[1] + else: + processed_links[parsed_link[0]] = parsed_link[0] + + return processed_links + + def get_exposed_ports(self, expose_list): """ Parse the ports and protocols (TCP/UDP) to expose in the docker-py `create_container` call from the docker CLI-style syntax. @@ -452,7 +468,6 @@ class DockerManager: return binds - def get_split_image_tag(self, image): if '/' in image: image = image.split('/')[1]