source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/library/DATA/pluginscripts/cerfacs_corail_ssh.py @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 5.7 KB
Line 
1import os
2import shutil
3import XDR
4
5DISTANT_UNIX_DIRECTORY = "C3Sm_projects"
6
7class cerfacs_corail_ssh(XDR.Plugin):
8    def __init__(self,typePlugin):
9        XDR.Plugin.__init__(self, typePlugin)
10       
11        print "Using corail plugin, check in terminal if password is asked"
12       
13        self.login = self.getPluginParam("login")
14        self.machine = "corail"
15        self.nbprocs = self.getPluginParam("nbprocs")
16        self.jobname = self.getPluginParam("jobname").replace(" ","_")
17        self.dir2send = []
18        self.distantDirectory = self.getPluginParam("directory")
19       
20       
21       
22       
23        # create the DISTANT_UNIX_DIRECTORY on the distant machine
24        sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+DISTANT_UNIX_DIRECTORY+""" ] ; then mkdir """+DISTANT_UNIX_DIRECTORY+""" ; fi" """
25        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
26       
27        self.distantDirectory = os.path.join(self.distantDirectory,DISTANT_UNIX_DIRECTORY)
28       
29        # then create the project_name folder if needed
30        project_name = XDR.getValue("name","project","meta")
31        sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+project_name+""" ] ; then mkdir """+project_name+""" ; fi" """   
32        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
33       
34        self.distantDirectory = os.path.join(self.distantDirectory,project_name)
35   
36   
37    # Applications supported
38    @XDR.supported_applications(['avsp52','avbp621','avtp2'])
39    def executeDistantCommand(self,command,execDirectory,appli, flags=[]):       
40       
41        execDir_abspath = os.path.join(self.distantDirectory,execDirectory)
42        print "Running executeDistantCommand "+command+" in "+execDirectory+" for appli"+appli
43       
44        ########
45        # INITS
46        ########
47        command_exe = command
48        local_directory = os.getcwd()
49        project_name = XDR.getValue("name","project","meta")
50
51        # Creating batch file
52        batchContent = "#!/bin/bash \n"
53        batchContent += "#PBS -N C3Sm\n"
54        batchContent += "#PBS -j oe\n"
55        batchContent += "#PBS -l select=" + self.getPluginParam("nbprocs")+"\n"
56        batchContent += "#PBS -l walltime=06:00:00 \n"
57        batchContent += "cat $PBS_NODEFILE \n"
58        batchContent += "nb_cpu=$(wc -l < $PBS_NODEFILE)\n"
59        batchContent += "cd $PBS_O_WORKDIR\n"
60        batchContent += "source /usr/local/bin/intelmpi.sh\n"
61               
62############################################################################
63############################################################################
64############################################################################
65                   
66        ########
67        # AVSP #
68        ########
69        if appli == "avsp52":
70            if command == "-c3sm_auto_avsp_exe-":
71                command_exe = "/usr/local/bin/python /home/rolex/AVSP/avsp53/quiet3.py &> ./quiet.out"
72                avsp_command = "mpirun -np "+self.nbprocs+ " /home/rolex/AVSP/avsp53/AVSP_V5.3.CORAIL"
73                XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_avsp_exe-",avsp_command)
74                anozzle_command = "/home/rolex/AVSP/avsp53/Anozzle_CORAIL.exe"
75                XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_anozzle_exe-",anozzle_command)
76                   
77        ########
78        # AVBP #
79        ########
80        if appli == "avbp621":
81            batchContent+="export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH\n"
82            if command == "-c3sm_auto_avbp_exe-":
83                command_exe = "mpirun -np $nb_cpu /home/rolex/AVBP_V6.X/AVBP_D6.2.1/AVBP_V6.2.1_beta.CORAIL > avbp_log.txt"
84               
85        ########
86        # AVTP #
87        ########
88        if appli == "avtp2":
89            if command == "-c3sm_auto_avtp_exe-":
90                command_exe = "mpirun -np $nb_cpu /home/rolex/AVTP/avtp2/AVTP_V2.X.CORAIL > avtp_log.txt"
91               
92############################################################################
93############################################################################
94############################################################################
95
96        if command_exe.startswith("-c3sm_auto_"):
97            XDR.error("command was not understood: "+command_exe )
98        batchContent +=command_exe
99       
100        batchFile = open(os.path.join(XDR.getCurrentRun(), "batch_C3Sm_CORAIL"), 'w')
101        batchFile.write(batchContent)
102        batchFile.close()
103
104        # create a zip archive of the directories list
105        print "Final composition of c3sm_archive:"
106        print self.dir2send
107       
108        XDR.ssh_send(self.machine,self.login, self.distantDirectory, self.dir2send, options="")   
109       
110        sshCommand = "cd {0}; /opt/pbs/default/bin/qsub batch_C3Sm_CORAIL".format(execDir_abspath)
111        XDR.ssh(self.machine,self.login, sshCommand, options="")
112       
113 
114    def retrieveDirectory(self,directory):
115        local_directory = os.path.abspath(directory)
116        dist_directory = os.path.basename(local_directory)
117        XDR.ssh_retrieve(self.machine, self.login, self.distantDirectory+"/"+dist_directory, local_directory )
118
119    def removeDirectory(self,directory):
120        if directory == "*":
121            sshCommand = """bash -c "cd """+self.distantDirectory+"/.. "+"""; if [ -d """+self.distantDirectory+""" ] ; then rm -r """+self.distantDirectory+""" ; fi"
122            """
123        else:
124            sshCommand = "rm -rf "+self.distantDirectory+"/"+directory
125           
126        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
127   
128    def getRunsState(self):
129        pass
Note: See TracBrowser for help on using the repository browser.