X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplanetlab%2Fnodemanager.py;h=db8bc0ffc960a15822e32e771af6509940373721;hb=31cc4fa991896f000abb106916662923f37bc3a6;hp=1671b9d6a4b191a96dbae0b79269fd6817c6f0ec;hpb=0f90da7f05fbe3d07e56790c10f6ecc877b33754;p=sfa.git diff --git a/sfa/planetlab/nodemanager.py b/sfa/planetlab/nodemanager.py index 1671b9d6..db8bc0ff 100644 --- a/sfa/planetlab/nodemanager.py +++ b/sfa/planetlab/nodemanager.py @@ -2,6 +2,7 @@ import tempfile import commands import os + class NodeManager: method = None @@ -12,25 +13,27 @@ class NodeManager: def __getattr__(self, method): self.method = method return self.__call__ - + def __call__(self, *args): method = self.method - sfa_slice_prefix = self.config.SFA_CM_SLICE_PREFIX + sfa_slice_prefix = self.config.SFA_CM_SLICE_PREFIX sfa_slice = sfa_slice_prefix + "_sfacm" - python = "/usr/bin/python" + python = "/usr/bin/python2" vserver_path = "/vservers/%s" % (sfa_slice) script_path = "/tmp/" path = "%(vserver_path)s/%(script_path)s" % locals() - (fd, filename) = tempfile.mkstemp(dir=path) + (fd, filename) = tempfile.mkstemp(dir=path) scriptname = script_path + os.sep + filename.split(os.sep)[-1:][0] # define the script to execute + # when providing support for python3 wrt xmlrpclib + # looks safer to keep things as-is script = """ #!%(python)s import xmlrpclib s = xmlrpclib.ServerProxy('http://127.0.0.1:812') print s.%(method)s%(args)s""" % locals() - try: + try: # write the script to a temporary file f = open(filename, 'w') f.write(script % locals()) @@ -39,8 +42,9 @@ print s.%(method)s%(args)s""" % locals() chmod_cmd = "/bin/chmod 775 %(filename)s" % locals() (status, output) = commands.getstatusoutput(chmod_cmd) - # execute the commad as a slice with root NM privs + # execute the commad as a slice with root NM privs cmd = 'su - %(sfa_slice)s -c "%(python)s %(scriptname)s"' % locals() (status, output) = commands.getstatusoutput(cmd) - return (status, output) - finally: os.unlink(filename) + return (status, output) + finally: + os.unlink(filename)