9 def __init__(self, config):
12 def __getattr__(self, method):
16 def __call__(self, *args):
18 sfa_slice_prefix = self.config.SFA_CM_SLICE_PREFIX
19 sfa_slice = sfa_slice_prefix + "_sfacm"
20 python = "/usr/bin/python"
21 vserver_path = "/vservers/%s" % (sfa_slice)
23 path = "%(vserver_path)s/%(script_path)s" % locals()
24 (fd, filename) = tempfile.mkstemp(dir=path)
25 scriptname = script_path + os.sep + filename.split(os.sep)[-1:][0]
26 # define the script to execute
30 s = xmlrpclib.ServerProxy('http://127.0.0.1:812')
31 print s.%(method)s%(args)s""" % locals()
34 # write the script to a temporary file
35 f = open(filename, 'w')
36 f.write(script % locals())
38 # make the file executeable
39 chmod_cmd = "/bin/chmod 775 %(filename)s" % locals()
40 (status, output) = commands.getstatusoutput(chmod_cmd)
42 # execute the commad as a slice with root NM privs
43 cmd = 'su - %(sfa_slice)s -c "%(python)s %(scriptname)s"' % locals()
44 (status, output) = commands.getstatusoutput(cmd)
45 return (status, output)
46 finally: os.unlink(filename)