From 66cbd5cf0a6c086e6d991c8ef20baacc056adbe6 Mon Sep 17 00:00:00 2001 From: gmt2001 Date: Wed, 1 Mar 2023 18:35:41 -0500 Subject: [PATCH] Detect container network mode and blank hostname closes #63 --- pyouroboros/helpers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyouroboros/helpers.py b/pyouroboros/helpers.py index 70f7ba8..287962a 100644 --- a/pyouroboros/helpers.py +++ b/pyouroboros/helpers.py @@ -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'],