]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdown/graph.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
7 # graph helper module for ifupdown
12 from collections
import deque
15 except ImportError, e
:
19 """ graph functions to sort and print interface graph """
22 self
.logger
= logging
.getLogger('ifupdown.' +
23 self
.__class
__.__name
__)
26 def topological_sort_graphs_all(cls
, dependency_graphs
, indegrees_arg
):
27 """ runs topological sort on interface list passed as dependency graph
30 **dependency_graphs** (dict): dependency graph with dependency
33 **indegrees_arg** (dict): indegrees array for all interfaces
38 indegrees
= copy
.deepcopy(indegrees_arg
)
39 for ifname
,indegree
in indegrees
.items():
48 dlist
= dependency_graphs
.get(x
)
54 indegrees
[y
] = indegrees
.get(y
) - 1
55 if indegrees
.get(y
) == 0:
60 for ifname
,indegree
in indegrees
.items():
62 raise Exception('cycle found involving iface %s' %ifname
+
63 ' (indegree %d)' %indegree
)
68 def generate_dots(cls
, dependency_graph
, indegrees
):
69 """ spits out interface dependency graph in dot format
72 **dependency_graphs** (dict): dependency graph with dependency
75 **indegrees_arg** (dict): indegrees array for all interfaces
80 for v
in dependency_graph
.keys():
81 graphnodes
[v
] = gvgraph
.newItem(v
)
83 for i
, v
in graphnodes
.items():
84 dlist
= dependency_graph
.get(i
, [])
88 gvgraph
.newLink(v
, graphnodes
.get(d
))