root / snf-deploy / fabfile.py @ 2a73a699
History | View | Annotate | Download (39.2 kB)
1 |
from __future__ import with_statement |
---|---|
2 |
from fabric.api import * |
3 |
from fabric.contrib.console import confirm |
4 |
from random import choice |
5 |
from fabric.operations import run, put |
6 |
import re |
7 |
import shutil, os |
8 |
from functools import wraps |
9 |
import imp |
10 |
import ConfigParser |
11 |
import sys |
12 |
import tempfile |
13 |
import ast |
14 |
from snfdeploy.lib import * |
15 |
from snfdeploy import massedit |
16 |
|
17 |
|
18 |
def setup_env(confdir="conf", packages="packages", |
19 |
templates="files", cluster_name="ganeti1", autoconf=False, disable_colors=False, key_inject=False): |
20 |
print("Loading configuration for synnefo...")
|
21 |
print(" * Using config files under %s..." % confdir)
|
22 |
print(" * Using %s and %s for packages and templates accordingly..." % (packages, templates))
|
23 |
|
24 |
autoconf = ast.literal_eval(autoconf) |
25 |
disable_colors = ast.literal_eval(disable_colors) |
26 |
env.key_inject = ast.literal_eval(key_inject) |
27 |
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf) |
28 |
env.env = Env(conf) |
29 |
|
30 |
env.local = autoconf |
31 |
env.password = env.env.password |
32 |
env.user = env.env.user |
33 |
env.shell = "/bin/bash -c"
|
34 |
|
35 |
if disable_colors:
|
36 |
disable_color() |
37 |
|
38 |
if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]: |
39 |
env.cms_pass = True
|
40 |
else:
|
41 |
env.cms_pass = False
|
42 |
|
43 |
if env.env.accounts.hostname in [env.env.cyclades.hostname, env.env.pithos.hostname]: |
44 |
env.csrf_disable = True
|
45 |
else:
|
46 |
env.csrf_disable = False
|
47 |
|
48 |
|
49 |
env.roledefs = { |
50 |
"nodes": env.env.ips,
|
51 |
"ips": env.env.ips,
|
52 |
"accounts": [env.env.accounts.ip],
|
53 |
"cyclades": [env.env.cyclades.ip],
|
54 |
"pithos": [env.env.pithos.ip],
|
55 |
"cms": [env.env.cms.ip],
|
56 |
"mq": [env.env.mq.ip],
|
57 |
"db": [env.env.db.ip],
|
58 |
"ns": [env.env.ns.ip],
|
59 |
"client": [env.env.client.ip],
|
60 |
"router": [env.env.router.ip],
|
61 |
} |
62 |
|
63 |
env.enable_lvm = False
|
64 |
env.enable_drbd = False
|
65 |
if ast.literal_eval(env.env.create_extra_disk) and env.env.extra_disk: |
66 |
env.enable_lvm = True
|
67 |
env.enable_drbd = True
|
68 |
|
69 |
env.roledefs.update({ |
70 |
"ganeti": env.env.cluster_ips,
|
71 |
"master": [env.env.master.ip],
|
72 |
}) |
73 |
|
74 |
|
75 |
def install_package(package): |
76 |
debug(env.host, " * Installing package %s..." % package)
|
77 |
APT_GET = "export DEBIAN_FRONTEND=noninteractive ;apt-get install -y --force-yes "
|
78 |
|
79 |
host_info = env.env.ips_info[env.host] |
80 |
env.env.update_packages(host_info.os) |
81 |
if ast.literal_eval(env.env.use_local_packages):
|
82 |
with settings(warn_only=True): |
83 |
deb = local("ls %s/%s*%s_all.deb" % (env.env.packages, package, host_info.os))
|
84 |
if deb:
|
85 |
debug(env.host, " * Package %s found in %s..." % (package, env.env.packages))
|
86 |
put(deb, "/tmp/")
|
87 |
try_run("dpkg -i /tmp/%s || " % os.path.basename(deb) + APT_GET + "-f") |
88 |
try_run("rm /tmp/%s" % os.path.basename(deb))
|
89 |
return
|
90 |
|
91 |
info = getattr(env.env, package)
|
92 |
if info in ["squeeze-backports", "squeeze", "stable", "testing", "unstable", "wheezy"]: |
93 |
APT_GET += " -t %s %s " % (info, package)
|
94 |
elif info:
|
95 |
APT_GET += " %s=%s " % (package, info)
|
96 |
else:
|
97 |
APT_GET += package |
98 |
|
99 |
try_run(APT_GET) |
100 |
|
101 |
return
|
102 |
|
103 |
|
104 |
@roles("ns") |
105 |
def update_ns_for_ganeti(): |
106 |
debug(env.host, "Updating name server entries for backend %s..." % env.env.cluster.fqdn)
|
107 |
update_arecord(env.env.cluster) |
108 |
update_ptrrecord(env.env.cluster) |
109 |
try_run("/etc/init.d/bind9 restart")
|
110 |
|
111 |
|
112 |
@roles("ns") |
113 |
def update_ns_for_node(node): |
114 |
info = env.env.nodes_info.get(node) |
115 |
update_arecord(info) |
116 |
update_ptrrecord(info) |
117 |
try_run("/etc/init.d/bind9 restart")
|
118 |
|
119 |
|
120 |
@roles("ns") |
121 |
def update_arecord(host): |
122 |
filename = "/etc/bind/zones/" + env.env.domain
|
123 |
cmd = """
|
124 |
echo '{0}' >> {1}
|
125 |
""".format(host.arecord, filename)
|
126 |
try_run(cmd) |
127 |
|
128 |
|
129 |
@roles("ns") |
130 |
def update_cnamerecord(host): |
131 |
filename = "/etc/bind/zones/" + env.env.domain
|
132 |
cmd = """
|
133 |
echo '{0}' >> {1}
|
134 |
""".format(host.cnamerecord, filename)
|
135 |
try_run(cmd) |
136 |
|
137 |
|
138 |
@roles("ns") |
139 |
def update_ptrrecord(host): |
140 |
filename = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
|
141 |
cmd = """
|
142 |
echo '{0}' >> {1}
|
143 |
""".format(host.ptrrecord, filename)
|
144 |
try_run(cmd) |
145 |
|
146 |
@roles("nodes") |
147 |
def apt_get_update(): |
148 |
debug(env.host, "apt-get update....")
|
149 |
try_run("apt-get update")
|
150 |
|
151 |
@roles("ns") |
152 |
def setup_ns(): |
153 |
debug(env.host, "Setting up name server..")
|
154 |
#WARNING: this should be remove after we are done
|
155 |
# because gevent does pick randomly nameservers and google does
|
156 |
# not know our setup!!!!!
|
157 |
apt_get_update() |
158 |
install_package("bind9")
|
159 |
tmpl = "/etc/bind/named.conf.local"
|
160 |
replace = { |
161 |
"domain": env.env.domain,
|
162 |
} |
163 |
custom = customize_settings_from_tmpl(tmpl, replace) |
164 |
put(custom, tmpl) |
165 |
|
166 |
try_run("mkdir -p /etc/bind/zones")
|
167 |
tmpl = "/etc/bind/zones/example.com"
|
168 |
replace = { |
169 |
"domain": env.env.domain,
|
170 |
"ns_node_ip": env.env.ns.ip,
|
171 |
} |
172 |
custom = customize_settings_from_tmpl(tmpl, replace) |
173 |
remote = "/etc/bind/zones/" + env.env.domain
|
174 |
put(custom, remote) |
175 |
|
176 |
try_run("mkdir -p /etc/bind/rev")
|
177 |
tmpl = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
|
178 |
replace = { |
179 |
"domain": env.env.domain,
|
180 |
} |
181 |
custom = customize_settings_from_tmpl(tmpl, replace) |
182 |
put(custom, tmpl) |
183 |
|
184 |
tmpl = "/etc/bind/named.conf.options"
|
185 |
replace = { |
186 |
"NODE_IPS": ";".join(env.env.ips), |
187 |
} |
188 |
custom = customize_settings_from_tmpl(tmpl, replace) |
189 |
put(custom, tmpl, mode=0644)
|
190 |
|
191 |
for role, info in env.env.roles.iteritems(): |
192 |
if role == "ns": |
193 |
continue
|
194 |
update_cnamerecord(info) |
195 |
for node, info in env.env.nodes_info.iteritems(): |
196 |
update_arecord(info) |
197 |
update_ptrrecord(info) |
198 |
|
199 |
try_run("/etc/init.d/bind9 restart")
|
200 |
|
201 |
|
202 |
@roles("nodes") |
203 |
def check_dhcp(): |
204 |
debug(env.host, "Checking IPs for synnefo..")
|
205 |
for n, info in env.env.nodes_info.iteritems(): |
206 |
try_run("ping -c 1 " + info.ip, True) |
207 |
|
208 |
@roles("nodes") |
209 |
def check_dns(): |
210 |
debug(env.host, "Checking fqdns for synnefo..")
|
211 |
for n, info in env.env.nodes_info.iteritems(): |
212 |
try_run("ping -c 1 " + info.fqdn, True) |
213 |
|
214 |
for n, info in env.env.roles.iteritems(): |
215 |
try_run("ping -c 1 " + info.fqdn, True) |
216 |
|
217 |
@roles("nodes") |
218 |
def check_connectivity(): |
219 |
debug(env.host, "Checking internet connectivity..")
|
220 |
try_run("ping -c 1 www.google.com", True) |
221 |
|
222 |
|
223 |
@roles("nodes") |
224 |
def check_ssh(): |
225 |
debug(env.host, "Checking password-less ssh..")
|
226 |
for n, info in env.env.nodes_info.iteritems(): |
227 |
try_run("ssh " + info.fqdn + " date", True) |
228 |
|
229 |
|
230 |
@roles("ips") |
231 |
def add_keys(): |
232 |
if not env.key_inject: |
233 |
debug(env.host, "Skipping ssh keys injection..")
|
234 |
return
|
235 |
else:
|
236 |
debug(env.host, "Adding rsa/dsa keys..")
|
237 |
try_run("mkdir -p /root/.ssh")
|
238 |
cmd = """
|
239 |
for f in $(ls /root/.ssh/*); do
|
240 |
cp $f $f.bak
|
241 |
done
|
242 |
"""
|
243 |
try_run(cmd) |
244 |
files = ["authorized_keys", "id_dsa", "id_dsa.pub", |
245 |
"id_rsa", "id_rsa.pub"] |
246 |
for f in files: |
247 |
tmpl = "/root/.ssh/" + f
|
248 |
replace = {} |
249 |
custom = customize_settings_from_tmpl(tmpl, replace) |
250 |
put(custom, tmpl, mode=0600)
|
251 |
|
252 |
cmd = """
|
253 |
if [ -e /root/.ssh/authorized_keys.bak ]; then
|
254 |
cat /root/.ssh/authorized_keys.bak >> /root/.ssh/authorized_keys
|
255 |
fi
|
256 |
"""
|
257 |
debug(env.host, "Updating exising authorized keys..")
|
258 |
try_run(cmd) |
259 |
|
260 |
@roles("ips") |
261 |
def setup_resolv_conf(): |
262 |
debug(env.host, "Tweak /etc/resolv.conf...")
|
263 |
try_run("/etc/init.d/network-manager stop")
|
264 |
tmpl = "/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate"
|
265 |
replace = {} |
266 |
custom = customize_settings_from_tmpl(tmpl, replace) |
267 |
put(custom, tmpl, mode=0644)
|
268 |
try_run("cp /etc/resolv.conf /etc/resolv.conf.bak")
|
269 |
tmpl = "/etc/resolv.conf"
|
270 |
replace = { |
271 |
"domain": env.env.domain,
|
272 |
"ns_node_ip": env.env.ns.ip,
|
273 |
} |
274 |
custom = customize_settings_from_tmpl(tmpl, replace) |
275 |
try:
|
276 |
put(custom, tmpl) |
277 |
except:
|
278 |
pass
|
279 |
try_run("chattr +i /etc/resolv.conf")
|
280 |
|
281 |
|
282 |
@roles("ips") |
283 |
def setup_hosts(): |
284 |
debug(env.host, "Tweaking /etc/hosts and ssh_config files...")
|
285 |
try_run("echo StrictHostKeyChecking no >> /etc/ssh/ssh_config")
|
286 |
cmd = "sed -i 's/^127.*$/127.0.0.1 localhost/g' /etc/hosts "
|
287 |
try_run(cmd) |
288 |
host_info = env.env.ips_info[env.host] |
289 |
cmd = "hostname %s" % host_info.hostname
|
290 |
try_run(cmd) |
291 |
cmd = "echo %s > /etc/hostname" % host_info.hostname
|
292 |
try_run(cmd) |
293 |
|
294 |
|
295 |
def try_run(cmd, abort=False): |
296 |
try:
|
297 |
if env.local:
|
298 |
return local(cmd, capture=True) |
299 |
else:
|
300 |
return run(cmd)
|
301 |
except:
|
302 |
debug(env.host, "WARNING: command failed. Continuing anyway...")
|
303 |
if abort:
|
304 |
raise
|
305 |
|
306 |
def create_bridges(): |
307 |
debug(env.host, " * Creating bridges...")
|
308 |
install_package("bridge-utils")
|
309 |
cmd = """
|
310 |
brctl addbr {0} ; ip link set {0} up
|
311 |
""".format(env.env.common_bridge)
|
312 |
try_run(cmd) |
313 |
|
314 |
|
315 |
def connect_bridges(): |
316 |
debug(env.host, " * Connecting bridges...")
|
317 |
cmd = """
|
318 |
brctl addif {0} {1}
|
319 |
""".format(env.env.common_bridge, env.env.public_iface)
|
320 |
#try_run(cmd)
|
321 |
|
322 |
|
323 |
@roles("ganeti") |
324 |
def setup_net_infra(): |
325 |
debug(env.host, "Setup networking infrastracture..")
|
326 |
create_bridges() |
327 |
connect_bridges() |
328 |
|
329 |
|
330 |
@roles("ganeti") |
331 |
def setup_lvm(): |
332 |
debug(env.host, "create volume group %s for ganeti.." % env.env.vg)
|
333 |
if env.enable_lvm:
|
334 |
install_package("lvm2")
|
335 |
cmd = """
|
336 |
pvcreate {0}
|
337 |
vgcreate {1} {0}
|
338 |
""".format(env.env.extra_disk, env.env.vg)
|
339 |
try_run(cmd) |
340 |
|
341 |
|
342 |
def customize_settings_from_tmpl(tmpl, replace): |
343 |
debug(env.host, " * Customizing template %s..." % tmpl)
|
344 |
local = env.env.templates + tmpl |
345 |
_, custom = tempfile.mkstemp() |
346 |
shutil.copyfile(local, custom) |
347 |
for k, v in replace.iteritems(): |
348 |
regex = "re.sub('%{0}%', '{1}', line)".format(k.upper(), v)
|
349 |
massedit.edit_files([custom], [regex], dry_run=False)
|
350 |
|
351 |
return custom
|
352 |
|
353 |
|
354 |
@roles("nodes") |
355 |
def setup_apt(): |
356 |
debug(env.host, "Setting up apt sources...")
|
357 |
install_package("curl")
|
358 |
cmd = """
|
359 |
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf
|
360 |
curl -k https://dev.grnet.gr/files/apt-grnetdev.pub | apt-key add -
|
361 |
"""
|
362 |
try_run(cmd) |
363 |
host_info = env.env.ips_info[env.host] |
364 |
if host_info.os == "squeeze": |
365 |
tmpl = "/etc/apt/sources.list.d/synnefo.squeeze.list"
|
366 |
else:
|
367 |
tmpl = "/etc/apt/sources.list.d/synnefo.wheezy.list"
|
368 |
replace = {} |
369 |
custom = customize_settings_from_tmpl(tmpl, replace) |
370 |
put(custom, tmpl) |
371 |
apt_get_update() |
372 |
|
373 |
|
374 |
@roles("cyclades", "cms", "pithos", "accounts") |
375 |
def restart_services(): |
376 |
debug(env.host, " * Restarting apache2 and gunicorn...")
|
377 |
try_run("/etc/init.d/gunicorn restart")
|
378 |
try_run("/etc/init.d/apache2 restart")
|
379 |
|
380 |
|
381 |
def setup_gunicorn(): |
382 |
debug(env.host, " * Setting up gunicorn...")
|
383 |
install_package("gunicorn")
|
384 |
tmpl = "/etc/gunicorn.d/synnefo"
|
385 |
replace = {} |
386 |
custom = customize_settings_from_tmpl(tmpl, replace) |
387 |
put(custom, tmpl, mode=0644)
|
388 |
try_run("/etc/init.d/gunicorn restart")
|
389 |
|
390 |
|
391 |
def setup_apache(): |
392 |
debug(env.host, " * Setting up apache2...")
|
393 |
host_info = env.env.ips_info[env.host] |
394 |
install_package("apache2")
|
395 |
tmpl = "/etc/apache2/sites-available/synnefo"
|
396 |
replace = { |
397 |
"HOST": host_info.fqdn,
|
398 |
} |
399 |
custom = customize_settings_from_tmpl(tmpl, replace) |
400 |
put(custom, tmpl) |
401 |
tmpl = "/etc/apache2/sites-available/synnefo-ssl"
|
402 |
custom = customize_settings_from_tmpl(tmpl, replace) |
403 |
put(custom, tmpl) |
404 |
cmd = """
|
405 |
a2enmod ssl
|
406 |
a2enmod rewrite
|
407 |
a2dissite default
|
408 |
a2ensite synnefo
|
409 |
a2ensite synnefo-ssl
|
410 |
a2enmod headers
|
411 |
a2enmod proxy_http
|
412 |
a2dismod autoindex
|
413 |
"""
|
414 |
try_run(cmd) |
415 |
try_run("/etc/init.d/apache2 restart")
|
416 |
|
417 |
|
418 |
@roles("mq") |
419 |
def setup_mq(): |
420 |
debug(env.host, "Setting up RabbitMQ...")
|
421 |
install_package("rabbitmq-server")
|
422 |
cmd = """
|
423 |
rabbitmqctl add_user {0} {1}
|
424 |
rabbitmqctl set_permissions {0} ".*" ".*" ".*"
|
425 |
rabbitmqctl delete_user guest
|
426 |
rabbitmqctl set_user_tags {0} administrator
|
427 |
""".format(env.env.synnefo_user, env.env.synnefo_rabbitmq_passwd)
|
428 |
try_run(cmd) |
429 |
try_run("/etc/init.d/rabbitmq-server restart")
|
430 |
|
431 |
|
432 |
@roles("db") |
433 |
def allow_access_in_db(ip, user="all", method="md5"): |
434 |
cmd = """
|
435 |
echo host all {0} {1}/32 {2} >> /etc/postgresql/8.4/main/pg_hba.conf
|
436 |
""".format(user, ip, method)
|
437 |
try_run(cmd) |
438 |
cmd = """
|
439 |
sed -i 's/\(host.*127.0.0.1.*\)md5/\\1trust/' /etc/postgresql/8.4/main/pg_hba.conf
|
440 |
"""
|
441 |
try_run(cmd) |
442 |
try_run("/etc/init.d/postgresql restart")
|
443 |
|
444 |
@roles("db") |
445 |
def setup_db(): |
446 |
debug(env.host, "Setting up DataBase server...")
|
447 |
install_package("postgresql")
|
448 |
|
449 |
tmpl = "/tmp/db-init.psql"
|
450 |
replace = { |
451 |
"synnefo_user": env.env.synnefo_user,
|
452 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
453 |
} |
454 |
custom = customize_settings_from_tmpl(tmpl, replace) |
455 |
put(custom, tmpl) |
456 |
cmd = 'su - postgres -c "psql -w -f %s" ' % tmpl
|
457 |
try_run(cmd) |
458 |
cmd = """
|
459 |
echo "listen_addresses = '*'" >> /etc/postgresql/8.4/main/postgresql.conf
|
460 |
"""
|
461 |
try_run(cmd) |
462 |
|
463 |
if env.env.testing_vm:
|
464 |
cmd = """
|
465 |
echo "fsync=off\nsynchronous_commit=off\nfull_page_writes=off" >> /etc/postgresql/8.4/main/postgresql.conf
|
466 |
"""
|
467 |
try_run(cmd) |
468 |
|
469 |
allow_access_in_db(env.host, "all", "trust") |
470 |
try_run("/etc/init.d/postgresql restart")
|
471 |
|
472 |
|
473 |
@roles("db") |
474 |
def destroy_db(): |
475 |
try_run("""su - postgres -c ' psql -w -c "drop database snf_apps" '""")
|
476 |
try_run("""su - postgres -c ' psql -w -c "drop database snf_pithos" '""")
|
477 |
|
478 |
|
479 |
def setup_webproject(): |
480 |
debug(env.host, " * Setting up snf-webproject...")
|
481 |
with settings(hide("everything")): |
482 |
try_run("ping -c1 " + env.env.db.ip)
|
483 |
setup_common() |
484 |
install_package("snf-webproject")
|
485 |
install_package("python-psycopg2")
|
486 |
install_package("python-gevent")
|
487 |
tmpl = "/etc/synnefo/webproject.conf"
|
488 |
replace = { |
489 |
"synnefo_user": env.env.synnefo_user,
|
490 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
491 |
"db_node": env.env.db.ip,
|
492 |
"domain": env.env.domain,
|
493 |
} |
494 |
custom = customize_settings_from_tmpl(tmpl, replace) |
495 |
put(custom, tmpl, mode=0644)
|
496 |
with settings(host_string=env.env.db.ip):
|
497 |
host_info = env.env.ips_info[env.host] |
498 |
allow_access_in_db(host_info.ip, "all", "trust") |
499 |
try_run("/etc/init.d/gunicorn restart")
|
500 |
|
501 |
|
502 |
def setup_common(): |
503 |
debug(env.host, " * Setting up snf-common...")
|
504 |
host_info = env.env.ips_info[env.host] |
505 |
install_package("python-objpool")
|
506 |
install_package("snf-common")
|
507 |
install_package("python-astakosclient")
|
508 |
install_package("snf-django-lib")
|
509 |
install_package("snf-branding")
|
510 |
tmpl = "/etc/synnefo/common.conf"
|
511 |
replace = { |
512 |
#FIXME:
|
513 |
"EMAIL_SUBJECT_PREFIX": env.host,
|
514 |
"domain": env.env.domain,
|
515 |
"HOST": host_info.fqdn,
|
516 |
} |
517 |
custom = customize_settings_from_tmpl(tmpl, replace) |
518 |
put(custom, tmpl, mode=0644)
|
519 |
try_run("/etc/init.d/gunicorn restart")
|
520 |
|
521 |
@roles("accounts") |
522 |
def astakos_loaddata(): |
523 |
debug(env.host, " * Loading initial data to astakos...")
|
524 |
cmd = """
|
525 |
snf-manage loaddata groups
|
526 |
"""
|
527 |
try_run(cmd) |
528 |
|
529 |
|
530 |
@roles("accounts") |
531 |
def astakos_register_components(): |
532 |
debug(env.host, " * Register services in astakos...")
|
533 |
|
534 |
cyclades_base_url = "https://%s/cyclades/" % env.env.cyclades.fqdn
|
535 |
pithos_base_url = "https://%s/pithos/" % env.env.pithos.fqdn
|
536 |
astakos_base_url = "https://%s/astakos/" % env.env.accounts.fqdn
|
537 |
|
538 |
cmd = """
|
539 |
snf-manage component-add "home" https://{0} home-icon.png
|
540 |
snf-manage component-add "cyclades" {1}ui/
|
541 |
snf-manage component-add "pithos" {2}ui/
|
542 |
snf-manage component-add "astakos" {3}ui/
|
543 |
""".format(env.env.cms.fqdn, cyclades_base_url,
|
544 |
pithos_base_url, astakos_base_url) |
545 |
try_run(cmd) |
546 |
|
547 |
|
548 |
@roles("accounts") |
549 |
def add_user(): |
550 |
debug(env.host, " * adding user %s to astakos..." % env.env.user_email)
|
551 |
email=env.env.user_email |
552 |
name=env.env.user_name |
553 |
lastname=env.env.user_lastname |
554 |
passwd=env.env.user_passwd |
555 |
cmd = """
|
556 |
snf-manage user-add {0} {1} {2}
|
557 |
""".format(email, name, lastname)
|
558 |
try_run(cmd) |
559 |
with settings(host_string=env.env.db.ip):
|
560 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(email) |
561 |
cmd = """
|
562 |
snf-manage user-modify --password {0} {1}
|
563 |
""".format(passwd, uid)
|
564 |
try_run(cmd) |
565 |
|
566 |
|
567 |
@roles("accounts") |
568 |
def activate_user(user_email=None): |
569 |
if not user_email: |
570 |
user_email = env.env.user_email |
571 |
debug(env.host, " * Activate user %s..." % user_email)
|
572 |
with settings(host_string=env.env.db.ip):
|
573 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(user_email) |
574 |
|
575 |
cmd = """
|
576 |
snf-manage user-modify --verify {0}
|
577 |
snf-manage user-modify --accept {0}
|
578 |
""".format(uid)
|
579 |
try_run(cmd) |
580 |
|
581 |
@roles("accounts") |
582 |
def setup_astakos(): |
583 |
debug(env.host, "Setting up snf-astakos-app...")
|
584 |
setup_gunicorn() |
585 |
setup_apache() |
586 |
setup_webproject() |
587 |
install_package("python-django-south")
|
588 |
install_package("snf-astakos-app")
|
589 |
install_package("kamaki")
|
590 |
|
591 |
tmpl = "/etc/synnefo/astakos.conf"
|
592 |
replace = { |
593 |
"ACCOUNTS": env.env.accounts.fqdn,
|
594 |
"domain": env.env.domain,
|
595 |
"CYCLADES": env.env.cyclades.fqdn,
|
596 |
"PITHOS": env.env.pithos.fqdn,
|
597 |
} |
598 |
custom = customize_settings_from_tmpl(tmpl, replace) |
599 |
put(custom, tmpl, mode=0644)
|
600 |
if env.csrf_disable:
|
601 |
cmd = """
|
602 |
cat <<EOF >> /etc/synnefo/astakos.conf
|
603 |
try:
|
604 |
MIDDLEWARE_CLASSES.remove('django.middleware.csrf.CsrfViewMiddleware')
|
605 |
except:
|
606 |
pass
|
607 |
EOF
|
608 |
"""
|
609 |
try_run(cmd) |
610 |
|
611 |
try_run("/etc/init.d/gunicorn restart")
|
612 |
|
613 |
cmd = """
|
614 |
snf-manage syncdb --noinput
|
615 |
snf-manage migrate im --delete-ghost-migrations
|
616 |
snf-manage migrate quotaholder_app
|
617 |
"""
|
618 |
try_run(cmd) |
619 |
|
620 |
|
621 |
@roles("accounts") |
622 |
def get_service_details(service="pithos"): |
623 |
debug(env.host, " * Getting registered details for %s service..." % service)
|
624 |
result = try_run("snf-manage component-list")
|
625 |
r = re.compile(r".*%s.*" % service, re.M)
|
626 |
service_id, _, _, service_token = r.search(result).group().split() |
627 |
# print("%s: %s %s" % (service, service_id, service_token))
|
628 |
return (service_id, service_token)
|
629 |
|
630 |
|
631 |
@roles("db") |
632 |
def get_auth_token_from_db(user_email=None): |
633 |
if not user_email: |
634 |
user_email=env.env.user_email |
635 |
debug(env.host, " * Getting authentication token and uuid for user %s..." % user_email)
|
636 |
cmd = """
|
637 |
echo "select id, auth_token, uuid, email from auth_user, im_astakosuser where auth_user.id = im_astakosuser.user_ptr_id and auth_user.email = '{0}';" > /tmp/psqlcmd
|
638 |
su - postgres -c "psql -w -d snf_apps -f /tmp/psqlcmd"
|
639 |
""".format(user_email)
|
640 |
|
641 |
result = try_run(cmd) |
642 |
r = re.compile(r"(\d+)[ |]*(\S+)[ |]*(\S+)[ |]*" + user_email, re.M)
|
643 |
match = r.search(result) |
644 |
uid, user_auth_token, user_uuid = match.groups() |
645 |
# print("%s: %s %s %s" % ( user_email, uid, user_auth_token, user_uuid))
|
646 |
|
647 |
return (uid, user_auth_token, user_uuid)
|
648 |
|
649 |
|
650 |
@roles("cms") |
651 |
def cms_loaddata(): |
652 |
debug(env.host, " * Loading cms initial data...")
|
653 |
if env.cms_pass:
|
654 |
debug(env.host, "Aborting. Prerequisites not met.")
|
655 |
return
|
656 |
tmpl = "/tmp/sites.json"
|
657 |
replace = {} |
658 |
custom = customize_settings_from_tmpl(tmpl, replace) |
659 |
put(custom, tmpl) |
660 |
|
661 |
tmpl = "/tmp/page.json"
|
662 |
replace = {} |
663 |
custom = customize_settings_from_tmpl(tmpl, replace) |
664 |
put(custom, tmpl) |
665 |
|
666 |
cmd = """
|
667 |
snf-manage loaddata /tmp/sites.json
|
668 |
snf-manage loaddata /tmp/page.json
|
669 |
snf-manage createsuperuser --username=admin --email=admin@{0} --noinput
|
670 |
""".format(env.env.domain)
|
671 |
try_run(cmd) |
672 |
|
673 |
|
674 |
@roles("cms") |
675 |
def setup_cms(): |
676 |
debug(env.host, "Setting up cms...")
|
677 |
if env.cms_pass:
|
678 |
debug(env.host, "Aborting. Prerequisites not met.")
|
679 |
return
|
680 |
with settings(hide("everything")): |
681 |
try_run("ping -c1 accounts." + env.env.domain)
|
682 |
setup_gunicorn() |
683 |
setup_apache() |
684 |
setup_webproject() |
685 |
install_package("snf-cloudcms")
|
686 |
|
687 |
tmpl = "/etc/synnefo/cms.conf"
|
688 |
replace = { |
689 |
"ACCOUNTS": env.env.accounts.fqdn,
|
690 |
} |
691 |
custom = customize_settings_from_tmpl(tmpl, replace) |
692 |
put(custom, tmpl, mode=0644)
|
693 |
try_run("/etc/init.d/gunicorn restart")
|
694 |
|
695 |
|
696 |
cmd = """
|
697 |
snf-manage syncdb
|
698 |
snf-manage migrate --delete-ghost-migrations
|
699 |
""".format(env.env.domain)
|
700 |
try_run(cmd) |
701 |
|
702 |
|
703 |
def setup_nfs_dirs(): |
704 |
debug(env.host, " * Creating NFS mount point for pithos and ganeti...")
|
705 |
cmd = """
|
706 |
mkdir -p {0}
|
707 |
cd {0}
|
708 |
mkdir -p data
|
709 |
chown www-data:www-data data
|
710 |
chmod g+ws data
|
711 |
mkdir -p /srv/okeanos
|
712 |
""".format(env.env.pithos_dir)
|
713 |
try_run(cmd) |
714 |
|
715 |
|
716 |
@roles("nodes") |
717 |
def setup_nfs_clients(): |
718 |
if env.host == env.env.pithos.ip:
|
719 |
return
|
720 |
|
721 |
host_info = env.env.ips_info[env.host] |
722 |
debug(env.host, " * Mounting pithos NFS mount point...")
|
723 |
with settings(hide("everything")): |
724 |
try_run("ping -c1 " + env.env.pithos.hostname)
|
725 |
with settings(host_string=env.env.pithos.ip):
|
726 |
update_nfs_exports(host_info.ip) |
727 |
|
728 |
install_package("nfs-common")
|
729 |
for d in [env.env.pithos_dir, env.env.image_dir]: |
730 |
try_run("mkdir -p " + d)
|
731 |
cmd = """
|
732 |
echo "{0}:{1} {1} nfs defaults,rw,noatime,rsize=131072,wsize=131072,timeo=14,intr,noacl" >> /etc/fstab
|
733 |
""".format(env.env.pithos.ip, d)
|
734 |
try_run(cmd) |
735 |
try_run("mount " + d)
|
736 |
|
737 |
@roles("pithos") |
738 |
def update_nfs_exports(ip): |
739 |
tmpl = "/tmp/exports"
|
740 |
replace = { |
741 |
"pithos_dir": env.env.pithos_dir,
|
742 |
"image_dir": env.env.image_dir,
|
743 |
"ip": ip,
|
744 |
} |
745 |
custom = customize_settings_from_tmpl(tmpl, replace) |
746 |
put(custom, tmpl) |
747 |
try_run("cat %s >> /etc/exports" % tmpl)
|
748 |
try_run("/etc/init.d/nfs-kernel-server restart")
|
749 |
|
750 |
@roles("pithos") |
751 |
def setup_nfs_server(): |
752 |
debug(env.host, " * Setting up NFS server for pithos...")
|
753 |
setup_nfs_dirs() |
754 |
install_package("nfs-kernel-server")
|
755 |
|
756 |
|
757 |
@roles("pithos") |
758 |
def setup_pithos(): |
759 |
debug(env.host, "Setting up snf-pithos-app...")
|
760 |
with settings(hide("everything")): |
761 |
try_run("ping -c1 accounts." + env.env.domain)
|
762 |
try_run("ping -c1 " + env.env.db.ip)
|
763 |
setup_gunicorn() |
764 |
setup_apache() |
765 |
setup_webproject() |
766 |
|
767 |
with settings(host_string=env.env.accounts.ip):
|
768 |
service_id, service_token = get_service_details("pithos")
|
769 |
|
770 |
install_package("kamaki")
|
771 |
install_package("snf-pithos-backend")
|
772 |
install_package("snf-pithos-app")
|
773 |
tmpl = "/etc/synnefo/pithos.conf"
|
774 |
replace = { |
775 |
"ACCOUNTS": env.env.accounts.fqdn,
|
776 |
"PITHOS": env.env.pithos.fqdn,
|
777 |
"db_node": env.env.db.ip,
|
778 |
"synnefo_user": env.env.synnefo_user,
|
779 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
780 |
"pithos_dir": env.env.pithos_dir,
|
781 |
"PITHOS_SERVICE_TOKEN": service_token,
|
782 |
"proxy": env.env.pithos.hostname == env.env.accounts.hostname
|
783 |
} |
784 |
custom = customize_settings_from_tmpl(tmpl, replace) |
785 |
put(custom, tmpl, mode=0644)
|
786 |
try_run("/etc/init.d/gunicorn restart")
|
787 |
|
788 |
install_package("snf-pithos-webclient")
|
789 |
tmpl = "/etc/synnefo/webclient.conf"
|
790 |
replace = { |
791 |
"ACCOUNTS": env.env.accounts.fqdn,
|
792 |
"PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE": service_id,
|
793 |
} |
794 |
custom = customize_settings_from_tmpl(tmpl, replace) |
795 |
put(custom, tmpl, mode=0644)
|
796 |
|
797 |
try_run("/etc/init.d/gunicorn restart")
|
798 |
#TOFIX: the previous command lets pithos-backend create blocks and maps
|
799 |
# with root owner
|
800 |
try_run("chown -R www-data:www-data %s/data " % env.env.pithos_dir)
|
801 |
#try_run("pithos-migrate stamp 4c8ccdc58192")
|
802 |
#try_run("pithos-migrate upgrade head")
|
803 |
|
804 |
|
805 |
@roles("ganeti") |
806 |
def setup_ganeti(): |
807 |
debug(env.host, "Setting up snf-ganeti...")
|
808 |
node_info = env.env.ips_info[env.host] |
809 |
with settings(hide("everything")): |
810 |
#if env.enable_lvm:
|
811 |
# try_run("vgs " + env.env.vg)
|
812 |
try_run("getent hosts " + env.env.cluster.fqdn)
|
813 |
try_run("getent hosts %s | grep -v ^127" % env.host)
|
814 |
try_run("hostname -f | grep " + node_info.fqdn)
|
815 |
#try_run("ip link show " + env.env.common_bridge)
|
816 |
#try_run("ip link show " + env.env.common_bridge)
|
817 |
#try_run("apt-get update")
|
818 |
install_package("qemu-kvm")
|
819 |
install_package("python-bitarray")
|
820 |
install_package("ganeti-htools")
|
821 |
install_package("snf-ganeti")
|
822 |
try_run("mkdir -p /srv/ganeti/file-storage/")
|
823 |
cmd = """
|
824 |
cat <<EOF > /etc/ganeti/file-storage-paths
|
825 |
/srv/ganeti/file-storage
|
826 |
/srv/ganeti/shared-file-storage
|
827 |
EOF
|
828 |
"""
|
829 |
try_run(cmd) |
830 |
|
831 |
|
832 |
@roles("master") |
833 |
def add_rapi_user(): |
834 |
debug(env.host, " * Adding RAPI user to Ganeti backend...")
|
835 |
cmd = """
|
836 |
echo -n "{0}:Ganeti Remote API:{1}" | openssl md5
|
837 |
""".format(env.env.synnefo_user, env.env.synnefo_rapi_passwd)
|
838 |
result = try_run(cmd) |
839 |
cmd = """
|
840 |
echo "{0} {1}{2} write" >> /var/lib/ganeti/rapi/users
|
841 |
""".format(env.env.synnefo_user, '{ha1}',result) |
842 |
try_run(cmd) |
843 |
try_run("/etc/init.d/ganeti restart")
|
844 |
|
845 |
@roles("master") |
846 |
def add_nodes(): |
847 |
nodes = env.env.cluster_nodes.split(",")
|
848 |
nodes.remove(env.env.master_node) |
849 |
debug(env.host, " * Adding nodes to Ganeti backend...")
|
850 |
for n in nodes: |
851 |
add_node(n) |
852 |
|
853 |
@roles("master") |
854 |
def add_node(node): |
855 |
node_info = env.env.nodes_info[node] |
856 |
debug(env.host, " * Adding node %s to Ganeti backend..." % node_info.fqdn)
|
857 |
cmd = "gnt-node add --no-ssh-key-check --master-capable=yes --vm-capable=yes " + node_info.fqdn
|
858 |
try_run(cmd) |
859 |
|
860 |
@roles("ganeti") |
861 |
def enable_drbd(): |
862 |
if env.enable_drbd:
|
863 |
debug(env.host, " * Enabling DRBD...")
|
864 |
try_run("modprobe drbd minor_count=255 usermode_helper=/bin/true")
|
865 |
try_run("echo drbd minor_count=255 usermode_helper=/bin/true >> /etc/modules")
|
866 |
|
867 |
@roles("master") |
868 |
def setup_drbd_dparams(): |
869 |
if env.enable_drbd:
|
870 |
debug(env.host, " * Twicking drbd related disk parameters in Ganeti...")
|
871 |
cmd = """
|
872 |
gnt-cluster modify --disk-parameters=drbd:metavg={0}
|
873 |
gnt-group modify --disk-parameters=drbd:metavg={0} default
|
874 |
""".format(env.env.vg)
|
875 |
try_run(cmd) |
876 |
|
877 |
@roles("master") |
878 |
def enable_lvm(): |
879 |
if env.enable_lvm:
|
880 |
debug(env.host, " * Enabling LVM...")
|
881 |
cmd = """
|
882 |
gnt-cluster modify --vg-name={0}
|
883 |
""".format(env.env.vg)
|
884 |
try_run(cmd) |
885 |
else:
|
886 |
debug(env.host, " * Disabling LVM...")
|
887 |
try_run("gnt-cluster modify --no-lvm-storage")
|
888 |
|
889 |
@roles("master") |
890 |
def destroy_cluster(): |
891 |
debug(env.host, " * Destroying Ganeti cluster...")
|
892 |
#TODO: remove instances first
|
893 |
allnodes = env.env.cluster_hostnames[:] |
894 |
allnodes.remove(env.host) |
895 |
for n in allnodes: |
896 |
host_info = env.env.ips_info[host] |
897 |
debug(env.host, " * Removing node %s..." % n)
|
898 |
cmd = "gnt-node remove " + host_info.fqdn
|
899 |
try_run(cmd) |
900 |
try_run("gnt-cluster destroy --yes-do-it")
|
901 |
|
902 |
|
903 |
@roles("master") |
904 |
def init_cluster(): |
905 |
debug(env.host, " * Initializing Ganeti backend...")
|
906 |
# extra = ""
|
907 |
# if env.enable_lvm:
|
908 |
# extra += " --vg-name={0} ".format(env.env.vg)
|
909 |
# else:
|
910 |
# extra += " --no-lvm-storage "
|
911 |
# if not env.enable_drbd:
|
912 |
# extra += " --no-drbd-storage "
|
913 |
extra = " --no-lvm-storage --no-drbd-storage "
|
914 |
cmd = """
|
915 |
gnt-cluster init --enabled-hypervisors=kvm \
|
916 |
{0} \
|
917 |
--nic-parameters link={1},mode=bridged \
|
918 |
--master-netdev {2} \
|
919 |
--default-iallocator hail \
|
920 |
--hypervisor-parameters kvm:kernel_path=,vnc_bind_address=0.0.0.0 \
|
921 |
--no-ssh-init --no-etc-hosts \
|
922 |
{3}
|
923 |
|
924 |
""".format(extra, env.env.common_bridge,
|
925 |
env.env.cluster_netdev, env.env.cluster.fqdn) |
926 |
try_run(cmd) |
927 |
|
928 |
|
929 |
@roles("ganeti") |
930 |
def debootstrap(): |
931 |
install_package("ganeti-instance-debootstrap")
|
932 |
|
933 |
|
934 |
@roles("ganeti") |
935 |
def setup_image_host(): |
936 |
debug(env.host, "Setting up snf-image...")
|
937 |
install_package("snf-pithos-backend")
|
938 |
install_package("snf-image")
|
939 |
try_run("mkdir -p %s" % env.env.image_dir)
|
940 |
tmpl = "/etc/default/snf-image"
|
941 |
replace = { |
942 |
"synnefo_user": env.env.synnefo_user,
|
943 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
944 |
"pithos_dir": env.env.pithos_dir,
|
945 |
"db_node": env.env.db.ip,
|
946 |
} |
947 |
custom = customize_settings_from_tmpl(tmpl, replace) |
948 |
put(custom, tmpl) |
949 |
|
950 |
|
951 |
@roles("ganeti") |
952 |
def setup_image_helper(): |
953 |
debug(env.host, " * Updating helper image...")
|
954 |
cmd = """
|
955 |
snf-image-update-helper -y
|
956 |
"""
|
957 |
try_run(cmd) |
958 |
|
959 |
|
960 |
@roles("ganeti") |
961 |
def setup_gtools(): |
962 |
debug(env.host, " * Setting up snf-cyclades-gtools...")
|
963 |
with settings(hide("everything")): |
964 |
try_run("ping -c1 " + env.env.mq.ip)
|
965 |
setup_common() |
966 |
install_package("snf-cyclades-gtools")
|
967 |
tmpl = "/etc/synnefo/gtools.conf"
|
968 |
replace = { |
969 |
"synnefo_user": env.env.synnefo_user,
|
970 |
"synnefo_rabbitmq_passwd": env.env.synnefo_rabbitmq_passwd,
|
971 |
"mq_node": env.env.mq.ip,
|
972 |
} |
973 |
custom = customize_settings_from_tmpl(tmpl, replace) |
974 |
put(custom, tmpl) |
975 |
|
976 |
cmd = """
|
977 |
sed -i 's/false/true/' /etc/default/snf-ganeti-eventd
|
978 |
/etc/init.d/snf-ganeti-eventd start
|
979 |
"""
|
980 |
try_run(cmd) |
981 |
|
982 |
|
983 |
@roles("ganeti") |
984 |
def setup_iptables(): |
985 |
debug(env.host, " * Setting up iptables to mangle DHCP requests...")
|
986 |
cmd = """
|
987 |
iptables -t mangle -A PREROUTING -i br+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
|
988 |
iptables -t mangle -A PREROUTING -i tap+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
|
989 |
iptables -t mangle -A PREROUTING -i prv+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
|
990 |
|
991 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 133 -j NFQUEUE --queue-num 43
|
992 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j NFQUEUE --queue-num 44
|
993 |
"""
|
994 |
try_run(cmd) |
995 |
|
996 |
@roles("ganeti") |
997 |
def setup_network(): |
998 |
debug(env.host, "Setting up networking for Ganeti instances (nfdhcpd, etc.)...")
|
999 |
install_package("nfqueue-bindings-python")
|
1000 |
install_package("nfdhcpd")
|
1001 |
tmpl = "/etc/nfdhcpd/nfdhcpd.conf"
|
1002 |
replace = { |
1003 |
"ns_node_ip": env.env.ns.ip
|
1004 |
} |
1005 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1006 |
put(custom, tmpl) |
1007 |
try_run("/etc/init.d/nfdhcpd restart")
|
1008 |
|
1009 |
install_package("snf-network")
|
1010 |
cmd = """
|
1011 |
sed -i 's/MAC_MASK.*/MAC_MASK = ff:ff:f0:00:00:00/' /etc/default/snf-network
|
1012 |
"""
|
1013 |
try_run(cmd) |
1014 |
|
1015 |
|
1016 |
@roles("router") |
1017 |
def setup_router(): |
1018 |
debug(env.host, " * Setting up internal router for NAT...")
|
1019 |
cmd = """
|
1020 |
echo 1 > /proc/sys/net/ipv4/ip_forward
|
1021 |
iptables -t nat -A POSTROUTING -s {0} -o {3} -j MASQUERADE
|
1022 |
ip addr add {1} dev {2}
|
1023 |
ip route add {0} dev {2} src {1}
|
1024 |
""".format(env.env.synnefo_public_network_subnet,
|
1025 |
env.env.synnefo_public_network_gateway, |
1026 |
env.env.common_bridge, env.env.public_iface) |
1027 |
try_run(cmd) |
1028 |
|
1029 |
|
1030 |
@roles("cyclades") |
1031 |
def cyclades_loaddata(): |
1032 |
debug(env.host, " * Loading initial data for cyclades...")
|
1033 |
try_run("snf-manage flavor-create %s %s %s %s" % (env.env.flavor_cpu,
|
1034 |
env.env.flavor_ram, |
1035 |
env.env.flavor_disk, |
1036 |
env.env.flavor_storage)) |
1037 |
#run("snf-manage loaddata flavors")
|
1038 |
|
1039 |
|
1040 |
@roles("cyclades") |
1041 |
def setup_cyclades(): |
1042 |
debug(env.host, "Setting up snf-cyclades-app...")
|
1043 |
with settings(hide("everything")): |
1044 |
try_run("ping -c1 accounts." + env.env.domain)
|
1045 |
try_run("ping -c1 " + env.env.db.ip)
|
1046 |
try_run("ping -c1 " + env.env.mq.ip)
|
1047 |
setup_gunicorn() |
1048 |
setup_apache() |
1049 |
setup_webproject() |
1050 |
install_package("memcached")
|
1051 |
install_package("python-memcache")
|
1052 |
install_package("snf-pithos-backend")
|
1053 |
install_package("kamaki")
|
1054 |
install_package("snf-cyclades-app")
|
1055 |
install_package("python-django-south")
|
1056 |
tmpl = "/etc/synnefo/cyclades.conf"
|
1057 |
|
1058 |
with settings(host_string=env.env.accounts.ip):
|
1059 |
service_id, service_token = get_service_details("cyclades")
|
1060 |
|
1061 |
replace = { |
1062 |
"ACCOUNTS": env.env.accounts.fqdn,
|
1063 |
"CYCLADES": env.env.cyclades.fqdn,
|
1064 |
"mq_node": env.env.mq.ip,
|
1065 |
"db_node": env.env.db.ip,
|
1066 |
"synnefo_user": env.env.synnefo_user,
|
1067 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
1068 |
"synnefo_rabbitmq_passwd": env.env.synnefo_rabbitmq_passwd,
|
1069 |
"pithos_dir": env.env.pithos_dir,
|
1070 |
"common_bridge": env.env.common_bridge,
|
1071 |
"HOST": env.env.cyclades.ip,
|
1072 |
"domain": env.env.domain,
|
1073 |
"CYCLADES_SERVICE_TOKEN": service_token,
|
1074 |
"proxy": env.env.cyclades.hostname == env.env.accounts.hostname
|
1075 |
} |
1076 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1077 |
put(custom, tmpl, mode=0644)
|
1078 |
try_run("/etc/init.d/gunicorn restart")
|
1079 |
|
1080 |
cmd = """
|
1081 |
sed -i 's/false/true/' /etc/default/snf-dispatcher
|
1082 |
/etc/init.d/snf-dispatcher start
|
1083 |
"""
|
1084 |
try_run(cmd) |
1085 |
|
1086 |
try_run("snf-manage syncdb")
|
1087 |
try_run("snf-manage migrate --delete-ghost-migrations")
|
1088 |
|
1089 |
|
1090 |
@roles("cyclades") |
1091 |
def get_backend_id(cluster_name="ganeti1.synnefo.deploy.local"): |
1092 |
backend_id = try_run("snf-manage backend-list 2>/dev/null | grep %s | awk '{print $1}'" % cluster_name)
|
1093 |
return backend_id
|
1094 |
|
1095 |
|
1096 |
@roles("cyclades") |
1097 |
def add_backend(): |
1098 |
debug(env.host, "adding %s ganeti backend to cyclades..." % env.env.cluster.fqdn)
|
1099 |
with settings(hide("everything")): |
1100 |
try_run("ping -c1 " + env.env.cluster.fqdn)
|
1101 |
cmd = """
|
1102 |
snf-manage backend-add --clustername={0} --user={1} --pass={2}
|
1103 |
""".format(env.env.cluster.fqdn, env.env.synnefo_user,
|
1104 |
env.env.synnefo_rapi_passwd) |
1105 |
try_run(cmd) |
1106 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
1107 |
try_run("snf-manage backend-modify --drained=False " + backend_id)
|
1108 |
|
1109 |
@roles("cyclades") |
1110 |
def pin_user_to_backend(user_email): |
1111 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
1112 |
# pin user to backend
|
1113 |
cmd = """
|
1114 |
cat <<EOF >> /etc/synnefo/cyclades.conf
|
1115 |
|
1116 |
BACKEND_PER_USER = {
|
1117 |
'%s': %s,
|
1118 |
}
|
1119 |
|
1120 |
EOF
|
1121 |
/etc/init.d/gunicorn restart
|
1122 |
""" % (user_email, backend_id)
|
1123 |
try_run(cmd) |
1124 |
|
1125 |
@roles("cyclades") |
1126 |
def add_pools(): |
1127 |
debug(env.host, " * Creating pools of resources (brigdes, mac prefixes) in cyclades...")
|
1128 |
try_run("snf-manage pool-create --type=mac-prefix --base=aa:00:0 --size=65536")
|
1129 |
try_run("snf-manage pool-create --type=bridge --base=prv --size=20")
|
1130 |
|
1131 |
|
1132 |
@roles("accounts", "cyclades", "pithos") |
1133 |
def export_services(): |
1134 |
debug(env.host, " * Exporting services...")
|
1135 |
host = env.host |
1136 |
services = [] |
1137 |
if host == env.env.cyclades.ip:
|
1138 |
services.append("cyclades")
|
1139 |
if host == env.env.pithos.ip:
|
1140 |
services.append("pithos")
|
1141 |
if host == env.env.accounts.ip:
|
1142 |
services.append("astakos")
|
1143 |
for service in services: |
1144 |
filename = "%s_services.json" % service
|
1145 |
cmd = "snf-manage service-export-%s > %s" % (service, filename)
|
1146 |
run(cmd) |
1147 |
get(filename, filename+".local")
|
1148 |
|
1149 |
|
1150 |
@roles("accounts") |
1151 |
def import_services(): |
1152 |
debug(env.host, " * Registering services to astakos...")
|
1153 |
for service in ["cyclades", "pithos", "astakos"]: |
1154 |
filename = "%s_services.json" % service
|
1155 |
put(filename +".local", filename)
|
1156 |
cmd = "snf-manage service-import --json=%s" % filename
|
1157 |
run(cmd) |
1158 |
|
1159 |
debug(env.host, " * Setting default quota...")
|
1160 |
cmd = """
|
1161 |
snf-manage resource-modify --limit 40G pithos.diskspace
|
1162 |
snf-manage resource-modify --limit 2 astakos.pending_app
|
1163 |
snf-manage resource-modify --limit 4 cyclades.vm
|
1164 |
snf-manage resource-modify --limit 40G cyclades.disk
|
1165 |
snf-manage resource-modify --limit 16G cyclades.ram
|
1166 |
snf-manage resource-modify --limit 8G cyclades.active_ram
|
1167 |
snf-manage resource-modify --limit 32 cyclades.cpu
|
1168 |
snf-manage resource-modify --limit 16 cyclades.active_cpu
|
1169 |
snf-manage resource-modify --limit 4 cyclades.network.private
|
1170 |
"""
|
1171 |
try_run(cmd) |
1172 |
|
1173 |
|
1174 |
@roles("cyclades") |
1175 |
def add_network(): |
1176 |
debug(env.host, " * Adding public network in cyclades...")
|
1177 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
1178 |
cmd = """
|
1179 |
snf-manage network-create --subnet={0} --gateway={1} --public --dhcp=True --flavor={2} --mode=bridged --link={3} --name=Internet --backend-id={4}
|
1180 |
""".format(env.env.synnefo_public_network_subnet,
|
1181 |
env.env.synnefo_public_network_gateway, |
1182 |
env.env.synnefo_public_network_type, |
1183 |
env.env.common_bridge, backend_id) |
1184 |
try_run(cmd) |
1185 |
|
1186 |
|
1187 |
@roles("cyclades") |
1188 |
def setup_vncauthproxy(): |
1189 |
debug(env.host, " * Setting up vncauthproxy...")
|
1190 |
install_package("snf-vncauthproxy")
|
1191 |
cmd = """
|
1192 |
echo CHUID="www-data:nogroup" >> /etc/default/vncauthproxy
|
1193 |
rm /var/log/vncauthproxy/vncauthproxy.log
|
1194 |
"""
|
1195 |
try_run(cmd) |
1196 |
try_run("/etc/init.d/vncauthproxy restart")
|
1197 |
|
1198 |
@roles("client") |
1199 |
def setup_kamaki(): |
1200 |
debug(env.host, "Setting up kamaki client...")
|
1201 |
with settings(hide("everything")): |
1202 |
try_run("ping -c1 accounts." + env.env.domain)
|
1203 |
try_run("ping -c1 cyclades." + env.env.domain)
|
1204 |
try_run("ping -c1 pithos." + env.env.domain)
|
1205 |
|
1206 |
with settings(host_string=env.env.db.ip):
|
1207 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email) |
1208 |
|
1209 |
install_package("python-progress")
|
1210 |
install_package("kamaki")
|
1211 |
cmd = """
|
1212 |
kamaki config set cloud.default.url "https://{0}/astakos/identity/v2.0/"
|
1213 |
kamaki config set cloud.default.token {1}
|
1214 |
""".format(env.env.accounts.fqdn, user_auth_token)
|
1215 |
try_run(cmd) |
1216 |
try_run("kamaki file create images")
|
1217 |
|
1218 |
@roles("client") |
1219 |
def upload_image(image="debian_base.diskdump"): |
1220 |
debug(env.host, " * Uploading initial image to pithos...")
|
1221 |
image = "debian_base.diskdump"
|
1222 |
try_run("wget {0} -O /tmp/{1}".format(env.env.debian_base_url, image))
|
1223 |
try_run("kamaki file upload --container images /tmp/{0} {0}".format(image))
|
1224 |
|
1225 |
@roles("client") |
1226 |
def register_image(image="debian_base.diskdump"): |
1227 |
debug(env.host, " * Register image to plankton...")
|
1228 |
# with settings(host_string=env.env.db.ip):
|
1229 |
# uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email)
|
1230 |
|
1231 |
image_location = "images:{0}".format(image)
|
1232 |
cmd = """
|
1233 |
sleep 5
|
1234 |
kamaki image register "Debian Base" {0} --public --disk-format=diskdump --property OSFAMILY=linux --property ROOT_PARTITION=1 --property description="Debian Squeeze Base System" --property size=450M --property kernel=2.6.32 --property GUI="No GUI" --property sortorder=1 --property USERS=root --property OS=debian
|
1235 |
""".format(image_location)
|
1236 |
try_run(cmd) |
1237 |
|
1238 |
@roles("client") |
1239 |
def setup_burnin(): |
1240 |
debug(env.host, "Setting up burnin testing tool...")
|
1241 |
install_package("kamaki")
|
1242 |
install_package("snf-tools")
|
1243 |
|
1244 |
@roles("pithos") |
1245 |
def add_image_locally(): |
1246 |
debug(env.host, " * Getting image locally in order snf-image to use it directly..")
|
1247 |
image = "debian_base.diskdump"
|
1248 |
try_run("wget {0} -O {1}/{2}".format(env.env.debian_base_url, env.env.image_dir, image))
|
1249 |
|
1250 |
|
1251 |
@roles("master") |
1252 |
def gnt_instance_add(name="test"): |
1253 |
debug(env.host, " * Adding test instance to Ganeti...")
|
1254 |
osp="""img_passwd=gamwtosecurity,img_format=diskdump,img_id=debian_base,img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"1"}'"""
|
1255 |
cmd = """
|
1256 |
gnt-instance add -o snf-image+default --os-parameters {0} -t plain --disk 0:size=1G --no-name-check --no-ip-check --net 0:ip=pool,network=test --no-install --hypervisor-parameters kvm:machine_version=pc-1.0 {1}
|
1257 |
""".format(osp, name)
|
1258 |
try_run(cmd) |
1259 |
|
1260 |
@roles("master") |
1261 |
def gnt_network_add(name="test", subnet="10.0.0.0/26", gw="10.0.0.1", mode="bridged", link="br0"): |
1262 |
debug(env.host, " * Adding test network to Ganeti...")
|
1263 |
cmd = """
|
1264 |
gnt-network add --network={1} --gateway={2} {0}
|
1265 |
gnt-network connect {0} {3} {4}
|
1266 |
""".format(name, subnet, gw, mode, link)
|
1267 |
try_run(cmd) |
1268 |
|
1269 |
@roles("ips") |
1270 |
def test(): |
1271 |
debug(env.host, "Testing...")
|
1272 |
try_run("hostname && date")
|