]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdown/graph.py
3 # Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
7 # graph helper module for ifupdown
13 from collections
import deque
17 except ImportError, e
:
22 """ graph functions to sort and print interface graph """
24 logger
= logging
.getLogger('ifupdown.graph')
27 def topological_sort_graphs_all(cls
, dependency_graphs
, indegrees_arg
):
28 """ runs topological sort on interface list passed as dependency graph
31 **dependency_graphs** (dict): dependency graph with dependency
34 **indegrees_arg** (dict): indegrees array for all interfaces
39 indegrees
= copy
.deepcopy(indegrees_arg
)
40 for ifname
,indegree
in indegrees
.items():
49 dlist
= dependency_graphs
.get(x
)
56 indegrees
[y
] = indegrees
.get(y
) - 1
58 cls
.logger
.debug('topological_sort_graphs_all: did not find %s' %y
)
61 if indegrees
.get(y
) == 0:
66 for ifname
,indegree
in indegrees
.items():
68 raise Exception('cycle found involving iface %s' %ifname
+
69 ' (indegree %d)' %indegree
)
74 def generate_dots(cls
, dependency_graph
, indegrees
):
75 """ spits out interface dependency graph in dot format
78 **dependency_graphs** (dict): dependency graph with dependency
81 **indegrees_arg** (dict): indegrees array for all interfaces
86 for v
in dependency_graph
.keys():
87 graphnodes
[v
] = gvgraph
.newItem(v
)
89 for i
, v
in graphnodes
.items():
90 dlist
= dependency_graph
.get(i
, [])
94 gvgraph
.newLink(v
, graphnodes
.get(d
))