Compare commits

...

8 Commits

Author SHA1 Message Date
Bob Lantz 9cdcc59c28 Check to make sure sudo works without password. 2012-03-13 23:54:12 -07:00
Bob Lantz 68b28201ad Pass code check. 2012-03-13 23:16:36 -07:00
Bob Lantz ebfc4d0d72 Reinstate fixLimits - complain if limits are too small. 2012-03-13 23:15:13 -07:00
Bob Lantz 67b06f3a83 Simplify reading pid from mnexec. 2012-03-13 22:42:49 -07:00
Ed Swierk f510caa0e7 Run commands with sudo so mininet can be directly imported by
an unprivileged Python process
2012-03-13 21:18:51 -07:00
Brandon Heller 99222e70f7 Merge pull request #26 from mininet/devel/install-oneiric
Devel/install oneiric
2012-03-13 15:11:29 -07:00
Bob Lantz 5562e66a2d Ignore build, dist and emacs backup~ files. 2012-03-12 16:14:00 -07:00
Bob Lantz 28f46c8d2d Pass code check. 2012-03-12 16:12:38 -07:00
6 changed files with 50 additions and 26 deletions
+3
View File
@@ -1,3 +1,6 @@
mnexec
*.pyc
*~
mininet.egg-info
build
dist
+1 -1
View File
@@ -53,7 +53,7 @@ disable-msg-cat=IR
#enable-msg=
# Disable the message(s) with the given id(s).
disable-msg=W0704,C0103,W0231,E1102,W0511,W0142,R0902,R0903,R0904,R0913,R0914,R0801
disable=W0704,C0103,W0231,E1102,W0511,W0142,R0902,R0903,R0904,R0913,R0914,R0801,I0011
[REPORTS]
+1 -1
View File
@@ -602,7 +602,7 @@ class MiniEdit( Frame ):
cleanUpScreens()
self.net = None
def xterm( self, ignore=None ):
def xterm( self, _ignore=None ):
"Make an xterm when a button is pressed."
if ( self.selection is None or
self.net is None or
+7 -7
View File
@@ -91,6 +91,7 @@ import re
import select
import signal
from time import sleep
from subprocess import check_output
from mininet.cli import CLI
from mininet.log import info, error, debug, output
@@ -561,13 +562,12 @@ def init():
"Initialize Mininet."
if init.inited:
return
if os.getuid() != 0:
# Note: this script must be run as root
# Perhaps we should do so automatically!
print "*** Mininet must run as root."
exit( 1 )
# If which produces no output, then mnexec is not in the path.
# May want to loosen this to handle mnexec in the current dir.
# Make sure we can sudo without a password
try:
check_output( [ 'sudo', '-n', 'echo' ] )
except:
raise Exception( "Could not run sudo -n echo - check /etc/sudoers" )
# Make sure mnexec is in our path
if not quietRun( 'which mnexec' ):
raise Exception( "Could not find mnexec - check $PATH" )
fixLimits()
+12 -10
View File
@@ -76,12 +76,12 @@ class Node( object ):
opts = '-cdp'
if self.inNamespace:
opts += 'n'
cmd = [ 'mnexec', opts, 'bash', '-m' ]
cmd = [ 'sudo', '-E', 'env', 'PATH=%s' % os.environ['PATH'],
'mnexec', opts, 'bash', '-m', '-p' ]
self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
close_fds=False )
self.stdin = self.shell.stdin
self.stdout = self.shell.stdout
self.pid = self.shell.pid
self.pollOut = select.poll()
self.pollOut.register( self.stdout )
# Maintain mapping between file descriptors and nodes
@@ -102,6 +102,8 @@ class Node( object ):
self.waiting = False
# Stash additional information as desired
self.args = kwargs
# Read pid from mnexec
self.pid = int( self.readline()[ 1: ] )
@classmethod
def fdToNode( cls, fd ):
@@ -116,19 +118,19 @@ class Node( object ):
self.shell = None
# Subshell I/O, commands and control
def read( self, bytes=1024 ):
def read( self, maxbytes=1024 ):
"""Buffered read from node, non-blocking.
bytes: maximum number of bytes to return"""
maxbytes: maximum number of bytes to return"""
count = len( self.readbuf )
if count < bytes:
data = os.read( self.stdout.fileno(), bytes - count )
if count < maxbytes:
data = os.read( self.stdout.fileno(), maxbytes - count )
self.readbuf += data
if bytes >= len( self.readbuf ):
if maxbytes >= len( self.readbuf ):
result = self.readbuf
self.readbuf = ''
else:
result = self.readbuf[ :bytes ]
self.readbuf = self.readbuf[ bytes: ]
result = self.readbuf[ :maxbytes ]
self.readbuf = self.readbuf[ maxbytes: ]
return result
def readline( self ):
@@ -149,7 +151,7 @@ class Node( object ):
def terminate( self ):
"Send kill signal to Node and clean up after it."
os.kill( self.pid, signal.SIGKILL )
quietRun( 'kill ' + str( self.pid ) )
self.cleanup()
def stop( self ):
+26 -7
View File
@@ -1,11 +1,12 @@
"Utility functions for Mininet."
from time import sleep
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
from resource import setrlimit, getrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
import select
from subprocess import call, check_call, Popen, PIPE, STDOUT
import os
from mininet.log import error
from mininet.log import error, warn
# Command execution support
@@ -29,6 +30,7 @@ def quietRun( *cmd ):
cmd = cmd[ 0 ]
if isinstance( cmd, str ):
cmd = cmd.split( ' ' )
cmd = ["sudo", "-E", "env", "PATH=%s" % os.environ["PATH"]] + cmd
popen = Popen( cmd, stdout=PIPE, stderr=STDOUT )
# We can't use Popen.communicate() because it uses
# select(), which can't handle
@@ -136,13 +138,13 @@ def createLink( node1, node2, port1=None, port2=None ):
# IP and Mac address formatting and parsing
def _colonHex( val, bytes ):
def _colonHex( val, count ):
"""Generate colon-hex string.
val: input as unsigned int
bytes: number of bytes to convert
count: number of bytes to convert
returns: chStr colon-hex string"""
pieces = []
for i in range( bytes - 1, -1, -1 ):
for i in range( count - 1, -1, -1 ):
piece = ( ( 0xff << ( i * 8 ) ) & val ) >> ( i * 8 )
pieces.append( '%02x' % piece )
chStr = ':'.join( pieces )
@@ -205,5 +207,22 @@ def makeNumeric( s ):
def fixLimits():
"Fix ridiculously small resource limits."
setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
manyprocs = 8192
manyfiles = 32768
minprocs, maxprocs = getrlimit( RLIMIT_NPROC )
minfiles, maxfiles = getrlimit( RLIMIT_NOFILE )
# Root can raise limits
if os.getuid() == 0:
maxprocs = max( maxprocs, manyprocs )
maxfiles = max( maxfiles, manyfiles )
minprocs = min( manyprocs, maxprocs )
minfiles = min( manyfiles, maxfiles )
setrlimit( RLIMIT_NPROC, ( minprocs, maxprocs ) )
setrlimit( RLIMIT_NOFILE, ( minfiles, maxfiles ) )
nprocs = max( getrlimit( RLIMIT_NPROC ) )
nfiles = max( getrlimit( RLIMIT_NOFILE ) )
# Complain if limits are too low
if nprocs < manyprocs:
warn( '*** Warning: process limit is low:', nprocs, 'procs\n' )
if nfiles < manyfiles:
warn( '*** Warning: open file limit is low:', nfiles, 'files \n' )