Revision bd558875 mininet/net.py

View differences:

mininet/net.py
91 91
import select
92 92
import signal
93 93
from time import sleep
94
from itertools import chain
94 95

  
95 96
from mininet.cli import CLI
96 97
from mininet.log import info, error, debug, output
......
216 217
            self.nameToNode[ name ] = controller_new
217 218
        return controller_new
218 219

  
219
    # BL: is this better than just using nameToNode[] ?
220
    # Should it have a better name?
220
    # BL: We now have four ways to look up nodes
221
    # This may (should?) be cleaned up in the future.
221 222
    def getNodeByName( self, *args ):
222 223
        "Return node(s) with given name(s)"
223 224
        if len( args ) == 1:
......
228 229
        "Convenience alias for getNodeByName"
229 230
        return self.getNodeByName( *args )
230 231

  
232
    # Even more convenient syntax for node lookup and iteration
233
    def __getitem__( self, *args ):
234
        """net [ name ] operator: Return node(s) with given name(s)"""
235
        return self.getNodeByName( *args )
236

  
237
    def __iter__( self ):
238
        "return iterator over nodes"
239
        return chain( self.hosts, self.switches, self.controllers )
240

  
231 241
    def addLink( self, node1, node2, port1=None, port2=None,
232 242
                 cls=None, **params ):
233 243
        """"Add a link from node1 to node2

Also available in: Unified diff