runner: update resilient monitor and move import/export scripts outside recipe
[slapos.git] / slapos / recipe / slaprunner / __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
30 #XXX-Nicolas This recipe has to be deleted as soon as possible
31 #No changes allowed, except full-replacement using buildout
32 class Test(GenericBaseRecipe):
33 def _options(self, options):
34 self.ipv4 = options['ipv4'].strip()
35 self.ipv6 = options['ipv6'].strip()
36 self.proxy_port = options['proxy_port'].strip()
37 self.runner_port = options['runner_port'].strip()
38 self.workdir = options['working-directory'].strip()
39 self.software_directory = options['software-directory'].strip()
40 self.instance_directory = options['instance-directory'].strip()
41 self.partition_amount = options['partition-amount'].strip()
42 self.cloud9_url = options.get('cloud9-url', '').strip()
43 # Set slaprunner access URL
44 options['access-url'] = 'http://[%s]:%s' % (self.ipv6, self.runner_port)
45
46 def install(self):
47 path_list = []
48
49 configuration = dict(
50 software_root=self.software_directory,
51 instance_root=self.instance_directory,
52 master_url='http://%s:%s/' % (self.ipv4, self.proxy_port),
53 computer_id='slaprunner',
54 partition_amount=self.partition_amount,
55 slapgrid_sr=self.options['slapgrid_sr'],
56 slapgrid_cp=self.options['slapgrid_cp'],
57 slapproxy=self.options['slapproxy'],
58 supervisor=self.options['supervisor'],
59 supervisord_config=os.path.join(self.instance_directory, 'etc',
60 'supervisord.conf'),
61 runner_workdir=self.workdir,
62 etc_dir=self.options['etc_dir'],
63 run_dir=self.options['etc_dir'],
64 log_dir=self.workdir,
65 runner_host=self.ipv4,
66 runner_port=self.runner_port,
67 ipv4_address=self.ipv4,
68 ipv6_address=self.ipv6,
69 proxy_host=self.ipv4,
70 proxy_port=self.proxy_port,
71 proxy_database=os.path.join(self.workdir, 'proxy.db'),
72 git=self.options['git-binary'],
73 ssh_client=self.options['ssh_client'],
74 public_key=self.options['public_key'],
75 private_key=self.options['private_key'],
76 cloud9_url=self.cloud9_url
77 )
78
79 config_file = self.createFile(self.options['slapos.cfg'],
80 self.substituteTemplate(self.getTemplateFilename('slapos.cfg.in'),
81 configuration))
82 path_list.append(config_file)
83
84 environment = dict(
85 PATH=os.path.dirname(
86 self.options['git-binary']) + ':' + os.environ['PATH'],
87 GIT_SSH=self.options['ssh_client'],
88 CONFIG_FILE_PATH=config_file
89 )
90 launch_args = [self.options['slaprunnertest'].strip()]
91
92 wrapper = self.createPythonScript(self.options['wrapper'],
93 'slapos.recipe.librecipe.execute.executee',
94 (launch_args, environment)
95 )
96 path_list.append(wrapper)
97
98 return path_list