Revision 1fdcd676 mininet/cli.py

View differences:

mininet/cli.py
47 47

  
48 48
    def __init__( self, mininet ):
49 49
        self.mn = mininet
50
        self.nodelist = self.mn.hosts + self.mn.switches + self.mn.controllers
50
        self.nodelist = self.mn.controllers + self.mn.switches + self.mn.hosts
51 51
        self.nodemap = {} # map names to Node objects
52 52
        for node in self.nodelist:
53 53
            self.nodemap[ node.name ] = node
......
69 69
                   '\n'
70 70
                   'The interpreter automatically substitutes IP '
71 71
                   'addresses\n'
72
                   'for node names when a node is the first arg, so command'
72
                   'for node names when a node is the first arg, so commands'
73 73
                   ' like\n'
74
                   '  mininet> h0 ping -c1 h1\n'
74
                   ' mininet> h0 ping -c1 h1\n'
75 75
                   'should work.\n'
76 76
                   '\n'
77 77
                   'Interactive commands are not really supported yet,\n'
......
90 90
        "List network connections."
91 91
        for switch in self.mn.switches:
92 92
            info( '%s <->', switch.name )
93
            for intf in switch.intfs:
93
            for intf in switch.intfs.values():
94 94
                name = switch.connection[ intf ][ 1 ]
95 95
                info( ' %s' % name )
96 96
            info( '\n' )
......
99 99
        "Run an external shell command"
100 100
        call( args, shell=True )
101 101

  
102
    # do_py() needs to catch any exception during eval()
103
    # pylint: disable-msg=W0703
104

  
105
    def do_py( self, args ):
106
        """Evaluate a Python expression.
107
           Node names may be used, e.g.: h1.cmd('ls')"""
108
        try:
109
            result = eval( args, globals(), self.nodemap )
110
            if not result:
111
                return
112
            elif isinstance( result, str ):
113
                info( result + '\n' )
114
            else:
115
                info( repr( result ) + '\n' )
116
        except Exception, e:
117
            info( str( e ) + '\n' )
118

  
119
    # pylint: enable-msg=W0703
120

  
102 121
    def do_pingall( self, args ):
103 122
        "Ping between all hosts."
104 123
        self.mn.pingAll()
......
119 138
    def do_intfs( self, args ):
120 139
        "List interfaces."
121 140
        for node in self.nodelist:
122
            info( '%s: %s\n' % ( node.name, ' '.join( node.intfs ) ) )
141
            info( '%s: %s\n' %
142
                ( node.name, ' '.join( sorted( node.intfs.values() ) ) ) )
123 143

  
124 144
    def do_dump( self, args ):
125 145
        "Dump node info."

Also available in: Unified diff