From: Sapan Bhatia Date: Fri, 18 Dec 2009 22:03:53 +0000 (+0000) Subject: Run with devices lets you isolate a given device in your slice. It is not complete X-Git-Tag: vsys-scripts-0.95-13~6 X-Git-Url: http://git.onelab.eu/?p=vsys-scripts.git;a=commitdiff_plain;h=6c5bb6c96be87e487e8dfa5ed0fa6a47f0412a58 Run with devices lets you isolate a given device in your slice. It is not complete yet. --- diff --git a/exec/run_with_devices.pl b/exec/run_with_devices.pl new file mode 100644 index 0000000..17132c4 --- /dev/null +++ b/exec/run_with_devices.pl @@ -0,0 +1,49 @@ +#!/usr/bin/python -u +# All vsys scripts should use STDOUT in unbuferred mode, or else sometimes your output will get bufferred and you will not see it till the buffer gets flushed. + +import sys +import os + +vsys_config_dir = "/etc/planetlab/vsys-attributes" + +slicename=sys.argv[1] +sliceid = pwd.getpwnam(slicename).pw_uid + +arglines = map(string.strip, sys.stdin.readlines()) +command_name = arglines[0] +device_names = arglines[1:] + +print "Validating interface names... ", +# Validate interface names + +for vif in device_names: + if len(vif)>16: + print "Interface name %s invalid"%(vif) + sys.exit(1) + if re.match(r'(tun|tap)%d-\d+' % sliceid, vif ) is None: + print "Interface name %s does not match slice id %d."%(vif, sliceid) + sys.exit(1) + print "[OK]" + +# The interfaces have been validated. We don't need to validate the executable +# path for escape hatches because we are going to use execve. + +pid = os.fork() +if (pid): + # Close open fds before execve + print "Closing file descriptors." + for fd in xrange(3, 1023): + try: + os.close(fd) + except OSError: + pass + # Execute command + vserver_command = "/usr/sbin/vserver" + args = [slicename] + args += ['exec'] + args += [command_name] + os.execve(vserver_command, args) +else: + for vif in device_names: + os.system('/sbin/ip link set %s netns %d'%(vif, pid)) +