removed another bunch of references to geni
[sfa.git] / sfa / util / nodemanager.py
1 import tempfile
2 import commands
3 import os
4
5 class NodeManager:
6
7     method = None
8
9     def __getattr__(self, method):
10         self.method = method
11         return self.__call__
12     
13     def __call__(self, *args):
14         method = self.method
15         ### WARNING -- hardwired name needs to be computed 
16         sfa_slice = "pl_genicw"
17         python = "/usr/bin/python"
18         vserver_path = "/vservers/%s" % (sfa_slice)
19         script_path = "/tmp/"
20         path = "%(vserver_path)s/%(script_path)s" % locals()
21         (fd, filename) = tempfile.mkstemp(dir=path)        
22         scriptname = script_path + os.sep + filename.split(os.sep)[-1:][0]
23         # define the script to execute
24         script = """
25 #!%(python)s
26 import xmlrpclib
27 s = xmlrpclib.ServerProxy('http://127.0.0.1:812')
28 print s.%(method)s%(args)s"""  % locals()
29
30         try:    
31             # write the script to a temporary file
32             f = open(filename, 'w')
33             f.write(script % locals())
34             f.close()
35             # make the file executeable
36             chmod_cmd = "/bin/chmod 775 %(filename)s" % locals()
37             print chmod_cmd
38             (status, output) = commands.getstatusoutput(chmod_cmd)
39
40             # execute the commad as a slice with root NM privs    
41             cmd = 'su - %(sfa_slice)s -c "%(python)s %(scriptname)s"' % locals()
42             print cmd
43             (status, output) = commands.getstatusoutput(cmd)
44             return (status, output)  
45         finally: os.unlink(filename)