root / snf-deploy / snfdeploy / fabfile2.py @ 3c3bccab
History | View | Annotate | Download (8.9 kB)
1 |
# Too many lines in module pylint: disable-msg=C0302
|
---|---|
2 |
# Too many arguments (7/5) pylint: disable-msg=R0913
|
3 |
|
4 |
# Copyright (C) 2010, 2011, 2012, 2013 GRNET S.A. All rights reserved.
|
5 |
#
|
6 |
# Redistribution and use in source and binary forms, with or
|
7 |
# without modification, are permitted provided that the following
|
8 |
# conditions are met:
|
9 |
#
|
10 |
# 1. Redistributions of source code must retain the above
|
11 |
# copyright notice, this list of conditions and the following
|
12 |
# disclaimer.
|
13 |
#
|
14 |
# 2. Redistributions in binary form must reproduce the above
|
15 |
# copyright notice, this list of conditions and the following
|
16 |
# disclaimer in the documentation and/or other materials
|
17 |
# provided with the distribution.
|
18 |
#
|
19 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
20 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
22 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A. OR
|
23 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
26 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
27 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
28 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
29 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
# POSSIBILITY OF SUCH DAMAGE.
|
31 |
#
|
32 |
# The views and conclusions contained in the software and
|
33 |
# documentation are those of the authors and should not be
|
34 |
# interpreted as representing official policies, either expressed
|
35 |
# or implied, of GRNET S.A.
|
36 |
|
37 |
"""
|
38 |
Fabric file for snf-deploy
|
39 |
|
40 |
"""
|
41 |
|
42 |
from __future__ import with_statement |
43 |
from fabric.api import hide, env, settings, local, roles, execute |
44 |
from fabric.operations import run, put, get |
45 |
import fabric |
46 |
import re |
47 |
import os |
48 |
import shutil |
49 |
import tempfile |
50 |
import ast |
51 |
from snfdeploy.lib import debug, Conf, Env, disable_color |
52 |
from snfdeploy.utils import * |
53 |
from snfdeploy import massedit |
54 |
from snfdeploy.components import * |
55 |
from snfdeploy import components |
56 |
|
57 |
|
58 |
def setup_env(args, localenv): |
59 |
"""Setup environment"""
|
60 |
print("Loading configuration for synnefo...")
|
61 |
|
62 |
env.env = localenv |
63 |
|
64 |
env.target_node = args.node |
65 |
env.target_component = args.component |
66 |
env.target_method = args.method |
67 |
env.target_role = args.role |
68 |
env.dry_run = args.dry_run |
69 |
env.local = args.autoconf |
70 |
env.key_inject = args.key_inject |
71 |
env.password = env.env.password |
72 |
env.user = env.env.user |
73 |
env.shell = "/bin/bash -c"
|
74 |
env.key_filename = args.ssh_key |
75 |
env.jsonfile = "/tmp/service.json"
|
76 |
env.force = args.force |
77 |
|
78 |
if args.disable_colors:
|
79 |
disable_color() |
80 |
|
81 |
env.roledefs = { |
82 |
"accounts": [env.env.accounts.ip],
|
83 |
"cyclades": [env.env.cyclades.ip],
|
84 |
"pithos": [env.env.pithos.ip],
|
85 |
"cms": [env.env.cms.ip],
|
86 |
"mq": [env.env.mq.ip],
|
87 |
"db": [env.env.db.ip],
|
88 |
"ns": [env.env.ns.ip],
|
89 |
"client": [env.env.client.ip],
|
90 |
"stats": [env.env.stats.ip],
|
91 |
"nfs": [env.env.nfs.ip],
|
92 |
} |
93 |
|
94 |
env.enable_lvm = False
|
95 |
env.enable_drbd = False
|
96 |
if ast.literal_eval(env.env.create_extra_disk) and env.env.extra_disk: |
97 |
env.enable_lvm = True
|
98 |
env.enable_drbd = True
|
99 |
|
100 |
env.roledefs.update({ |
101 |
"ganeti": env.env.cluster_ips,
|
102 |
"master": [env.env.master.ip],
|
103 |
}) |
104 |
|
105 |
|
106 |
#
|
107 |
#
|
108 |
# Those methods retrieve info from existing installation and update env
|
109 |
#
|
110 |
#
|
111 |
@roles("db") |
112 |
def update_env_with_user_info(): |
113 |
user_email = env.env.user_email |
114 |
result = RunComponentMethod(DB, "get_user_info_from_db")
|
115 |
r = re.compile(r"(\d+)[ |]*(\S+)[ |]*(\S+)[ |]*" + user_email, re.M)
|
116 |
match = r.search(result) |
117 |
if env.dry_run:
|
118 |
env.user_id, env.user_auth_token, env.user_uuid = \ |
119 |
("dummy_uid", "dummy_user_auth_token", "dummy_user_uuid") |
120 |
else:
|
121 |
env.user_id, env.user_auth_token, env.user_uuid = match.groups() |
122 |
|
123 |
|
124 |
@roles("accounts") |
125 |
def update_env_with_service_info(service="pithos"): |
126 |
result = RunComponentMethod(Astakos, "get_services")
|
127 |
r = re.compile(r"(\d+)[ ]*%s[ ]*(\S+)" % service, re.M)
|
128 |
match = r.search(result) |
129 |
if env.dry_run:
|
130 |
env.service_id, env.service_token = \ |
131 |
("dummy_service_id", "dummy_service_token") |
132 |
else:
|
133 |
env.service_id, env.service_token = match.groups() |
134 |
|
135 |
|
136 |
@roles("cyclades") |
137 |
def update_env_with_backend_info(): |
138 |
cluster_name = env.env.cluster.fqdn |
139 |
result = RunComponentMethod(Cyclades, "list_backends")
|
140 |
r = re.compile(r"(\d+)[ ]*%s.*" % cluster_name, re.M)
|
141 |
match = r.search(result) |
142 |
if env.dry_run:
|
143 |
env.backend_id = "dummy_backend_id"
|
144 |
else:
|
145 |
env.backend_id, = match.groups() |
146 |
|
147 |
#
|
148 |
#
|
149 |
# Those methods act on components after their basic setup
|
150 |
#
|
151 |
#
|
152 |
@roles("cyclades") |
153 |
def add_ganeti_backend(): |
154 |
RunComponentMethod(Cyclades, "add_backend")
|
155 |
execute(update_env_with_backend_info) |
156 |
RunComponentMethod(Cyclades, "undrain_backend")
|
157 |
|
158 |
|
159 |
@roles("accounts") |
160 |
def add_synnefo_user(): |
161 |
RunComponentMethod(Astakos, "add_user")
|
162 |
|
163 |
|
164 |
@roles("accounts") |
165 |
def activate_user(): |
166 |
execute(update_env_with_user_info) |
167 |
RunComponentMethod(Astakos, "activate_user")
|
168 |
|
169 |
|
170 |
@roles("accounts") |
171 |
def import_service(): |
172 |
f = env.jsonfile |
173 |
PutToComponent(Astakos, f + ".local", f)
|
174 |
RunComponentMethod(Astakos, "import_service")
|
175 |
|
176 |
|
177 |
@roles("ns") |
178 |
def update_ns_for_node(node_info): |
179 |
RunComponentMethod(NS, "update_ns_for_node", node_info)
|
180 |
|
181 |
|
182 |
@roles("nfs") |
183 |
def update_exports_for_node(node_info): |
184 |
RunComponentMethod(NFS, "update_exports", node_info)
|
185 |
|
186 |
|
187 |
@roles("master") |
188 |
def add_ganeti_node(node_info): |
189 |
RunComponentMethod(Master, "add_node", node_info)
|
190 |
|
191 |
|
192 |
@roles("db") |
193 |
def allow_db_access(node_info): |
194 |
RunComponentMethod(DB, "allow_access_in_db", node_info, "all", "trust") |
195 |
|
196 |
|
197 |
@roles("accounts") |
198 |
def set_default_quota(): |
199 |
RunComponentMethod(Astakos, "set_default_quota")
|
200 |
|
201 |
|
202 |
@roles("cyclades") |
203 |
def add_public_networks(): |
204 |
RunComponentMethod(Cyclades, "add_network")
|
205 |
if ast.literal_eval(env.env.testing_vm):
|
206 |
RunComponentMethod(Cyclades, "add_network6")
|
207 |
|
208 |
|
209 |
@roles("client") |
210 |
def add_image(): |
211 |
RunComponentMethod(Kamaki, "fetch_image")
|
212 |
RunComponentMethod(Kamaki, "upload_image")
|
213 |
RunComponentMethod(Kamaki, "register_image")
|
214 |
#
|
215 |
#
|
216 |
# Those methods do the basic setup of a synnefo role
|
217 |
#
|
218 |
#
|
219 |
@roles("ns") |
220 |
def setup_ns_role(): |
221 |
SetupSynnefoRole("ns")
|
222 |
|
223 |
|
224 |
@roles("nfs") |
225 |
def setup_nfs_role(): |
226 |
SetupSynnefoRole("nfs")
|
227 |
|
228 |
|
229 |
@roles("db") |
230 |
def setup_db_role(): |
231 |
SetupSynnefoRole("db")
|
232 |
if ast.literal_eval(env.env.testing_vm):
|
233 |
RunComponentMethod(DB, "make_db_fast")
|
234 |
|
235 |
|
236 |
@roles("mq") |
237 |
def setup_mq_role(): |
238 |
SetupSynnefoRole("mq")
|
239 |
|
240 |
|
241 |
@roles("accounts") |
242 |
def setup_astakos_role(): |
243 |
node_info = get_node_info(env.host) |
244 |
execute(allow_db_access, node_info) |
245 |
SetupSynnefoRole("astakos")
|
246 |
RunComponentMethod(Astakos, "export_service")
|
247 |
f = env.jsonfile |
248 |
GetFromComponent(Astakos, f, f + ".local")
|
249 |
execute(import_service) |
250 |
|
251 |
|
252 |
@roles("pithos") |
253 |
def setup_pithos_role(): |
254 |
node_info = get_node_info(env.host) |
255 |
execute(allow_db_access, node_info) |
256 |
execute(update_env_with_service_info, "pithos")
|
257 |
SetupSynnefoRole("pithos")
|
258 |
RunComponentMethod(Pithos, "export_service")
|
259 |
f = env.jsonfile |
260 |
GetFromComponent(Pithos, f, f + ".local")
|
261 |
execute(import_service) |
262 |
|
263 |
|
264 |
@roles("cyclades") |
265 |
def setup_cyclades_role(): |
266 |
node_info = get_node_info(env.host) |
267 |
execute(allow_db_access, node_info) |
268 |
execute(update_env_with_service_info, "cyclades")
|
269 |
SetupSynnefoRole("cyclades")
|
270 |
RunComponentMethod(Cyclades, "export_service")
|
271 |
f = env.jsonfile |
272 |
GetFromComponent(Cyclades, f, f + ".local")
|
273 |
execute(import_service) |
274 |
|
275 |
|
276 |
@roles("cms") |
277 |
def setup_cms_role(): |
278 |
SetupSynnefoRole("cms")
|
279 |
|
280 |
|
281 |
@roles("ganeti") |
282 |
def setup_ganeti_role(): |
283 |
if not env.host: |
284 |
return
|
285 |
node_info = get_node_info(env.host) |
286 |
execute(update_exports_for_node, node_info) |
287 |
SetupSynnefoRole("ganeti")
|
288 |
execute(add_ganeti_node, node_info) |
289 |
#FIXME: prepare_lvm ????
|
290 |
|
291 |
|
292 |
@roles("master") |
293 |
def setup_master_role(): |
294 |
node_info = get_node_info(env.host) |
295 |
execute(update_exports_for_node, node_info) |
296 |
execute(update_ns_for_node, env.env.cluster) |
297 |
SetupSynnefoRole("master")
|
298 |
|
299 |
|
300 |
@roles("stats") |
301 |
def setup_stats_role(): |
302 |
SetupSynnefoRole("stats")
|
303 |
|
304 |
|
305 |
@roles("client") |
306 |
def setup_client_role(): |
307 |
execute(update_env_with_user_info) |
308 |
SetupSynnefoRole("client")
|
309 |
|
310 |
|
311 |
def setup(): |
312 |
node_info = get_node_info(env.target_node) |
313 |
if not node_info: |
314 |
debug("setup", "Please give a valid node identifier") |
315 |
return
|
316 |
execute(update_ns_for_node, node_info) |
317 |
env.host = env.host_string = node_info.ip |
318 |
if env.target_role:
|
319 |
SetupSynnefoRole(env.target_role) |
320 |
return
|
321 |
if not env.target_component: |
322 |
debug("setup", "Please give a valid Component") |
323 |
return
|
324 |
component_class = getattr(components, env.target_component)
|
325 |
if not env.target_method: |
326 |
debug("setup", "Please give a valid Component method") |
327 |
return
|
328 |
RunComponentMethod(component_class, env.target_method) |