Slightly cleaned up setParam to match node.py.

This commit is contained in:
Bob Lantz
2012-03-07 23:38:08 -08:00
parent b1f90976a3
commit edf46e9570
+13 -10
View File
@@ -94,27 +94,30 @@ class BasicIntf( object ):
"Return whether interface is up" "Return whether interface is up"
return "UP" in self.ifconfig() return "UP" in self.ifconfig()
# The reason why we configure things in this way is so # The reason why we configure things in this way is so
# That the parameters can be listed and documented in # That the parameters can be listed and documented in
# the config method. # the config method.
# Dealing with subclasses and superclasses is slightly # Dealing with subclasses and superclasses is slightly
# annoying, but at least the information is there! # annoying, but at least the information is there!
def setParam( self, result, method, **param ): def setParam( self, results, method, **param ):
"""Internal method: configure single parameter """Internal method: configure a *single* parameter
result: dict of results to update results: dict of results to update
method: config method method: config method name
param: foo=bar (ignore if bar=None)""" param: arg=value (ignore if value=None)
value may also be list or dict"""
name, value = param.items()[ 0 ] name, value = param.items()[ 0 ]
if value is None: f = getattr( self, method, None )
if not f or value is None:
return return
if type( value ) is list: if type( value ) is list:
result[ name ] = getattr( self, method )( *value ) result = f( *value )
elif type( value ) is dict: elif type( value ) is dict:
result[ name ] = getattr( self, method )( **value ) result = f( **value )
else: else:
result[ name ] = getattr( self, method )( value ) result = f( value )
results[ name ] = result
return result
def config( self, mac=None, ip=None, ifconfig=None, def config( self, mac=None, ip=None, ifconfig=None,
defaultRoute=None, **params): defaultRoute=None, **params):