Remove obsolete util.custom(), and make custom() a method
This commit is contained in:
@@ -32,7 +32,7 @@ from mininet.nodelib import LinuxBridge
|
|||||||
from mininet.link import Link, TCLink
|
from mininet.link import Link, TCLink
|
||||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||||
from mininet.topolib import TreeTopo, TorusTopo
|
from mininet.topolib import TreeTopo, TorusTopo
|
||||||
from mininet.util import custom, customConstructor
|
from mininet.util import customConstructor
|
||||||
from mininet.util import buildTopo
|
from mininet.util import buildTopo
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@@ -67,8 +67,8 @@ SWITCHES = { 'user': UserSwitch,
|
|||||||
|
|
||||||
HOSTDEF = 'proc'
|
HOSTDEF = 'proc'
|
||||||
HOSTS = { 'proc': Host,
|
HOSTS = { 'proc': Host,
|
||||||
'rt': custom( CPULimitedHost, sched='rt' ),
|
'rt': partial( CPULimitedHost, sched='rt' ),
|
||||||
'cfs': custom( CPULimitedHost, sched='cfs' ) }
|
'cfs': partial( CPULimitedHost, sched='cfs' ) }
|
||||||
|
|
||||||
CONTROLLERDEF = 'default'
|
CONTROLLERDEF = 'default'
|
||||||
CONTROLLERS = { 'ref': Controller,
|
CONTROLLERS = { 'ref': Controller,
|
||||||
@@ -118,32 +118,6 @@ def version( *_args ):
|
|||||||
print "%s" % VERSION
|
print "%s" % VERSION
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def custom( option, opt_str, value, parser, *args, **kwargs ):
|
|
||||||
"""Parse custom file and add params.
|
|
||||||
option: option e.g. --custom
|
|
||||||
opt_str: option string e.g. --custom
|
|
||||||
value: the value the follows the option
|
|
||||||
parser: option parser instance
|
|
||||||
args: empty tuple
|
|
||||||
kwargs: dict that contains { self : MininetRunner reference }"""
|
|
||||||
|
|
||||||
self = kwargs['self']
|
|
||||||
files = []
|
|
||||||
if os.path.isfile( value ):
|
|
||||||
# accept any single file (including those with commas)
|
|
||||||
files.append( value )
|
|
||||||
else:
|
|
||||||
# accept a comma-separated list of filenames
|
|
||||||
files += value.split(',')
|
|
||||||
|
|
||||||
for fileName in files:
|
|
||||||
customs = {}
|
|
||||||
if os.path.isfile( fileName ):
|
|
||||||
execfile( fileName, customs, customs )
|
|
||||||
for name, val in customs.iteritems():
|
|
||||||
self.setCustom( name, val )
|
|
||||||
else:
|
|
||||||
raise Exception( 'could not find custom file: %s' % fileName )
|
|
||||||
|
|
||||||
class MininetRunner( object ):
|
class MininetRunner( object ):
|
||||||
"Build, setup, and run Mininet."
|
"Build, setup, and run Mininet."
|
||||||
@@ -158,6 +132,29 @@ class MininetRunner( object ):
|
|||||||
self.setup()
|
self.setup()
|
||||||
self.begin()
|
self.begin()
|
||||||
|
|
||||||
|
def custom( self, option, opt_str, value, parser ):
|
||||||
|
"""Parse custom file and add params.
|
||||||
|
option: option e.g. --custom
|
||||||
|
opt_str: option string e.g. --custom
|
||||||
|
value: the value the follows the option
|
||||||
|
parser: option parser instance"""
|
||||||
|
files = []
|
||||||
|
if os.path.isfile( value ):
|
||||||
|
# Accept any single file (including those with commas)
|
||||||
|
files.append( value )
|
||||||
|
else:
|
||||||
|
# Accept a comma-separated list of filenames
|
||||||
|
files += value.split(',')
|
||||||
|
|
||||||
|
for fileName in files:
|
||||||
|
customs = {}
|
||||||
|
if os.path.isfile( fileName ):
|
||||||
|
execfile( fileName, customs, customs )
|
||||||
|
for name, val in customs.iteritems():
|
||||||
|
self.setCustom( name, val )
|
||||||
|
else:
|
||||||
|
raise Exception( 'could not find custom file: %s' % fileName )
|
||||||
|
|
||||||
def setCustom( self, name, value ):
|
def setCustom( self, name, value ):
|
||||||
"Set custom parameters for MininetRunner."
|
"Set custom parameters for MininetRunner."
|
||||||
if name in ( 'topos', 'switches', 'hosts', 'controllers' ):
|
if name in ( 'topos', 'switches', 'hosts', 'controllers' ):
|
||||||
@@ -191,9 +188,9 @@ class MininetRunner( object ):
|
|||||||
|
|
||||||
opts.add_option( '--clean', '-c', action='store_true',
|
opts.add_option( '--clean', '-c', action='store_true',
|
||||||
default=False, help='clean and exit' )
|
default=False, help='clean and exit' )
|
||||||
opts.add_option( '--custom', action='callback', callback=custom,
|
opts.add_option( '--custom', action='callback',
|
||||||
type='string', callback_kwargs={ 'self' : self },
|
callback=partial( self.custom, self=self ),
|
||||||
help='read custom classes or params from .py file' )
|
type='string', help='read custom classes or params from .py file(s)' )
|
||||||
opts.add_option( '--test', type='choice', choices=TESTS,
|
opts.add_option( '--test', type='choice', choices=TESTS,
|
||||||
default=TESTS[ 0 ],
|
default=TESTS[ 0 ],
|
||||||
help='|'.join( TESTS ) )
|
help='|'.join( TESTS ) )
|
||||||
|
|||||||
Reference in New Issue
Block a user