X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplanetlab%2Fnodemanager.py;h=2e755d9e78d1ffd11792eae2ffb1484d2548d1e1;hb=4a9e6751f9f396f463932133b9d62fc925a99ef6;hp=1671b9d6a4b191a96dbae0b79269fd6817c6f0ec;hpb=c4e713b97658195775b8fd147b8ab9dceb785493;p=sfa.git diff --git a/sfa/planetlab/nodemanager.py b/sfa/planetlab/nodemanager.py index 1671b9d6..2e755d9e 100644 --- a/sfa/planetlab/nodemanager.py +++ b/sfa/planetlab/nodemanager.py @@ -1,7 +1,8 @@ import tempfile -import commands +import subprocess import os + class NodeManager: method = None @@ -12,35 +13,38 @@ 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()) f.close() # make the file executeable chmod_cmd = "/bin/chmod 775 %(filename)s" % locals() - (status, output) = commands.getstatusoutput(chmod_cmd) + (status, output) = subprocess.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) + (status, output) = subprocess.getstatusoutput(cmd) + return (status, output) + finally: + os.unlink(filename)