slaprunner recipe: remove trailing / from master_url.
[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 class Recipe(GenericBaseRecipe):
31
32 def _options(self, options):
33 self.ipv4 = options['ipv4'].strip()
34 self.ipv6 = options['ipv6'].strip()
35 self.proxy_port = options['proxy_port'].strip()
36 self.runner_port = options['runner_port'].strip()
37 self.workdir = options['working-directory'].strip()
38 self.software_directory = options['software-directory'].strip()
39 self.instance_directory = options['instance-directory'].strip()
40 self.partition_amount = options['partition-amount'].strip()
41 self.cloud9_url = options.get('cloud9-url', '').strip()
42 self.log_file = os.path.join(options['log_dir'].strip(), 'slaprunner.log')
43 # Set slaprunner access URL, CLN Beware ipv6 access is made throught nginx
44 options['access-url'] = 'https://[%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['run_dir'],
64 log_dir=self.options['log_dir'],
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 )
89 launch_args = [self.options['slaprunner'].strip(), config_file,
90 '--log_file', self.log_file]
91 if self.optionIsTrue('debug', default=False):
92 launch_args.append('--debug')
93
94 wrapper = self.createPythonScript(self.options['wrapper'],
95 'slapos.recipe.librecipe.execute.executee',
96 (launch_args, environment)
97 )
98 path_list.append(wrapper)
99
100 return path_list
101
102 class Test(GenericBaseRecipe):
103 def _options(self, options):
104 self.ipv4 = options['ipv4'].strip()
105 self.ipv6 = options['ipv6'].strip()
106 self.proxy_port = options['proxy_port'].strip()
107 self.runner_port = options['runner_port'].strip()
108 self.workdir = options['working-directory'].strip()
109 self.software_directory = options['software-directory'].strip()
110 self.instance_directory = options['instance-directory'].strip()
111 self.partition_amount = options['partition-amount'].strip()
112 self.cloud9_url = options.get('cloud9-url', '').strip()
113 # Set slaprunner access URL
114 options['access-url'] = 'http://[%s]:%s' % (self.ipv6, self.runner_port)
115
116 def install(self):
117 path_list = []
118
119 configuration = dict(
120 software_root=self.software_directory,
121 instance_root=self.instance_directory,
122 master_url='http://%s:%s/' % (self.ipv4, self.proxy_port),
123 computer_id='slaprunner',
124 partition_amount=self.partition_amount,
125 slapgrid_sr=self.options['slapgrid_sr'],
126 slapgrid_cp=self.options['slapgrid_cp'],
127 slapproxy=self.options['slapproxy'],
128 supervisor=self.options['supervisor'],
129 supervisord_config=os.path.join(self.instance_directory, 'etc',
130 'supervisord.conf'),
131 runner_workdir=self.workdir,
132 etc_dir=self.options['etc_dir'],
133 run_dir=self.options['etc_dir'],
134 log_dir=self.workdir,
135 runner_host=self.ipv4,
136 runner_port=self.runner_port,
137 ipv4_address=self.ipv4,
138 ipv6_address=self.ipv6,
139 proxy_host=self.ipv4,
140 proxy_port=self.proxy_port,
141 proxy_database=os.path.join(self.workdir, 'proxy.db'),
142 git=self.options['git-binary'],
143 ssh_client=self.options['ssh_client'],
144 public_key=self.options['public_key'],
145 private_key=self.options['private_key'],
146 cloud9_url=self.cloud9_url
147 )
148
149 config_file = self.createFile(self.options['slapos.cfg'],
150 self.substituteTemplate(self.getTemplateFilename('slapos.cfg.in'),
151 configuration))
152 path_list.append(config_file)
153
154 environment = dict(
155 PATH=os.path.dirname(
156 self.options['git-binary']) + ':' + os.environ['PATH'],
157 GIT_SSH=self.options['ssh_client'],
158 CONFIG_FILE_PATH=config_file
159 )
160 launch_args = [self.options['slaprunnertest'].strip()]
161
162 wrapper = self.createPythonScript(self.options['wrapper'],
163 'slapos.recipe.librecipe.execute.executee',
164 (launch_args, environment)
165 )
166 path_list.append(wrapper)
167
168 return path_list