ignore docker networks without 'IPAM' attr

This commit is contained in:
clore 2024-03-29 23:46:55 +00:00
parent 90eae3ed7f
commit be211eefea
1 changed files with 20 additions and 16 deletions

View File

@ -137,22 +137,26 @@ def get_docker_networks():
# Iterate through each network to gather details # Iterate through each network to gather details
for network in networks: for network in networks:
network_details = { try:
'Name': network.name, network_details = {
'ID': network.id, 'Name': network.name,
'Driver': network.attrs["Driver"], 'ID': network.id,
'Scope': network.attrs["Scope"], 'Driver': network.attrs["Driver"],
'IPAM': [] 'Scope': network.attrs["Scope"],
} 'IPAM': []
}
# IPAM Config might have multiple configurations. Gather them.
ipam_configs = network.attrs.get('IPAM', {}).get('Config', []) # IPAM Config might have multiple configurations. Gather them.
for config in ipam_configs: ipam_configs = network.attrs.get('IPAM', {}).get('Config', [])
subnet = config.get('Subnet', 'Not specified') if type(ipam_configs) == list:
gateway = config.get('Gateway', 'Not specified') for config in ipam_configs:
network_details['IPAM'].append({'Subnet': subnet, 'Gateway': gateway}) subnet = config.get('Subnet', 'Not specified')
gateway = config.get('Gateway', 'Not specified')
networks_list.append(network_details) network_details['IPAM'].append({'Subnet': subnet, 'Gateway': gateway})
networks_list.append(network_details)
except Exception as e:
pass
return networks_list return networks_list
except Exception as e: except Exception as e: