Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.core
Commits
63de3e29
Commit
63de3e29
authored
Oct 01, 2018
by
Samuel GAIST
Browse files
[dock][Host] Add function to retrieve ip address of container
parent
0562c77d
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/core/dock.py
View file @
63de3e29
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment