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