Skip to content

Commit

Permalink
Fix network id and name discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Sep 26, 2024
1 parent 20fa9d9 commit e84ed0c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nginx_proxy/WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ def learn_yourself(self):
raise Exception()
self.container = self.client.containers.get(hostname)
self.id=self.container.id
self.networks = [a for a in self.container.attrs["NetworkSettings"]["Networks"].keys()]
self.networks = {self.client.networks.get(a).id: a for a in self.networks}
networks = [a for a in self.container.attrs["NetworkSettings"]["Networks"].keys()]
for network in networks:
net_detail=self.client.networks.get(a)
self.networks[net_detail.id]=self.networks[net_detail.name]
self.networks[net_detail.name]=self.networks[net_detail.id]
except (KeyboardInterrupt, SystemExit) as e:
raise e
except Exception as e:
Expand All @@ -88,7 +91,7 @@ def learn_yourself(self):
file=sys.stderr)
print("Falling back to default network", file=sys.stderr)
network = self.client.networks.get("frontend")
self.networks[network.id] = network.id
self.networks[network.id] = "frontend"

def _register_container(self, container: DockerContainer):
"""
Expand Down Expand Up @@ -159,7 +162,9 @@ def disconnect(self, network, container, scope):
print("Nginx Proxy removed from network ",self.networks[network])
print("Connected Networks:",self.networks)
# it's weird that the disconnect log is sent twice. this this check is necessary
rev_id=self.networks[network]
del self.networks[network]
del self.networks[rev_id]
self.rescan_and_reload()
elif container in self.containers and network in self.networks:
if not self.update_container(container):
Expand All @@ -169,7 +174,9 @@ def disconnect(self, network, container, scope):
def connect(self, network, container, scope):
if self.id is not None and container == self.id:
if network not in self.networks:
self.networks[network] = self.client.networks.get(network).name
new_network=self.client.networks.get(network)
self.networks[new_network.id] = new_network.name
self.networks[new_network.name] = new_network.id
self.rescan_and_reload()
elif network in self.networks:
self.update_container(container)
Expand Down

0 comments on commit e84ed0c

Please sign in to comment.