Revision 18aab5b7 examples/clustercli.py

View differences:

examples/clustercli.py
5 5
from mininet.cli import CLI
6 6
from mininet.log import output, error
7 7

  
8
# pylint: disable=global-statement
8 9
nx, graphviz_layout, plt = None, None, None  # Will be imported on demand
9 10

  
10 11

  
......
23 24
        colors = colors[ 0 : slen ]
24 25
        return colors
25 26

  
26
    def do_plot( self, line ):
27
    def do_plot( self, _line ):
27 28
        "Plot topology colored by node placement"
28 29
        # Import networkx if needed
29 30
        global nx, plt
30 31
        if not nx:
31 32
            try:
32
                import networkx as nx
33
                import matplotlib.pyplot as plt
33
                import networkx
34
                nx = networkx  # satisfy pylint
35
                from matplotlib import pyplot
36
                plt = pyplot   # satisfiy pylint
34 37
                import pygraphviz
35 38
                assert pygraphviz  # silence pyflakes
36
            except:
39
            except ImportError:
37 40
                error( 'plot requires networkx, matplotlib and pygraphviz - '
38 41
                       'please install them and try again\n' )
39 42
                return
......
53 56
        pos = nx.graphviz_layout( g )
54 57
        opts = { 'ax': None, 'font_weight': 'bold',
55 58
		 'width': 2, 'edge_color': 'darkblue' }
56
        hcolors = [ color[ getattr( h, 'server', 'localhost' ) ] for h in hosts ]
57
        scolors = [ color[ getattr( s, 'server', 'localhost' ) ] for s in switches ]
58
        nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800, label='host',
59
                          node_color=hcolors, node_shape='s', **opts )
59
        hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
60
                    for h in hosts ]
61
        scolors = [ color[ getattr( s, 'server', 'localhost' ) ]
62
                    for s in switches ]
63
        nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800,
64
                          label='host', node_color=hcolors, node_shape='s',
65
                          **opts )
60 66
        nx.draw_networkx( g, pos=pos, nodelist=switches, node_size=1000,
61 67
                          node_color=scolors, node_shape='o', **opts )
62 68
        # Get rid of axes, add title, and show
......
68 74
        plt.title( 'Node Placement', fontweight='bold' )
69 75
        plt.show()
70 76

  
71
    def do_status( self, line ):
77
    def do_status( self, _line ):
72 78
        "Report on node shell status"
73 79
        nodes = self.mn.hosts + self.mn.switches
74 80
        for node in nodes:
......
83 89
            output( 'All nodes are still running.\n' )
84 90

  
85 91

  
86
    def do_placement( self, line ):
92
    def do_placement( self, _line ):
87 93
        "Describe node placement"
88 94
        mn = self.mn
89 95
        nodes = mn.hosts + mn.switches + mn.controllers

Also available in: Unified diff