[4775] | 1 | import os,XDR,shutil |
---|
| 2 | |
---|
| 3 | MAIN_DIRECTORY_NAME = "C3Sm_projects" |
---|
| 4 | |
---|
| 5 | class unix_curie(XDR.Plugin): |
---|
| 6 | |
---|
| 7 | def __init__(self,typePlugin): |
---|
| 8 | XDR.Plugin.__init__(self, typePlugin) |
---|
| 9 | |
---|
| 10 | print "Using curie plugin" |
---|
| 11 | try : |
---|
| 12 | self.login = XDR.getValue("login","unix_curie",self.type+"_plugins","config") |
---|
| 13 | self.machinecea = XDR.getValue("machinecea","unix_curie",self.type+"_plugins","config") |
---|
| 14 | self.nbprocs = XDR.getValue("nbprocs","unix_curie",self.type+"_plugins","config") |
---|
| 15 | self.timelimit = XDR.getValue("timelimit","unix_curie",self.type+"_plugins","config") |
---|
| 16 | self.distantDirectory = XDR.getValue("distantdir","unix_curie",self.type+"_plugins","config") |
---|
| 17 | except XDRnoNodeException: |
---|
| 18 | XDR.error("Some values are missing in the configuration of plugin unix_curie") |
---|
| 19 | |
---|
| 20 | if self.machinecea == "curie": |
---|
| 21 | self.machine = "curie-ccrt.ccc.cea.fr" |
---|
| 22 | if self.machinecea == "airain": |
---|
| 23 | self.machine = "airain.ccc.cea.fr" |
---|
| 24 | |
---|
| 25 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+MAIN_DIRECTORY_NAME+""" ] ; then mkdir """+MAIN_DIRECTORY_NAME+""" ; fi" """ |
---|
| 26 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
| 27 | |
---|
| 28 | self.distantDirectory = os.path.join(self.distantDirectory,MAIN_DIRECTORY_NAME) |
---|
| 29 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+XDR.getValue("name","project","meta")+""" ] ; then mkdir """+XDR.getValue("name","project","meta")+""" ; fi" """ |
---|
| 30 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
| 31 | |
---|
| 32 | self.distantDirectory = os.path.join(self.distantDirectory,XDR.getValue("name","project","meta")) |
---|
| 33 | |
---|
| 34 | def sendDirectory(self,directory): |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | local_directory = os.path.abspath(directory) |
---|
| 38 | directory_basename = os.path.basename(local_directory) |
---|
| 39 | |
---|
| 40 | if os.path.exists(local_directory): |
---|
| 41 | pass |
---|
| 42 | else: |
---|
| 43 | raise Exception("Error : "+directory+" doesn't exist") |
---|
| 44 | |
---|
| 45 | print "scp -r "+local_directory+" "+self.login+"@"+self.machine+":"+self.distantDirectory + "/" |
---|
| 46 | XDR.execute("scp -r "+local_directory+" "+self.login+"@"+self.machine+":"+self.distantDirectory + "/") |
---|
| 47 | print "done" |
---|
| 48 | |
---|
| 49 | def executeDistantCommand(self,command,execDirectory,flags=[]): |
---|
| 50 | |
---|
| 51 | # Creating batch file |
---|
| 52 | batchContent = """#!/bin/bash |
---|
| 53 | #MSUB -r """+XDR.getValue("name","project","meta")+""" |
---|
| 54 | #MSUB -n """+self.nbprocs+""" |
---|
| 55 | #MSUB -T """+self.timelimit+""" |
---|
| 56 | #MSUB -q standard |
---|
| 57 | #MSUB -o %I.o |
---|
| 58 | #MSUB -e %I.e |
---|
| 59 | |
---|
| 60 | source /etc/profile.d/modules.sh |
---|
| 61 | |
---|
| 62 | """ |
---|
| 63 | if "mpi" in flags: |
---|
| 64 | batchContent +="" |
---|
| 65 | |
---|
| 66 | if ("hdf185" in flags) or ("hdf5" in flags): |
---|
| 67 | batchContent += "module load hdf5/1.8.5\n" |
---|
| 68 | |
---|
| 69 | batchContent += """cd """+os.path.join(self.distantDirectory,execDirectory)+"\n" |
---|
| 70 | |
---|
| 71 | if "nompirun" in flags: |
---|
| 72 | batchContent+=command+"\n" |
---|
| 73 | else: |
---|
| 74 | batchContent+="mpirun "+command+"\n" |
---|
| 75 | |
---|
| 76 | batchFile = open("batch_C3Sm_CCRT",'w') |
---|
| 77 | batchFile.write(batchContent) |
---|
| 78 | batchFile.close() |
---|
| 79 | |
---|
| 80 | XDR.execute("scp -r batch_C3Sm_CCRT "+self.login+"@"+self.machine+":"+self.distantDirectory + "/" + execDirectory + "/") |
---|
| 81 | |
---|
| 82 | sshCommand = """cd """+os.path.join(self.distantDirectory,execDirectory)+"""; ccc_msub batch_C3Sm_CCRT""" |
---|
| 83 | |
---|
| 84 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | def retrieveDirectory(self,directory): |
---|
| 89 | |
---|
| 90 | local_directory = os.path.abspath(directory) |
---|
| 91 | dist_directory = os.path.basename(local_directory) |
---|
| 92 | # Retrieve Directory |
---|
| 93 | shutil.rmtree(local_directory) |
---|
| 94 | scpCommand = "scp -r "+self.login+"@"+self.machine+":"+self.distantDirectory+"/"+dist_directory+" "+os.path.dirname(local_directory) |
---|
| 95 | |
---|
| 96 | XDR.execute(scpCommand) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | def removeDirectory(self,directory): |
---|
| 100 | if directory == "*": |
---|
| 101 | sshCommand = """bash -c "cd """+os.path.join(self.distantDirectory,"..")+"""; if [ -d """+self.distantDirectory+""" ] ; then rm -r """+self.distantDirectory+""" ; fi" |
---|
| 102 | """ |
---|
| 103 | else: |
---|
| 104 | sshCommand = "rm -r "+os.path.join(self.distantDirectory,directory) |
---|
| 105 | |
---|
| 106 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
| 107 | |
---|