Fix plot() command for newer networkx
Networkx moved graphviz_layout, so we look for it in two different places. Also plot() should be fixed for regular Mininet(), which doesn't have a .servers list.
This commit is contained in:
+10
-4
@@ -27,16 +27,21 @@ class ClusterCLI( CLI ):
|
|||||||
def do_plot( self, _line ):
|
def do_plot( self, _line ):
|
||||||
"Plot topology colored by node placement"
|
"Plot topology colored by node placement"
|
||||||
# Import networkx if needed
|
# Import networkx if needed
|
||||||
global nx, plt
|
global nx, plt, graphviz_layout
|
||||||
if not nx:
|
if not nx:
|
||||||
try:
|
try:
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import networkx
|
import networkx
|
||||||
nx = networkx # satisfy pylint
|
nx = networkx # satisfy pylint
|
||||||
from matplotlib import pyplot
|
from matplotlib import pyplot
|
||||||
plt = pyplot # satisfiy pylint
|
plt = pyplot # satisfy pylint
|
||||||
import pygraphviz
|
import pygraphviz
|
||||||
assert pygraphviz # silence pyflakes
|
assert pygraphviz # silence pyflakes
|
||||||
|
# Networkx moved this around
|
||||||
|
if hasattr( nx, 'graphviz_layout' ):
|
||||||
|
graphviz_layout = nx.graphviz_layout
|
||||||
|
else:
|
||||||
|
graphviz_layout = nx.drawing.nx_agraph.graphviz_layout
|
||||||
# pylint: enable=import-error
|
# pylint: enable=import-error
|
||||||
except ImportError:
|
except ImportError:
|
||||||
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
||||||
@@ -45,7 +50,8 @@ class ClusterCLI( CLI ):
|
|||||||
# Make a networkx Graph
|
# Make a networkx Graph
|
||||||
g = nx.Graph()
|
g = nx.Graph()
|
||||||
mn = self.mn
|
mn = self.mn
|
||||||
servers, hosts, switches = mn.servers, mn.hosts, mn.switches
|
servers = getattr( mn, 'servers', [ 'localhost' ] )
|
||||||
|
hosts, switches = mn.hosts, mn.switches
|
||||||
nodes = hosts + switches
|
nodes = hosts + switches
|
||||||
g.add_nodes_from( nodes )
|
g.add_nodes_from( nodes )
|
||||||
links = [ ( link.intf1.node, link.intf2.node )
|
links = [ ( link.intf1.node, link.intf2.node )
|
||||||
@@ -55,7 +61,7 @@ class ClusterCLI( CLI ):
|
|||||||
# shapes = hlen * [ 's' ] + slen * [ 'o' ]
|
# shapes = hlen * [ 's' ] + slen * [ 'o' ]
|
||||||
color = dict( zip( servers, self.colorsFor( servers ) ) )
|
color = dict( zip( servers, self.colorsFor( servers ) ) )
|
||||||
# Plot it!
|
# Plot it!
|
||||||
pos = nx.graphviz_layout( g )
|
pos = graphviz_layout( g )
|
||||||
opts = { 'ax': None, 'font_weight': 'bold',
|
opts = { 'ax': None, 'font_weight': 'bold',
|
||||||
'width': 2, 'edge_color': 'darkblue' }
|
'width': 2, 'edge_color': 'darkblue' }
|
||||||
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
|
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
|
||||||
|
|||||||
Reference in New Issue
Block a user