Skip to content
Snippets Groups Projects
Commit bcfb3009 authored by Brandon Heller's avatar Brandon Heller
Browse files

small refactor: put function to ensure root in util

Two benefits:
- One place to change if in the future, a more granular method of
  root access is used (like the BigSwitch patch).
- Makes this reusable by stuff like examples/baresshd.py that use
  the low-level Mininet API.
parent 8a1264e2
No related branches found
No related tags found
No related merge requests found
......@@ -96,7 +96,7 @@
from mininet.log import info, error, debug, output
from mininet.node import Host, OVSKernelSwitch, Controller
from mininet.link import Link, Intf
from mininet.util import quietRun, fixLimits, numCores
from mininet.util import quietRun, fixLimits, numCores, ensureRoot
from mininet.util import macColonHex, ipStr, ipParse, netParse, ipAdd
from mininet.term import cleanUpScreens, makeTerms
......@@ -571,12 +571,7 @@ def init( cls ):
"Initialize Mininet"
if cls.inited:
return
if os.getuid() != 0:
# Note: this script must be run as root
# Probably we should only sudo when we need
# to as per Big Switch's patch
print "*** Mininet must run as root."
exit( 1 )
ensureRoot()
fixLimits()
cls.inited = True
......
......@@ -9,6 +9,7 @@
import re
from fcntl import fcntl, F_GETFL, F_SETFL
from os import O_NONBLOCK
import os
# Command execution support
......@@ -456,3 +457,13 @@ def buildTopo( topos, topoStr ):
if topo not in topos:
raise Exception( 'Invalid topo name %s' % topo )
return topos[ topo ]( *args, **kwargs )
def ensureRoot():
"""Ensure that we are running as root.
Probably we should only sudo when needed as per Big Switch's patch.
"""
if os.getuid() != 0:
print "*** Mininet must run as root."
exit( 1 )
return
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment