Skip to content

Commit

Permalink
Detect container network mode and blank hostname
Browse files Browse the repository at this point in the history
closes #63
  • Loading branch information
gmt2001 committed Mar 1, 2023
1 parent 9b37d52 commit 66cbd5c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyouroboros/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ def execfile(filepath, myglobals=None, mylocals=None):
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), myglobals, mylocals)

def isContainerNetwork(container):
parts = container.attrs['HostConfig']['NetworkMode'].split(':')
return len(parts) > 1 and parts[0] == 'container'

def set_properties(old, new, self_name=None):
"""Store object for spawning new container in place of the one with outdated image"""
properties = {
'name': self_name if self_name else old.name,
'hostname': old.attrs['Config']['Hostname'],
'hostname': '' if isContainerNetwork(old) else old.attrs['Config']['Hostname'],
'user': old.attrs['Config']['User'],
'detach': True,
'domainname': old.attrs['Config']['Domainname'],
Expand Down

0 comments on commit 66cbd5c

Please sign in to comment.