root / snf-deploy / fabfile.py @ 8f5ea521
History | View | Annotate | Download (37.6 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): |
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 |
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf) |
27 |
env.env = Env(conf) |
28 |
|
29 |
env.local = autoconf |
30 |
env.password = env.env.password |
31 |
env.user = env.env.user |
32 |
env.shell = "/bin/bash -c"
|
33 |
|
34 |
if disable_colors:
|
35 |
disable_color() |
36 |
|
37 |
if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]: |
38 |
env.cms_pass = True
|
39 |
else:
|
40 |
env.cms_pass = False
|
41 |
|
42 |
if env.env.accounts.hostname in [env.env.cyclades.hostname, env.env.pithos.hostname]: |
43 |
env.csrf_disable = True
|
44 |
else:
|
45 |
env.csrf_disable = False
|
46 |
|
47 |
|
48 |
env.roledefs = { |
49 |
"nodes": env.env.ips,
|
50 |
"ips": env.env.ips,
|
51 |
"accounts": [env.env.accounts.ip],
|
52 |
"cyclades": [env.env.cyclades.ip],
|
53 |
"pithos": [env.env.pithos.ip],
|
54 |
"cms": [env.env.cms.ip],
|
55 |
"mq": [env.env.mq.ip],
|
56 |
"db": [env.env.db.ip],
|
57 |
"ns": [env.env.ns.ip],
|
58 |
"client": [env.env.client.ip],
|
59 |
"router": [env.env.router.ip],
|
60 |
} |
61 |
|
62 |
env.enable_lvm = False
|
63 |
env.enable_drbd = False
|
64 |
if ast.literal_eval(env.env.create_extra_disk) and env.env.extra_disk: |
65 |
env.enable_lvm = True
|
66 |
env.enable_drbd = True
|
67 |
|
68 |
env.roledefs.update({ |
69 |
"ganeti": env.env.cluster_ips,
|
70 |
"master": [env.env.master.ip],
|
71 |
}) |
72 |
|
73 |
|
74 |
def install_package(package): |
75 |
debug(env.host, " * Installing package %s..." % package)
|
76 |
APT_GET = "export DEBIAN_FRONTEND=noninteractive ;apt-get install -y --force-yes "
|
77 |
|
78 |
if ast.literal_eval(env.env.use_local_packages):
|
79 |
with settings(warn_only=True): |
80 |
deb = local("ls %s/%s*deb" % (env.env.packages, package))
|
81 |
if deb:
|
82 |
debug(env.host, " * Package %s found in %s..." % (package, env.env.packages))
|
83 |
put(deb, "/tmp/")
|
84 |
try_run("dpkg -i /tmp/%s*deb || " % package + APT_GET + "-f") |
85 |
try_run("rm /tmp/%s*deb" % package)
|
86 |
return
|
87 |
|
88 |
info = getattr(env.env, package)
|
89 |
if info in ["stable", "squeeze-backports", "testing", "unstable"]: |
90 |
APT_GET += " -t %s %s " % (info, package)
|
91 |
elif info:
|
92 |
APT_GET += " %s=%s " % (package, info)
|
93 |
else:
|
94 |
APT_GET += package |
95 |
|
96 |
try_run(APT_GET) |
97 |
|
98 |
return
|
99 |
|
100 |
|
101 |
@roles("ns") |
102 |
def update_ns_for_ganeti(): |
103 |
debug(env.host, "Updating name server entries for backend %s..." % env.env.cluster.fqdn)
|
104 |
update_arecord(env.env.cluster) |
105 |
update_ptrrecord(env.env.cluster) |
106 |
try_run("/etc/init.d/bind9 restart")
|
107 |
|
108 |
|
109 |
@roles("ns") |
110 |
def update_ns_for_node(node): |
111 |
info = env.env.nodes_info.get(node) |
112 |
update_arecord(info) |
113 |
update_ptrrecord(info) |
114 |
try_run("/etc/init.d/bind9 restart")
|
115 |
|
116 |
|
117 |
@roles("ns") |
118 |
def update_arecord(host): |
119 |
filename = "/etc/bind/zones/" + env.env.domain
|
120 |
cmd = """
|
121 |
echo '{0}' >> {1}
|
122 |
""".format(host.arecord, filename)
|
123 |
try_run(cmd) |
124 |
|
125 |
|
126 |
@roles("ns") |
127 |
def update_cnamerecord(host): |
128 |
filename = "/etc/bind/zones/" + env.env.domain
|
129 |
cmd = """
|
130 |
echo '{0}' >> {1}
|
131 |
""".format(host.cnamerecord, filename)
|
132 |
try_run(cmd) |
133 |
|
134 |
|
135 |
@roles("ns") |
136 |
def update_ptrrecord(host): |
137 |
filename = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
|
138 |
cmd = """
|
139 |
echo '{0}' >> {1}
|
140 |
""".format(host.ptrrecord, filename)
|
141 |
try_run(cmd) |
142 |
|
143 |
@roles("nodes") |
144 |
def apt_get_update(): |
145 |
debug(env.host, "apt-get update....")
|
146 |
try_run("apt-get update")
|
147 |
|
148 |
@roles("ns") |
149 |
def setup_ns(): |
150 |
debug(env.host, "Setting up name server..")
|
151 |
#WARNING: this should be remove after we are done
|
152 |
# because gevent does pick randomly nameservers and google does
|
153 |
# not know our setup!!!!!
|
154 |
apt_get_update() |
155 |
install_package("bind9")
|
156 |
tmpl = "/etc/bind/named.conf.local"
|
157 |
replace = { |
158 |
"domain": env.env.domain,
|
159 |
} |
160 |
custom = customize_settings_from_tmpl(tmpl, replace) |
161 |
put(custom, tmpl) |
162 |
|
163 |
try_run("mkdir -p /etc/bind/zones")
|
164 |
tmpl = "/etc/bind/zones/example.com"
|
165 |
replace = { |
166 |
"domain": env.env.domain,
|
167 |
"ns_node_ip": env.env.ns.ip,
|
168 |
} |
169 |
custom = customize_settings_from_tmpl(tmpl, replace) |
170 |
remote = "/etc/bind/zones/" + env.env.domain
|
171 |
put(custom, remote) |
172 |
|
173 |
try_run("mkdir -p /etc/bind/rev")
|
174 |
tmpl = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
|
175 |
replace = { |
176 |
"domain": env.env.domain,
|
177 |
} |
178 |
custom = customize_settings_from_tmpl(tmpl, replace) |
179 |
put(custom, tmpl) |
180 |
|
181 |
tmpl = "/etc/bind/named.conf.options"
|
182 |
replace = { |
183 |
"NODE_IPS": ";".join(env.env.ips), |
184 |
} |
185 |
custom = customize_settings_from_tmpl(tmpl, replace) |
186 |
put(custom, tmpl, mode=0644)
|
187 |
|
188 |
for role, info in env.env.roles.iteritems(): |
189 |
if role == "ns": |
190 |
continue
|
191 |
update_cnamerecord(info) |
192 |
for node, info in env.env.nodes_info.iteritems(): |
193 |
update_arecord(info) |
194 |
update_ptrrecord(info) |
195 |
|
196 |
try_run("/etc/init.d/bind9 restart")
|
197 |
|
198 |
|
199 |
@roles("nodes") |
200 |
def check_dhcp(): |
201 |
debug(env.host, "Checking IPs for synnefo..")
|
202 |
for n, info in env.env.nodes_info.iteritems(): |
203 |
try_run("ping -c 1 " + info.ip, True) |
204 |
|
205 |
@roles("nodes") |
206 |
def check_dns(): |
207 |
debug(env.host, "Checking fqdns for synnefo..")
|
208 |
for n, info in env.env.nodes_info.iteritems(): |
209 |
try_run("ping -c 1 " + info.fqdn, True) |
210 |
|
211 |
for n, info in env.env.roles.iteritems(): |
212 |
try_run("ping -c 1 " + info.fqdn, True) |
213 |
|
214 |
@roles("nodes") |
215 |
def check_connectivity(): |
216 |
debug(env.host, "Checking internet connectivity..")
|
217 |
try_run("ping -c 1 www.google.com", True) |
218 |
|
219 |
|
220 |
@roles("nodes") |
221 |
def check_ssh(): |
222 |
debug(env.host, "Checking password-less ssh..")
|
223 |
for n, info in env.env.nodes_info.iteritems(): |
224 |
try_run("ssh " + info.fqdn + " date", True) |
225 |
|
226 |
|
227 |
@roles("ips") |
228 |
def add_keys(): |
229 |
if not ast.literal_eval(env.env.key_inject): |
230 |
debug(env.host, "Skipping ssh keys injection..")
|
231 |
try_run("mkdir -p /root/.ssh")
|
232 |
cmd = """
|
233 |
for f in $(ls /root/.ssh/*); do
|
234 |
cp $f $f.bak
|
235 |
done
|
236 |
"""
|
237 |
try_run(cmd) |
238 |
files = ["authorized_keys", "id_dsa", "id_dsa.pub", |
239 |
"id_rsa", "id_rsa.pub"] |
240 |
for f in files: |
241 |
tmpl = "/root/.ssh/" + f
|
242 |
replace = {} |
243 |
custom = customize_settings_from_tmpl(tmpl, replace) |
244 |
put(custom, tmpl) |
245 |
|
246 |
cmd = """
|
247 |
if [ -e /root/.ssh/authorized_keys.bak ]; then
|
248 |
cat /root/.ssh/authorized_keys.bak >> /root/.ssh/authorized_keys
|
249 |
fi
|
250 |
"""
|
251 |
debug(env.host, "Updating exising authorized keys..")
|
252 |
try_run(cmd) |
253 |
|
254 |
@roles("ips") |
255 |
def setup_resolv_conf(): |
256 |
debug(env.host, "Tweak /etc/resolv.conf...")
|
257 |
try_run("/etc/init.d/network-manager stop")
|
258 |
tmpl = "/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate"
|
259 |
replace = {} |
260 |
custom = customize_settings_from_tmpl(tmpl, replace) |
261 |
put(custom, tmpl, mode=0644)
|
262 |
try_run("cp /etc/resolv.conf /etc/resolv.conf.bak")
|
263 |
tmpl = "/etc/resolv.conf"
|
264 |
replace = { |
265 |
"domain": env.env.domain,
|
266 |
"ns_node_ip": env.env.ns.ip,
|
267 |
} |
268 |
custom = customize_settings_from_tmpl(tmpl, replace) |
269 |
put(custom, tmpl) |
270 |
try_run("chattr +i /etc/resolv.conf")
|
271 |
|
272 |
|
273 |
@roles("ips") |
274 |
def setup_hosts(): |
275 |
debug(env.host, "Tweaking /etc/hosts and ssh_config files...")
|
276 |
try_run("echo StrictHostKeyChecking no >> /etc/ssh/ssh_config")
|
277 |
cmd = " sed -i 's/^127.*/127.0.0.1 localhost/g' /etc/hosts "
|
278 |
try_run(cmd) |
279 |
|
280 |
|
281 |
def try_run(cmd, abort=False): |
282 |
try:
|
283 |
if env.local:
|
284 |
return local(cmd, capture=True) |
285 |
else:
|
286 |
return run(cmd)
|
287 |
except:
|
288 |
debug(env.host, "WARNING: command failed. Continuing anyway...")
|
289 |
if abort:
|
290 |
raise
|
291 |
|
292 |
def create_bridges(): |
293 |
debug(env.host, " * Creating bridges...")
|
294 |
install_package("bridge-utils")
|
295 |
cmd = """
|
296 |
brctl addbr {0} ; ip link set {0} up
|
297 |
""".format(env.env.common_bridge)
|
298 |
try_run(cmd) |
299 |
|
300 |
|
301 |
def connect_bridges(): |
302 |
debug(env.host, " * Connecting bridges...")
|
303 |
cmd = """
|
304 |
brctl addif {0} {1}
|
305 |
""".format(env.env.common_bridge, env.env.public_iface)
|
306 |
#try_run(cmd)
|
307 |
|
308 |
|
309 |
@roles("ganeti") |
310 |
def setup_net_infra(): |
311 |
debug(env.host, "Setup networking infrastracture..")
|
312 |
create_bridges() |
313 |
connect_bridges() |
314 |
|
315 |
|
316 |
@roles("ganeti") |
317 |
def setup_lvm(): |
318 |
debug(env.host, "create volume group %s for ganeti.." % env.env.vg)
|
319 |
if env.enable_lvm:
|
320 |
install_package("lvm2")
|
321 |
cmd = """
|
322 |
pvcreate {0}
|
323 |
vgcreate {1} {0}
|
324 |
""".format(env.env.extra_disk, env.env.vg)
|
325 |
try_run(cmd) |
326 |
|
327 |
|
328 |
def customize_settings_from_tmpl(tmpl, replace): |
329 |
debug(env.host, " * Customizing template %s..." % tmpl)
|
330 |
local = env.env.templates + tmpl |
331 |
_, custom = tempfile.mkstemp() |
332 |
shutil.copyfile(local, custom) |
333 |
for k, v in replace.iteritems(): |
334 |
regex = "re.sub('%{0}%', '{1}', line)".format(k.upper(), v)
|
335 |
massedit.edit_files([custom], [regex], dry_run=False)
|
336 |
|
337 |
return custom
|
338 |
|
339 |
|
340 |
@roles("nodes") |
341 |
def setup_apt(): |
342 |
debug(env.host, "Setting up apt sources...")
|
343 |
install_package("curl")
|
344 |
cmd = """
|
345 |
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf
|
346 |
curl -k https://dev.grnet.gr/files/apt-grnetdev.pub | apt-key add -
|
347 |
"""
|
348 |
try_run(cmd) |
349 |
tmpl = "/etc/apt/sources.list.d/okeanos.list"
|
350 |
replace = {} |
351 |
custom = customize_settings_from_tmpl(tmpl, replace) |
352 |
put(custom, tmpl) |
353 |
apt_get_update() |
354 |
|
355 |
|
356 |
@roles("cyclades", "cms", "pithos", "accounts") |
357 |
def restart_services(): |
358 |
debug(env.host, " * Restarting apache2 and gunicorn...")
|
359 |
try_run("/etc/init.d/gunicorn restart")
|
360 |
try_run("/etc/init.d/apache2 restart")
|
361 |
|
362 |
|
363 |
def setup_gunicorn(): |
364 |
debug(env.host, " * Setting up gunicorn...")
|
365 |
install_package("gunicorn")
|
366 |
tmpl = "/etc/gunicorn.d/synnefo"
|
367 |
replace = {} |
368 |
custom = customize_settings_from_tmpl(tmpl, replace) |
369 |
put(custom, tmpl, mode=0644)
|
370 |
try_run("/etc/init.d/gunicorn restart")
|
371 |
|
372 |
|
373 |
def setup_apache(): |
374 |
debug(env.host, " * Setting up apache2...")
|
375 |
host_info = env.env.ips_info[env.host] |
376 |
install_package("apache2")
|
377 |
tmpl = "/etc/apache2/sites-available/synnefo"
|
378 |
replace = { |
379 |
"HOST": host_info.fqdn,
|
380 |
} |
381 |
custom = customize_settings_from_tmpl(tmpl, replace) |
382 |
put(custom, tmpl) |
383 |
tmpl = "/etc/apache2/sites-available/synnefo-ssl"
|
384 |
custom = customize_settings_from_tmpl(tmpl, replace) |
385 |
put(custom, tmpl) |
386 |
cmd = """
|
387 |
a2enmod ssl
|
388 |
a2enmod rewrite
|
389 |
a2dissite default
|
390 |
a2ensite synnefo
|
391 |
a2ensite synnefo-ssl
|
392 |
a2enmod headers
|
393 |
a2enmod proxy_http
|
394 |
a2dismod autoindex
|
395 |
"""
|
396 |
try_run(cmd) |
397 |
try_run("/etc/init.d/apache2 restart")
|
398 |
|
399 |
|
400 |
@roles("mq") |
401 |
def setup_mq(): |
402 |
debug(env.host, "Setting up RabbitMQ...")
|
403 |
install_package("rabbitmq-server")
|
404 |
cmd = """
|
405 |
rabbitmqctl add_user {0} {1}
|
406 |
rabbitmqctl set_permissions {0} ".*" ".*" ".*"
|
407 |
rabbitmqctl delete_user guest
|
408 |
rabbitmqctl set_user_tags {0} administrator
|
409 |
""".format(env.env.synnefo_user, env.env.synnefo_rabbitmq_passwd)
|
410 |
try_run(cmd) |
411 |
try_run("/etc/init.d/rabbitmq-server restart")
|
412 |
|
413 |
|
414 |
@roles("db") |
415 |
def allow_access_in_db(ip, user="all", trust=""): |
416 |
cmd = """
|
417 |
echo host all {0} {1}/32 md5 {2} >> /etc/postgresql/8.4/main/pg_hba.conf
|
418 |
""".format(user, ip, trust)
|
419 |
try_run(cmd) |
420 |
try_run("/etc/init.d/postgresql restart")
|
421 |
|
422 |
@roles("db") |
423 |
def setup_db(): |
424 |
debug(env.host, "Setting up DataBase server...")
|
425 |
install_package("postgresql")
|
426 |
|
427 |
tmpl = "/tmp/db-init.psql"
|
428 |
replace = { |
429 |
"synnefo_user": env.env.synnefo_user,
|
430 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
431 |
} |
432 |
custom = customize_settings_from_tmpl(tmpl, replace) |
433 |
put(custom, tmpl) |
434 |
cmd = 'su - postgres -c "psql -w -f %s" ' % tmpl
|
435 |
try_run(cmd) |
436 |
cmd = """
|
437 |
echo "listen_addresses = '*'" >> /etc/postgresql/8.4/main/postgresql.conf
|
438 |
"""
|
439 |
try_run(cmd) |
440 |
|
441 |
try_run("/etc/init.d/postgresql restart")
|
442 |
allow_access_in_db("127.0.0.1", "postgres", "trust") |
443 |
|
444 |
|
445 |
@roles("db") |
446 |
def destroy_db(): |
447 |
try_run("""su - postgres -c ' psql -w -c "drop database snf_apps" '""")
|
448 |
try_run("""su - postgres -c ' psql -w -c "drop database snf_pithos" '""")
|
449 |
|
450 |
|
451 |
def setup_webproject(): |
452 |
debug(env.host, " * Setting up snf-webproject...")
|
453 |
with settings(hide("everything")): |
454 |
try_run("ping -c1 " + env.env.db.ip)
|
455 |
setup_common() |
456 |
install_package("snf-webproject")
|
457 |
install_package("python-psycopg2")
|
458 |
install_package("python-gevent")
|
459 |
tmpl = "/etc/synnefo/webproject.conf"
|
460 |
replace = { |
461 |
"synnefo_user": env.env.synnefo_user,
|
462 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
463 |
"db_node": env.env.db.ip,
|
464 |
"domain": env.env.domain,
|
465 |
} |
466 |
custom = customize_settings_from_tmpl(tmpl, replace) |
467 |
put(custom, tmpl, mode=0644)
|
468 |
with settings(host_string=env.env.db.ip):
|
469 |
host_info = env.env.ips_info[env.host] |
470 |
allow_access_in_db(host_info.ip) |
471 |
try_run("/etc/init.d/gunicorn restart")
|
472 |
|
473 |
|
474 |
def setup_common(): |
475 |
debug(env.host, " * Setting up snf-common...")
|
476 |
host_info = env.env.ips_info[env.host] |
477 |
install_package("python-objpool")
|
478 |
install_package("snf-common")
|
479 |
install_package("python-astakosclient")
|
480 |
install_package("snf-django-lib")
|
481 |
install_package("snf-branding")
|
482 |
tmpl = "/etc/synnefo/common.conf"
|
483 |
replace = { |
484 |
#FIXME:
|
485 |
"EMAIL_SUBJECT_PREFIX": env.host,
|
486 |
"domain": env.env.domain,
|
487 |
"HOST": host_info.fqdn,
|
488 |
} |
489 |
custom = customize_settings_from_tmpl(tmpl, replace) |
490 |
put(custom, tmpl, mode=0644)
|
491 |
try_run("/etc/init.d/gunicorn restart")
|
492 |
|
493 |
@roles("accounts") |
494 |
def astakos_loaddata(): |
495 |
debug(env.host, " * Loading initial data to astakos...")
|
496 |
cmd = """
|
497 |
snf-manage loaddata groups
|
498 |
"""
|
499 |
try_run(cmd) |
500 |
|
501 |
|
502 |
@roles("accounts") |
503 |
def astakos_register_services(): |
504 |
debug(env.host, " * Register services in astakos...")
|
505 |
cmd = """
|
506 |
snf-manage component-add "home" https://{0} home-icon.png
|
507 |
snf-manage component-add "cyclades" https://{1}/cyclades/ui/
|
508 |
snf-manage component-add "pithos" https://{2}/pithos/ui/
|
509 |
snf-manage component-add "astakos" https://{3}/astakos/ui/
|
510 |
""".format(env.env.cms.fqdn, env.env.cyclades.fqdn, env.env.pithos.fqdn, env.env.accounts.fqdn)
|
511 |
try_run(cmd) |
512 |
import_service("astakos")
|
513 |
import_service("pithos")
|
514 |
import_service("cyclades")
|
515 |
tmpl = "/tmp/resources.json"
|
516 |
replace = {} |
517 |
custom = customize_settings_from_tmpl(tmpl, replace) |
518 |
put(custom, tmpl) |
519 |
try_run("snf-manage resource-import --json %s" % tmpl)
|
520 |
cmd = """
|
521 |
snf-manage resource-modify --limit 40G pithos.diskspace
|
522 |
snf-manage resource-modify --limit 2 astakos.pending_app
|
523 |
snf-manage resource-modify --limit 4 cyclades.vm
|
524 |
snf-manage resource-modify --limit 40G cyclades.disk
|
525 |
snf-manage resource-modify --limit 8G cyclades.ram
|
526 |
snf-manage resource-modify --limit 16 cyclades.cpu
|
527 |
snf-manage resource-modify --limit 4 cyclades.network.private
|
528 |
"""
|
529 |
try_run(cmd) |
530 |
|
531 |
|
532 |
@roles("accounts") |
533 |
def add_user(): |
534 |
debug(env.host, " * adding user %s to astakos..." % env.env.user_email)
|
535 |
email=env.env.user_email |
536 |
name=env.env.user_name |
537 |
lastname=env.env.user_lastname |
538 |
passwd=env.env.user_passwd |
539 |
cmd = """
|
540 |
snf-manage user-add {0} {1} {2}
|
541 |
""".format(email, name, lastname)
|
542 |
try_run(cmd) |
543 |
with settings(host_string=env.env.db.ip):
|
544 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(email) |
545 |
cmd = """
|
546 |
snf-manage user-modify --password {0} {1}
|
547 |
""".format(passwd, uid)
|
548 |
try_run(cmd) |
549 |
|
550 |
|
551 |
@roles("accounts") |
552 |
def activate_user(user_email=None): |
553 |
if not user_email: |
554 |
user_email = env.env.user_email |
555 |
debug(env.host, " * Activate user %s..." % user_email)
|
556 |
with settings(host_string=env.env.db.ip):
|
557 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(user_email) |
558 |
|
559 |
cmd = """
|
560 |
snf-manage user-modify --verify {0}
|
561 |
snf-manage user-modify --accept {0}
|
562 |
""".format(uid)
|
563 |
try_run(cmd) |
564 |
|
565 |
@roles("accounts") |
566 |
def setup_astakos(): |
567 |
debug(env.host, "Setting up snf-astakos-app...")
|
568 |
setup_gunicorn() |
569 |
setup_apache() |
570 |
setup_webproject() |
571 |
install_package("python-django-south")
|
572 |
install_package("snf-astakos-app")
|
573 |
install_package("kamaki")
|
574 |
|
575 |
tmpl = "/etc/synnefo/astakos.conf"
|
576 |
replace = { |
577 |
"ACCOUNTS": env.env.accounts.fqdn,
|
578 |
"domain": env.env.domain,
|
579 |
"CYCLADES": env.env.cyclades.fqdn,
|
580 |
"PITHOS": env.env.pithos.fqdn,
|
581 |
} |
582 |
custom = customize_settings_from_tmpl(tmpl, replace) |
583 |
put(custom, tmpl, mode=0644)
|
584 |
if env.csrf_disable:
|
585 |
cmd = """
|
586 |
cat <<EOF >> /etc/synnefo/astakos.conf
|
587 |
try:
|
588 |
MIDDLEWARE_CLASSES.remove('django.middleware.csrf.CsrfViewMiddleware')
|
589 |
except:
|
590 |
pass
|
591 |
EOF
|
592 |
"""
|
593 |
try_run(cmd) |
594 |
|
595 |
try_run("/etc/init.d/gunicorn restart")
|
596 |
|
597 |
cmd = """
|
598 |
snf-manage syncdb --noinput
|
599 |
snf-manage migrate im --delete-ghost-migrations
|
600 |
snf-manage migrate quotaholder_app
|
601 |
"""
|
602 |
try_run(cmd) |
603 |
|
604 |
def import_service(service): |
605 |
tmpl = "/tmp/%s.json" % service
|
606 |
replace = { |
607 |
"DOMAIN": env.env.domain,
|
608 |
} |
609 |
custom = customize_settings_from_tmpl(tmpl, replace) |
610 |
put(custom, tmpl) |
611 |
try_run("snf-manage service-import --json %s" % tmpl)
|
612 |
|
613 |
@roles("accounts") |
614 |
def get_service_details(service="pithos"): |
615 |
debug(env.host, " * Getting registered details for %s service..." % service)
|
616 |
result = try_run("snf-manage component-list")
|
617 |
r = re.compile(r".*%s.*" % service, re.M)
|
618 |
service_id, _, _, service_token = r.search(result).group().split() |
619 |
# print("%s: %s %s" % (service, service_id, service_token))
|
620 |
return (service_id, service_token)
|
621 |
|
622 |
|
623 |
@roles("db") |
624 |
def get_auth_token_from_db(user_email=None): |
625 |
if not user_email: |
626 |
user_email=env.env.user_email |
627 |
debug(env.host, " * Getting authentication token and uuid for user %s..." % user_email)
|
628 |
cmd = """
|
629 |
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
|
630 |
su - postgres -c "psql -w -d snf_apps -f /tmp/psqlcmd"
|
631 |
""".format(user_email)
|
632 |
|
633 |
result = try_run(cmd) |
634 |
r = re.compile(r"(\d+)[ |]*(\S+)[ |]*(\S+)[ |]*" + user_email, re.M)
|
635 |
match = r.search(result) |
636 |
uid, user_auth_token, user_uuid = match.groups() |
637 |
# print("%s: %s %s %s" % ( user_email, uid, user_auth_token, user_uuid))
|
638 |
|
639 |
return (uid, user_auth_token, user_uuid)
|
640 |
|
641 |
|
642 |
@roles("cms") |
643 |
def cms_loaddata(): |
644 |
debug(env.host, " * Loading cms initial data...")
|
645 |
if env.cms_pass:
|
646 |
debug(env.host, "Aborting. Prerequisites not met.")
|
647 |
return
|
648 |
tmpl = "/tmp/sites.json"
|
649 |
replace = {} |
650 |
custom = customize_settings_from_tmpl(tmpl, replace) |
651 |
put(custom, tmpl) |
652 |
|
653 |
tmpl = "/tmp/page.json"
|
654 |
replace = {} |
655 |
custom = customize_settings_from_tmpl(tmpl, replace) |
656 |
put(custom, tmpl) |
657 |
|
658 |
cmd = """
|
659 |
snf-manage loaddata /tmp/sites.json
|
660 |
snf-manage loaddata /tmp/page.json
|
661 |
snf-manage createsuperuser --username=admin --email=admin@{0} --noinput
|
662 |
""".format(env.env.domain)
|
663 |
try_run(cmd) |
664 |
|
665 |
|
666 |
@roles("cms") |
667 |
def setup_cms(): |
668 |
debug(env.host, "Setting up cms...")
|
669 |
if env.cms_pass:
|
670 |
debug(env.host, "Aborting. Prerequisites not met.")
|
671 |
return
|
672 |
with settings(hide("everything")): |
673 |
try_run("ping -c1 accounts." + env.env.domain)
|
674 |
setup_gunicorn() |
675 |
setup_apache() |
676 |
setup_webproject() |
677 |
install_package("snf-cloudcms")
|
678 |
|
679 |
tmpl = "/etc/synnefo/cms.conf"
|
680 |
replace = { |
681 |
"ACCOUNTS": env.env.accounts.fqdn,
|
682 |
} |
683 |
custom = customize_settings_from_tmpl(tmpl, replace) |
684 |
put(custom, tmpl, mode=0644)
|
685 |
try_run("/etc/init.d/gunicorn restart")
|
686 |
|
687 |
|
688 |
cmd = """
|
689 |
snf-manage syncdb
|
690 |
snf-manage migrate --delete-ghost-migrations
|
691 |
""".format(env.env.domain)
|
692 |
try_run(cmd) |
693 |
|
694 |
|
695 |
def setup_nfs_dirs(): |
696 |
debug(env.host, " * Creating NFS mount point for pithos and ganeti...")
|
697 |
cmd = """
|
698 |
mkdir -p {0}
|
699 |
cd {0}
|
700 |
mkdir -p data
|
701 |
chown www-data:www-data data
|
702 |
chmod g+ws data
|
703 |
mkdir -p /srv/okeanos
|
704 |
""".format(env.env.pithos_dir)
|
705 |
try_run(cmd) |
706 |
|
707 |
|
708 |
@roles("nodes") |
709 |
def setup_nfs_clients(): |
710 |
if env.host == env.env.pithos.ip:
|
711 |
return
|
712 |
|
713 |
debug(env.host, " * Mounting pithos NFS mount point...")
|
714 |
with settings(hide("everything")): |
715 |
try_run("ping -c1 " + env.env.pithos.hostname)
|
716 |
install_package("nfs-common")
|
717 |
for d in [env.env.pithos_dir, "/srv/okeanos"]: |
718 |
try_run("mkdir -p " + d)
|
719 |
cmd = """
|
720 |
echo "{0}:/{1} {2} nfs4 defaults,rw,noatime,nodiratime,intr,rsize=1048576,wsize=1048576,noacl" >> /etc/fstab
|
721 |
""".format(env.env.pithos.hostname, os.path.basename(d), d)
|
722 |
try_run(cmd) |
723 |
try_run("mount " + d)
|
724 |
|
725 |
|
726 |
@roles("pithos") |
727 |
def setup_nfs_server(): |
728 |
debug(env.host, " * Setting up NFS server for pithos...")
|
729 |
setup_nfs_dirs() |
730 |
install_package("nfs-kernel-server")
|
731 |
tmpl = "/etc/exports"
|
732 |
replace = { |
733 |
"pithos_dir": env.env.pithos_dir,
|
734 |
"srv": os.path.dirname(env.env.pithos_dir),
|
735 |
"subnet": env.env.subnet
|
736 |
} |
737 |
custom = customize_settings_from_tmpl(tmpl, replace) |
738 |
put(custom, tmpl) |
739 |
try_run("/etc/init.d/nfs-kernel-server restart")
|
740 |
|
741 |
|
742 |
@roles("pithos") |
743 |
def setup_pithos(): |
744 |
debug(env.host, "Setting up snf-pithos-app...")
|
745 |
with settings(hide("everything")): |
746 |
try_run("ping -c1 accounts." + env.env.domain)
|
747 |
try_run("ping -c1 " + env.env.db.ip)
|
748 |
setup_gunicorn() |
749 |
setup_apache() |
750 |
setup_webproject() |
751 |
|
752 |
with settings(host_string=env.env.accounts.ip):
|
753 |
service_id, service_token = get_service_details("pithos")
|
754 |
|
755 |
install_package("kamaki")
|
756 |
install_package("snf-pithos-backend")
|
757 |
install_package("snf-pithos-app")
|
758 |
tmpl = "/etc/synnefo/pithos.conf"
|
759 |
replace = { |
760 |
"ACCOUNTS": env.env.accounts.fqdn,
|
761 |
"PITHOS": env.env.pithos.fqdn,
|
762 |
"db_node": env.env.db.ip,
|
763 |
"synnefo_user": env.env.synnefo_user,
|
764 |
"synnefo_db_passwd": env.env.synnefo_db_passwd,
|
765 |
"pithos_dir": env.env.pithos_dir,
|
766 |
"PITHOS_SERVICE_TOKEN": service_token,
|
767 |
"proxy": env.env.pithos.hostname == env.env.accounts.hostname
|
768 |
} |
769 |
custom = customize_settings_from_tmpl(tmpl, replace) |
770 |
put(custom, tmpl, mode=0644)
|
771 |
try_run("/etc/init.d/gunicorn restart")
|
772 |
|
773 |
install_package("snf-pithos-webclient")
|
774 |
tmpl = "/etc/synnefo/webclient.conf"
|
775 |
replace = { |
776 |
"ACCOUNTS": env.env.accounts.fqdn,
|
777 |
"PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE": service_id,
|
778 |
} |
779 |
custom = customize_settings_from_tmpl(tmpl, replace) |
780 |
put(custom, tmpl, mode=0644)
|
781 |
|
782 |
try_run("/etc/init.d/gunicorn restart")
|
783 |
#TOFIX: the previous command lets pithos-backend create blocks and maps
|
784 |
# with root owner
|
785 |
try_run("chown -R www-data:www-data %s/data " % env.env.pithos_dir)
|
786 |
#try_run("pithos-migrate stamp 4c8ccdc58192")
|
787 |
#try_run("pithos-migrate upgrade head")
|
788 |
|
789 |
|
790 |
def add_wheezy(): |
791 |
tmpl = "/etc/apt/sources.list.d/wheezy.list"
|
792 |
replace = {} |
793 |
custom = customize_settings_from_tmpl(tmpl, replace) |
794 |
put(custom, tmpl) |
795 |
apt_get_update() |
796 |
|
797 |
|
798 |
def remove_wheezy(): |
799 |
try_run("rm -f /etc/apt/sources.list.d/wheezy.list")
|
800 |
apt_get_update() |
801 |
|
802 |
|
803 |
@roles("ganeti") |
804 |
def setup_ganeti(): |
805 |
debug(env.host, "Setting up snf-ganeti...")
|
806 |
node_info = env.env.ips_info[env.host] |
807 |
with settings(hide("everything")): |
808 |
#if env.enable_lvm:
|
809 |
# try_run("vgs " + env.env.vg)
|
810 |
try_run("getent hosts " + env.env.cluster.fqdn)
|
811 |
try_run("getent hosts %s | grep -v ^127" % env.host)
|
812 |
try_run("hostname -f | grep " + node_info.fqdn)
|
813 |
#try_run("ip link show " + env.env.common_bridge)
|
814 |
#try_run("ip link show " + env.env.common_bridge)
|
815 |
#try_run("apt-get update")
|
816 |
install_package("qemu-kvm")
|
817 |
install_package("python-bitarray")
|
818 |
add_wheezy() |
819 |
install_package("ganeti-htools")
|
820 |
remove_wheezy() |
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 /srv/okeanos")
|
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 |
@roles("cyclades") |
1030 |
def cyclades_loaddata(): |
1031 |
debug(env.host, " * Loading initial data for cyclades...")
|
1032 |
tmpl = "/tmp/flavor.json"
|
1033 |
replace = {} |
1034 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1035 |
put(custom, tmpl) |
1036 |
try_run("snf-manage loaddata " + tmpl)
|
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("cyclades") |
1133 |
def add_network(): |
1134 |
debug(env.host, " * Adding public network in cyclades...")
|
1135 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
1136 |
cmd = """
|
1137 |
snf-manage network-create --subnet={0} --gateway={1} --public --dhcp --flavor={2} --mode=bridged --link={3} --name=Internet --backend-id={4}
|
1138 |
""".format(env.env.synnefo_public_network_subnet,
|
1139 |
env.env.synnefo_public_network_gateway, |
1140 |
env.env.synnefo_public_network_type, |
1141 |
env.env.common_bridge, backend_id) |
1142 |
try_run(cmd) |
1143 |
|
1144 |
|
1145 |
@roles("cyclades") |
1146 |
def setup_vncauthproxy(): |
1147 |
debug(env.host, " * Setting up vncauthproxy...")
|
1148 |
install_package("snf-vncauthproxy")
|
1149 |
cmd = """
|
1150 |
echo CHUID="www-data:nogroup" >> /etc/default/vncauthproxy
|
1151 |
rm /var/log/vncauthproxy/vncauthproxy.log
|
1152 |
"""
|
1153 |
try_run(cmd) |
1154 |
try_run("/etc/init.d/vncauthproxy restart")
|
1155 |
|
1156 |
@roles("client") |
1157 |
def setup_kamaki(): |
1158 |
debug(env.host, "Setting up kamaki client...")
|
1159 |
with settings(hide("everything")): |
1160 |
try_run("ping -c1 accounts." + env.env.domain)
|
1161 |
try_run("ping -c1 cyclades." + env.env.domain)
|
1162 |
try_run("ping -c1 pithos." + env.env.domain)
|
1163 |
|
1164 |
with settings(host_string=env.env.db.ip):
|
1165 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email) |
1166 |
|
1167 |
install_package("python-progress")
|
1168 |
install_package("kamaki")
|
1169 |
cmd = """
|
1170 |
kamaki config set cloud.default.url "https://{0}/astakos/identity/v2.0/"
|
1171 |
kamaki config set cloud.default.token {1}
|
1172 |
""".format(env.env.accounts.fqdn, user_auth_token)
|
1173 |
try_run(cmd) |
1174 |
try_run("kamaki file create images")
|
1175 |
|
1176 |
@roles("client") |
1177 |
def upload_image(image="debian_base.diskdump"): |
1178 |
debug(env.host, " * Uploading initial image to pithos...")
|
1179 |
image = "debian_base.diskdump"
|
1180 |
try_run("wget {0} -O /tmp/{1}".format(env.env.debian_base_url, image))
|
1181 |
try_run("kamaki file upload --container images /tmp/{0} {0}".format(image))
|
1182 |
|
1183 |
@roles("client") |
1184 |
def register_image(image="debian_base.diskdump"): |
1185 |
debug(env.host, " * Register image to plankton...")
|
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 |
pithos_url = "pithos://{0}/images/{1}".format(user_uuid, image)
|
1190 |
cmd = """
|
1191 |
sleep 5
|
1192 |
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
|
1193 |
""".format(pithos_url)
|
1194 |
try_run(cmd) |
1195 |
|
1196 |
@roles("client") |
1197 |
def setup_burnin(): |
1198 |
debug(env.host, "Setting up burnin testing tool...")
|
1199 |
install_package("kamaki")
|
1200 |
install_package("snf-tools")
|
1201 |
|
1202 |
@roles("pithos") |
1203 |
def add_image_locally(): |
1204 |
debug(env.host, " * Getting image locally in order snf-image to use it directly..")
|
1205 |
image = "debian_base.diskdump"
|
1206 |
try_run("wget {0} -O /srv/okeanos/{1}".format(env.env.debian_base_url, image))
|
1207 |
|
1208 |
|
1209 |
@roles("master") |
1210 |
def gnt_instance_add(name="test"): |
1211 |
debug(env.host, " * Adding test instance to Ganeti...")
|
1212 |
osp="""img_passwd=gamwtosecurity,img_format=diskdump,img_id=debian_base,img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"1"}'"""
|
1213 |
cmd = """
|
1214 |
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}
|
1215 |
""".format(osp, name)
|
1216 |
try_run(cmd) |
1217 |
|
1218 |
@roles("master") |
1219 |
def gnt_network_add(name="test", subnet="10.0.0.0/26", gw="10.0.0.1", mode="bridged", link="br0"): |
1220 |
debug(env.host, " * Adding test network to Ganeti...")
|
1221 |
cmd = """
|
1222 |
gnt-network add --network={1} --gateway={2} {0}
|
1223 |
gnt-network connect {0} {3} {4}
|
1224 |
""".format(name, subnet, gw, mode, link)
|
1225 |
try_run(cmd) |
1226 |
|
1227 |
@roles("ips") |
1228 |
def test(): |
1229 |
debug(env.host, "Testing...")
|
1230 |
try_run("hostname && date")
|