From ba2ca68284002e4ca82a5c0e7536b1a6751a7253 Mon Sep 17 00:00:00 2001 From: LeoVerto Date: Thu, 8 Nov 2018 14:59:01 +0100 Subject: [PATCH] Fix error on containerless networks --- docker-net-graph.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docker-net-graph.py b/docker-net-graph.py index 3852f9b..75383f7 100755 --- a/docker-net-graph.py +++ b/docker-net-graph.py @@ -93,16 +93,17 @@ def generate_graph(verbose: bool, file: str): style='filled' ) - for container_id, container in sorted(net['Containers'].items()): - if verbose: - dump_json(container) - print(" * ", container['Name'], container['IPv4Address'], container['IPv6Address']) + if net['Containers']: + for container_id, container in sorted(net['Containers'].items()): + if verbose: + dump_json(container) + print(" * ", container['Name'], container['IPv4Address'], container['IPv6Address']) - container_node_id = 'container_%s' % container_id + container_node_id = 'container_%s' % container_id - container_iface_ref = "%s:%s" % (container_node_id, container['EndpointID']) + container_iface_ref = "%s:%s" % (container_node_id, container['EndpointID']) - g.edge(container_iface_ref, net_node_id+":gw_iface", color=color) + g.edge(container_iface_ref, net_node_id+":gw_iface", color=color) print(g.source) if file: