1
0
Fork 0

Try to fix Docker Swarm with network attachment

This commit is contained in:
Joao Gilberto Magalhaes 2023-02-26 21:39:07 -06:00
parent 3cc9547388
commit 7dc683b254

View file

@ -164,16 +164,15 @@ class Swarm(ProcessorInterface):
self.parsed_object = {} self.parsed_object = {}
for service in self.client.services.list(): for service in self.client.services.list():
ip_address = None ip_address = None
network_list = []
for endpoint in service.attrs["Endpoint"]["VirtualIPs"]: for endpoint in service.attrs["Endpoint"]["VirtualIPs"]:
if ha_proxy_network_id == endpoint["NetworkID"]: if ha_proxy_network_id == endpoint["NetworkID"]:
ip_address = endpoint["Addr"].split("/")[0] ip_address = endpoint["Addr"].split("/")[0]
break break
network_list.append(endpoint["NetworkID"])
# add the network ha_proxy_network_id to the service object # add the network ha_proxy_network_id to the service object
if ip_address is None: if ip_address is None:
self.client.networks.get(ha_proxy_network_id).connect(service.name) network_attachment = docker.types.NetworkAttachmentConfig(target=ha_proxy_network_id)
service.update(networks = [network_attachment])
continue # skip to the next service to give time to update the network continue # skip to the next service to give time to update the network
self.parsed_object[ip_address] = service.attrs["Spec"]["Labels"] self.parsed_object[ip_address] = service.attrs["Spec"]["Labels"]