Add net['h1'] and for node in net support
thanks to Brian O'Connor for reminder + suggestion closes #114
This commit is contained in:
+12
-2
@@ -91,6 +91,7 @@ import re
|
||||
import select
|
||||
import signal
|
||||
from time import sleep
|
||||
from itertools import chain
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output
|
||||
@@ -216,8 +217,8 @@ class Mininet( object ):
|
||||
self.nameToNode[ name ] = controller_new
|
||||
return controller_new
|
||||
|
||||
# BL: is this better than just using nameToNode[] ?
|
||||
# Should it have a better name?
|
||||
# BL: We now have four ways to look up nodes
|
||||
# This may (should?) be cleaned up in the future.
|
||||
def getNodeByName( self, *args ):
|
||||
"Return node(s) with given name(s)"
|
||||
if len( args ) == 1:
|
||||
@@ -228,6 +229,15 @@ class Mininet( object ):
|
||||
"Convenience alias for getNodeByName"
|
||||
return self.getNodeByName( *args )
|
||||
|
||||
# Even more convenient syntax for node lookup and iteration
|
||||
def __getitem__( self, *args ):
|
||||
"""net [ name ] operator: Return node(s) with given name(s)"""
|
||||
return self.getNodeByName( *args )
|
||||
|
||||
def __iter__( self ):
|
||||
"return iterator over nodes"
|
||||
return chain( self.hosts, self.switches, self.controllers )
|
||||
|
||||
def addLink( self, node1, node2, port1=None, port2=None,
|
||||
cls=None, **params ):
|
||||
""""Add a link from node1 to node2
|
||||
|
||||
Reference in New Issue
Block a user