BonjourGrid: Resolv hostname bug when deploy condor project
[slapos.git] / slapos / recipe / bonjourgrid / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27 from slapos.recipe.librecipe import GenericBaseRecipe
28 import os
29 import subprocess
30 import pwd
31 import signal
32 import zc.buildout
33
34 class Recipe(GenericBaseRecipe):
35 """Deploy a fully operational BonjourGrid Master architecture."""
36
37
38 def install(self):
39 path_list = []
40 condor_wrapper = self.options['condor-wrapper'].strip()
41 boinc_wrapper = self.options['boinc-wrapper'].strip()
42 startCondor = startBoinc = False
43 condor_wrapper_list = []
44 boinc_wrapper_list = []
45 for file in os.listdir(condor_wrapper):
46 condor_wrapper_list.append(os.path.join(condor_wrapper, file))
47 for file in os.listdir(boinc_wrapper):
48 boinc_wrapper_list.append(os.path.join(boinc_wrapper, file))
49
50 type = self.options['type'].strip()
51 if type == "condor":
52 startCondor = True
53 project = self.options['condor_host'].strip()
54 if type == "boinc":
55 project = self.options['url-boinc'].strip()
56 startBoinc = True
57
58 #Generate BOINC/Condor launcher script
59 grid_wrapper = self.options['boinc_condor_wrapper'].strip()
60 parameters = dict(startCondor=startCondor, startBoinc=startBoinc,
61 bg_base=self.options['work_dir'].strip(),
62 condor_wrapper_list=condor_wrapper_list,
63 boinc_wrapper_list=boinc_wrapper_list)
64 bonjourGrid_wrapper = self.createPythonScript(grid_wrapper,
65 '%s.configure.launchScript' % __name__,
66 parameters
67 )
68 path_list.append(bonjourGrid_wrapper)
69
70 #Generate wrapper for BonjourGrid Master
71 bonjourgrid_master = self.options['master_script'].strip()
72 python = self.options['python-bin'].strip()
73 bg_wrapper = self.options['wrapper'].strip()
74 log = self.options['log_file'].strip()
75 pid_file = self.options['pid_file'].strip()
76 wrapper = self.createPythonScript(bg_wrapper,
77 'slapos.recipe.librecipe.execute.execute',
78 ([python, bonjourgrid_master, '--log_file', log,
79 '--pid_file', pid_file,
80 '--master_wrapper', grid_wrapper,
81 '--directory', self.options['work_dir'].strip(),
82 '--server', self.options['redis-url'].strip(),
83 '--port', self.options['redis-port'].strip(),
84 '--num_workers', self.options['nworkers'].strip(),
85 ])
86 )
87 path_list.append(wrapper)
88
89
90 #generate Computer information file
91 config_info_file = os.path.join(self.options['work_dir'].strip(),
92 'machineinfo.sh')
93 config_info = self.createFile(config_info_file,
94 self.substituteTemplate(self.getTemplateFilename('machineinfo.sh.in'),
95 dict(ip_address=self.options['ipv6'].strip(),
96 project=project,
97 middleware=type)))
98 os.chmod(config_info_file, 0744)
99 path_list.append(config_info)
100
101 update = install
102
103 class Client(GenericBaseRecipe):
104
105 def install(self):
106 path_list = []
107 boinc_script = self.options['boinc_script'].strip()
108 condor_script = self.options['condor_script'].strip()
109
110 #Generate wrapper for BonjourGrid Worker
111 bonjourgrid_client = self.options['client_script'].strip()
112 python = self.options['python-bin'].strip()
113 bg_wrapper = self.options['wrapper'].strip()
114 log = self.options['log_file'].strip()
115 pid_file = self.options['pid_file'].strip()
116 wrapper = self.createPythonScript(bg_wrapper,
117 'slapos.recipe.librecipe.execute.execute',
118 ([python, bonjourgrid_client, '--log_file', log,
119 '--pid_file', pid_file,
120 '--boinc_wrapper', boinc_script,
121 '--condor_wrapper', condor_script,
122 '--directory', self.options['work_dir'].strip(),
123 '--install_directory', self.options['install_dir'].strip(),
124 '--server', self.options['redis-url'].strip(),
125 '--port', self.options['redis-port'].strip(),
126 ])
127 )
128 path_list.append(wrapper)
129
130 #generate BOINC and Condor configure script for bonjourgrid
131 boinc_wrapper = self.createPythonScript(boinc_script,
132 '%s.boinc.runBoinc' % __name__,
133 dict(ipv6=self.options['ipv6'].strip(),
134 email=self.options['email'].strip(),
135 boinc_wrapper=self.options['boinc_wrapper'].strip(),
136 boinc_cmd=self.options['boinc_cmd'].strip(),
137 boinc_rpc_port=self.options['boinc_rpc_port'],
138 boinc_install_dir=self.options['boinc_install_dir'].strip(),
139 boinc_passwd=self.options['boinc_passwd'].strip(),
140 account_name=self.options['account_name'].strip(),
141 account_passwd=self.options['account_passwd'].strip(),
142 )
143 )
144 path_list.append(boinc_wrapper)
145 condor_wrapper = self.createPythonScript(condor_script,
146 '%s.condor.runCondor' % __name__,
147 dict(ipv6=self.options['ipv6'].strip(),
148 condor_bin=self.options['condor_bin'].strip(),
149 condor_sbin=self.options['condor_sbin'].strip(),
150 condor_wrapper=self.options['condor_wrapper'].strip(),
151 condor_config=self.options['condor_config'].strip(),
152 condor_config_local=self.options['condor_config_local'].strip(),
153 )
154 )
155 path_list.append(condor_wrapper)
156