Revision 9281719d mininet/cli.py

View differences:

mininet/cli.py
43 43

  
44 44
    def __init__( self, mininet, stdin=sys.stdin, script=None ):
45 45
        self.mn = mininet
46
        # CLI locals for py commands
47
        self.locals = { 'net': mininet }
46 48
        # Attempt to handle input
47 49
        self.stdin = stdin
48 50
        self.inPoller = poll()
......
71 73
        "Don't repeat last command when you hit return."
72 74
        pass
73 75

  
74
    def locals( self ):
76
    def getLocals( self ):
75 77
        "Local variable bindings for py command"
76
        locals = { 'net': self.mn }
77
        locals.update( self.mn )
78
        return locals
78
        self.locals.update( self.mn )
79
        return self.locals
79 80

  
80 81
    # Disable pylint "Unused argument: 'arg's'" messages, as well as
81 82
    # "method could be a function" warning, since each CLI function
......
109 110

  
110 111
    def do_nodes( self, _line ):
111 112
        "List all nodes."
112
        #                                                 self.mn.values()
113
        nodes = ' '.join( [ node.name for node in sorted( self.mn ) ] )
113
        nodes = ' '.join( sorted( self.mn ) )
114 114
        output( 'available nodes are: \n%s\n' % nodes )
115 115

  
116 116
    def do_net( self, _line ):
117 117
        "List network connections."
118
        #                    self.mn.values()
119
        dumpNodeConnections( self.mn )
118
        dumpNodeConnections( self.mn.values() )
120 119

  
121 120
    def do_sh( self, line ):
122 121
        "Run an external shell command"
......
129 128
        """Evaluate a Python expression.
130 129
           Node names may be used, e.g.: py h1.cmd('ls')"""
131 130
        try:
132
            result = eval( line, globals(), self.locals() )
131
            result = eval( line, globals(), self.getLocals() )
133 132
            if not result:
134 133
                return
135 134
            elif isinstance( result, str ):
......
146 145
        """Execute a Python statement.
147 146
            Node names may be used, e.g.: px print h1.cmd('ls')"""
148 147
        try:
149
            exec( line, globals(), self.locals() )
148
            exec( line, globals(), self.getLocals() )
150 149
        except Exception, e:
151 150
            output( str( e ) + '\n' )
152 151

  
......
177 176
            hosts = []
178 177
            err = False
179 178
            for arg in args:
180
                #             self.mn.keys()
181 179
                if arg not in self.mn:
182 180
                    err = True
183 181
                    error( "node '%s' not in network\n" % arg )
......
211 209

  
212 210
    def do_intfs( self, _line ):
213 211
        "List interfaces."
214
        #           self.mn.values()
215
        for node in self.mn:
212
        for node in self.mn.values():
216 213
            output( '%s: %s\n' %
217 214
                    ( node.name, ','.join( node.intfNames() ) ) )
218 215

  
219 216
    def do_dump( self, _line ):
220 217
        "Dump node info."
221
        #           self.mn.values()
222
        for node in self.mn:
218
        for node in self.mn.values():
223 219
            output( '%s\n' % repr( node ) )
224 220

  
225 221
    def do_link( self, line ):
......
239 235
            error( 'usage: %s node1 node2 ...\n' % term )
240 236
        else:
241 237
            for arg in args:
242
                #             self.mn.keys()
243 238
                if arg not in self.mn:
244 239
                    error( "node '%s' not in network\n" % arg )
245 240
                else:

Also available in: Unified diff