Commit 63de3e29 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[dock][Host] Add function to retrieve ip address of container

parent 0562c77d
......@@ -546,6 +546,25 @@ class Host(object):
return status, output
def get_ipaddress(self, container):
""" Returns the ip address of the given container"""
cmd = [
'docker',
'inspect',
'--format',
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
container.id
]
(status, stdout, stderr) = self._exec(cmd)
if status != 0:
logger.error("Failed to retrieve the ip address of the container, reason:\n\n%s", stderr)
return None
return stdout.replace('\n', '')
def _exec(self, command, timeout=None):
process_stdout = tempfile.NamedTemporaryFile()
process_stderr = tempfile.NamedTemporaryFile()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment