def mountDirs( self, dirs ): "Mount a list of directories" for dir_ in dirs: mountpoint = self.root + dir_ #print mountpoint errFail( 'mount -B %s %s' % ( dir_, mountpoint ) )
def mountPrivateDirs(self): "Create and bind mount private dirs" for dir in self.privateDirs: privateDir = self.private + dir errFail('mkdir -p ' + privateDir) mountPoint = self.root + dir errFail('mount -B %s %s' % (privateDir, mountPoint))
def mountPrivateDirs( self ): "Create and bind mount private dirs" for dir_ in self.privateDirs: privateDir = self.private + dir_ errFail( 'mkdir -p ' + privateDir ) mountPoint = self.root + dir_ errFail( 'mount -B %s %s' % ( privateDir, mountPoint) )
def cleanup(self): """Clean up, then unmount bind mounts unmount: actually unmount bind mounts?""" # Wait for process to actually terminate self.shell.wait() Host.cleanup(self) if self.unmount: self.unmountBindMounts() errFail('rmdir ' + self.root)
def cleanup( self ): """Clean up, then unmount bind mounts unmount: actually unmount bind mounts?""" # Wait for process to actually terminate self.shell.wait() Host.cleanup( self ) if self.unmount: self.unmountBindMounts() errFail( 'rmdir ' + self.root )
def setCPUs(self, cores, mems=0): "Specify (real) cores that our cgroup can run on" if type(cores) is list: cores = ','.join([str(c) for c in cores]) self.cgroupSet(resource='cpuset', param='cpus', value=cores) # Memory placement is probably not relevant, but we # must specify it anyway self.cgroupSet(resource='cpuset', param='mems', value=mems) # We have to do this here after we've specified # cpus and mems errFail('cgclassify -g cpuset:/%s %s' % (self.name, self.pid))
def setCPUs(self, cores, mems=0): "Specify (real) cores that our cgroup can run on" if type(cores) is list: cores = ",".join([str(c) for c in cores]) self.cgroupSet(resource="cpuset", param="cpus", value=cores) # Memory placement is probably not relevant, but we # must specify it anyway self.cgroupSet(resource="cpuset", param="mems", value=mems) # We have to do this here after we've specified # cpus and mems errFail("cgclassify -g cpuset:/%s %s" % (self.name, self.pid))
def set_sysctl_variable(var, value): """ Use Mininet command execution to set and verify sysctl variables. :param var: sysctl var name, e.g. 'net.mptcp.mptcp_enabled' :param value: variable value, e.g. '1' :return: """ errFail(['sysctl', '-w', '{0}={1}'.format(var, value)]) out, err, ret = errFail(['sysctl', '-n', var]) debug('type {} and value "{}"\n'.format(type(out), out.strip())) out = out.replace('\n', '') if type(value) is bool and bool(out) != value or type( value) is not bool and out != str(value): raise Exception( "sysctl Fail: setting {} failed, should be {} is {}".format( var, value, out))
def __init__( self, name, sched='cfs', **kwargs ): Host.__init__( self, name, **kwargs ) # Initialize class if necessary if not CPULimitedHost.inited: CPULimitedHost.init() # Create a cgroup and move shell into it self.cgroup = 'cpu,cpuacct,cpuset:/' + self.name errFail( 'cgcreate -g ' + self.cgroup ) # We don't add ourselves to a cpuset because you must # specify the cpu and memory placement first errFail( 'cgclassify -g cpu,cpuacct:/%s %s' % ( self.name, self.pid ) ) # BL: Setting the correct period/quota is tricky, particularly # for RT. RT allows very small quotas, but the overhead # seems to be high. CFS has a mininimum quota of 1 ms, but # still does better with larger period values. self.period_us = kwargs.get( 'period_us', 100000 ) self.sched = sched self.rtprio = 20
def __init__(self, name, sched='cfs', **kwargs): """Initailized Resource Limited Host Class""" Host.__init__(self, name, **kwargs) # Initialize class if necessary if not RSLimitedHost.inited: RSLimitedHost.init() self.cgroup = 'cpu,cpuacct,cpuset,memory,blkio:/' + self.name errFail('cgcreate -g ' + self.cgroup) errFail('cgclassify -g cpu,cpuacct,memory,blkio:/%s %s' % (self.name, self.pid)) self.period_us = kwargs.get('period_us', 100000) self.sched = sched if sched == 'rt': self.checkRtGroupSched() self.rtprio = 20
def mountPoints(): "Return list of mounted file systems" mtab, _err, _ret = errFail('cat /proc/mounts') lines = mtab.split('\n') mounts = [] for line in lines: if not line: continue fields = line.split(' ') mount = fields[1] mounts.append(mount) return mounts
def mountPoints(): "Return list of mounted file systems" mtab, _err, _ret = errFail( 'cat /proc/mounts' ) lines = mtab.split( '\n' ) mounts = [] for line in lines: if not line: continue fields = line.split( ' ') mount = fields[ 1 ] mounts.append( mount ) return mounts
def createBindMounts(self): """Create a chroot directory structure, with self.privateDirs as private dirs""" errFail('mkdir -p ' + self.rundir) unmountAll(self.rundir) # Create /root and /private directories self.root = self.rundir + '/root' self.private = self.rundir + '/private' errFail('mkdir -p ' + self.root) errFail('mkdir -p ' + self.private) # Recursively mount / in private doort # note we'll remount /sys and /proc later errFail('mount -B / ' + self.root) self.mountDirs(self.remounts) self.mountPrivateDirs()
def createBindMounts( self ): """Create a chroot directory structure, with self.privateDirs as private dirs""" errFail( 'mkdir -p '+ self.rundir ) unmountAll( self.rundir ) # Create /root and /private directories self.root = self.rundir + '/root' self.private = self.rundir + '/private' errFail( 'mkdir -p ' + self.root ) errFail( 'mkdir -p ' + self.private ) # Recursively mount / in private doort # note we'll remount /sys and /proc later errFail( 'mount -B / ' + self.root ) self.mountDirs( self.remounts ) self.mountPrivateDirs()
def mountDirs(self, dirs): "Mount a list of directories" for dir in dirs: mountpoint = self.root + dir errFail('mount -B %s %s' % (dir, mountpoint))
def get_system_available_congestioncontrol_algos(): out, err, ret = errFail( ['sysctl', '-n', 'net.ipv4.tcp_available_congestion_control']) return out.strip().split()