X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sfa%2Fplanetlab%2Fnodemanager.py;h=eb00fdcf34f215726ca1e65a13a0b6e0435e1911;hb=04a3f20dc71bf8b3f96b1e3172623aa346a638a7;hp=12e7f22ed36a70a9db0a70f9eeb69e8082f884a8;hpb=c1c136b3042a24604823c6da135308b7c031c234;p=sfa.git diff --git a/sfa/planetlab/nodemanager.py b/sfa/planetlab/nodemanager.py index 12e7f22e..eb00fdcf 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,16 +13,16 @@ 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" 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 @@ -32,7 +33,7 @@ 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()) @@ -41,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)