2 # 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.
7 vsys_config_dir = "/etc/planetlab/vsys-attributes"
10 sliceid = pwd.getpwnam(slicename).pw_uid
12 arglines = map(string.strip, sys.stdin.readlines())
13 command_name = arglines[0]
14 device_names = arglines[1:]
16 print "Validating interface names... ",
17 # Validate interface names
19 for vif in device_names:
21 print "Interface name %s invalid"%(vif)
23 if re.match(r'(tun|tap)%d-\d+' % sliceid, vif ) is None:
24 print "Interface name %s does not match slice id %d."%(vif, sliceid)
28 # The interfaces have been validated. We don't need to validate the executable
29 # path for escape hatches because we are going to use execve.
33 # Close open fds before execve
34 print "Closing file descriptors."
35 for fd in xrange(3, 1023):
41 vserver_command = "/usr/sbin/vserver"
44 args += [command_name]
46 os.system('touch /etc/vservers/%s/spaces/net'%slicename)
49 os.execve(vserver_command, args)
53 os.system('rm /etc/vservers/%s/spaces/net'%slicename)
55 for vif in device_names:
56 os.system('/sbin/ip link set %s netns %d'%(vif, pid))