type( foo ) is bar -> isinstance( foo, bar )
This commit is contained in:
+2
-2
@@ -160,9 +160,9 @@ class Intf( object ):
|
|||||||
f = getattr( self, method, None )
|
f = getattr( self, method, None )
|
||||||
if not f or value is None:
|
if not f or value is None:
|
||||||
return
|
return
|
||||||
if type( value ) is list:
|
if isinstance( value, list ):
|
||||||
result = f( *value )
|
result = f( *value )
|
||||||
elif type( value ) is dict:
|
elif isinstance( value, dict ):
|
||||||
result = f( **value )
|
result = f( **value )
|
||||||
else:
|
else:
|
||||||
result = f( value )
|
result = f( value )
|
||||||
|
|||||||
+7
-7
@@ -258,7 +258,7 @@ class Node( object ):
|
|||||||
assert not self.waiting
|
assert not self.waiting
|
||||||
printPid = kwargs.get( 'printPid', True )
|
printPid = kwargs.get( 'printPid', True )
|
||||||
# Allow sendCmd( [ list ] )
|
# Allow sendCmd( [ list ] )
|
||||||
if len( args ) == 1 and type( args[ 0 ] ) is list:
|
if len( args ) == 1 and isinstance( args[ 0 ], list ):
|
||||||
cmd = args[ 0 ]
|
cmd = args[ 0 ]
|
||||||
# Allow sendCmd( cmd, arg1, arg2... )
|
# Allow sendCmd( cmd, arg1, arg2... )
|
||||||
elif len( args ) > 0:
|
elif len( args ) > 0:
|
||||||
@@ -352,7 +352,7 @@ class Node( object ):
|
|||||||
[ 'mnexec', '-da', str( self.pid ) ] }
|
[ 'mnexec', '-da', str( self.pid ) ] }
|
||||||
defaults.update( kwargs )
|
defaults.update( kwargs )
|
||||||
if len( args ) == 1:
|
if len( args ) == 1:
|
||||||
if type( args[ 0 ] ) is list:
|
if isinstance( args[ 0 ], list ):
|
||||||
# popen([cmd, arg1, arg2...])
|
# popen([cmd, arg1, arg2...])
|
||||||
cmd = args[ 0 ]
|
cmd = args[ 0 ]
|
||||||
elif isinstance( args[ 0 ], basestring ):
|
elif isinstance( args[ 0 ], basestring ):
|
||||||
@@ -539,9 +539,9 @@ class Node( object ):
|
|||||||
f = getattr( self, method, None )
|
f = getattr( self, method, None )
|
||||||
if not f:
|
if not f:
|
||||||
return
|
return
|
||||||
if type( value ) is list:
|
if isinstance( value, list ):
|
||||||
result = f( *value )
|
result = f( *value )
|
||||||
elif type( value ) is dict:
|
elif isinstance( valude, dict ):
|
||||||
result = f( **value )
|
result = f( **value )
|
||||||
else:
|
else:
|
||||||
result = f( value )
|
result = f( value )
|
||||||
@@ -774,7 +774,7 @@ class CPULimitedHost( Host ):
|
|||||||
"Specify (real) cores that our cgroup can run on"
|
"Specify (real) cores that our cgroup can run on"
|
||||||
if not cores:
|
if not cores:
|
||||||
return
|
return
|
||||||
if type( cores ) is list:
|
if isinstance( cores, list ):
|
||||||
cores = ','.join( [ str( c ) for c in cores ] )
|
cores = ','.join( [ str( c ) for c in cores ] )
|
||||||
self.cgroupSet( resource='cpuset', param='cpus',
|
self.cgroupSet( resource='cpuset', param='cpus',
|
||||||
value=cores )
|
value=cores )
|
||||||
@@ -937,7 +937,7 @@ class UserSwitch( Switch ):
|
|||||||
over tc queuing disciplines. To resolve the conflict,
|
over tc queuing disciplines. To resolve the conflict,
|
||||||
we re-create the user switch's configuration, but as a
|
we re-create the user switch's configuration, but as a
|
||||||
leaf of the TCIntf-created configuration."""
|
leaf of the TCIntf-created configuration."""
|
||||||
if type( intf ) is TCIntf:
|
if isinstance( intf, TCIntf ):
|
||||||
ifspeed = 10000000000 # 10 Gbps
|
ifspeed = 10000000000 # 10 Gbps
|
||||||
minspeed = ifspeed * 0.001
|
minspeed = ifspeed * 0.001
|
||||||
|
|
||||||
@@ -1097,7 +1097,7 @@ class OVSSwitch( Switch ):
|
|||||||
"""Unfortunately OVS and Mininet are fighting
|
"""Unfortunately OVS and Mininet are fighting
|
||||||
over tc queuing disciplines. As a quick hack/
|
over tc queuing disciplines. As a quick hack/
|
||||||
workaround, we clear OVS's and reapply our own."""
|
workaround, we clear OVS's and reapply our own."""
|
||||||
if type( intf ) is TCIntf:
|
if isinstance( intf, TCIntf ):
|
||||||
intf.config( **intf.params )
|
intf.config( **intf.params )
|
||||||
|
|
||||||
def attach( self, intf ):
|
def attach( self, intf ):
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ class MultiGraph( object ):
|
|||||||
entry = self.edge[ dst ][ src ] = self.edge[ src ][ dst ]
|
entry = self.edge[ dst ][ src ] = self.edge[ src ][ dst ]
|
||||||
# If no key, pick next ordinal number
|
# If no key, pick next ordinal number
|
||||||
if key is None:
|
if key is None:
|
||||||
keys = [ k for k in entry.keys() if type( k ) is int ]
|
keys = [ k for k in entry.keys() if isinstance( k, int ) ]
|
||||||
key = max( [ 0 ] + keys ) + 1
|
key = max( [ 0 ] + keys ) + 1
|
||||||
entry[ key ] = attr_dict
|
entry[ key ] = attr_dict
|
||||||
return key
|
return key
|
||||||
|
|||||||
+1
-1
@@ -388,7 +388,7 @@ def sysctlTestAndSet( name, limit ):
|
|||||||
#read limit
|
#read limit
|
||||||
with open( name, 'r' ) as readFile:
|
with open( name, 'r' ) as readFile:
|
||||||
oldLimit = readFile.readline()
|
oldLimit = readFile.readline()
|
||||||
if type( limit ) is int:
|
if isinstance( limit, int ):
|
||||||
#compare integer limits before overriding
|
#compare integer limits before overriding
|
||||||
if int( oldLimit ) < limit:
|
if int( oldLimit ) < limit:
|
||||||
with open( name, 'w' ) as writeFile:
|
with open( name, 'w' ) as writeFile:
|
||||||
|
|||||||
Reference in New Issue
Block a user