10 def __init__(self, config):
13 def __getattr__(self, method):
17 def __call__(self, *args):
19 sfa_slice_prefix = self.config.SFA_CM_SLICE_PREFIX
20 sfa_slice = sfa_slice_prefix + "_sfacm"
21 python = "/usr/bin/python"
22 vserver_path = "/vservers/%s" % (sfa_slice)
24 path = "%(vserver_path)s/%(script_path)s" % locals()
25 (fd, filename) = tempfile.mkstemp(dir=path)
26 scriptname = script_path + os.sep + filename.split(os.sep)[-1:][0]
27 # define the script to execute
28 # when providing support for python3 wrt xmlrpclib
29 # looks safer to keep things as-is
33 s = xmlrpclib.ServerProxy('http://127.0.0.1:812')
34 print s.%(method)s%(args)s""" % locals()
37 # write the script to a temporary file
38 f = open(filename, 'w')
39 f.write(script % locals())
41 # make the file executeable
42 chmod_cmd = "/bin/chmod 775 %(filename)s" % locals()
43 (status, output) = commands.getstatusoutput(chmod_cmd)
45 # execute the commad as a slice with root NM privs
46 cmd = 'su - %(sfa_slice)s -c "%(python)s %(scriptname)s"' % locals()
47 (status, output) = commands.getstatusoutput(cmd)
48 return (status, output)