Revision f1800130 snf-deploy/fabfile.py
b/snf-deploy/fabfile.py | ||
---|---|---|
1 |
# Too many lines in module pylint: disable-msg=C0302 |
|
2 |
# Too many arguments (7/5) pylint: disable-msg=R0913 |
|
3 |
""" |
|
4 |
Fabric file for snf-deploy |
|
5 |
|
|
6 |
""" |
|
7 |
|
|
1 | 8 |
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 |
|
9 |
from fabric.api import hide, env, settings, local, roles |
|
10 |
from fabric.operations import run, put, get |
|
6 | 11 |
import re |
7 |
import shutil, os |
|
8 |
from functools import wraps |
|
9 |
import imp |
|
10 |
import ConfigParser |
|
11 |
import sys |
|
12 |
import os |
|
13 |
import shutil |
|
12 | 14 |
import tempfile |
13 | 15 |
import ast |
14 |
from snfdeploy.lib import *
|
|
16 |
from snfdeploy.lib import debug, Conf, Env, disable_color
|
|
15 | 17 |
from snfdeploy import massedit |
16 | 18 |
|
17 | 19 |
|
18 |
def setup_env(confdir="conf", packages="packages", |
|
19 |
templates="files", cluster_name="ganeti1", autoconf=False, disable_colors=False, key_inject=False): |
|
20 |
def setup_env(confdir="conf", packages="packages", templates="files", |
|
21 |
cluster_name="ganeti1", autoconf=False, disable_colors=False, |
|
22 |
key_inject=False): |
|
23 |
"""Setup environment""" |
|
20 | 24 |
print("Loading configuration for synnefo...") |
21 | 25 |
print(" * Using config files under %s..." % confdir) |
22 |
print(" * Using %s and %s for packages and templates accordingly..." % (packages, templates)) |
|
26 |
print(" * Using %s and %s for packages and templates accordingly..." |
|
27 |
% (packages, templates)) |
|
23 | 28 |
|
24 | 29 |
autoconf = ast.literal_eval(autoconf) |
25 | 30 |
disable_colors = ast.literal_eval(disable_colors) |
26 | 31 |
env.key_inject = ast.literal_eval(key_inject) |
27 |
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf) |
|
32 |
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, |
|
33 |
autoconf=autoconf) |
|
28 | 34 |
env.env = Env(conf) |
29 | 35 |
|
30 | 36 |
env.local = autoconf |
... | ... | |
35 | 41 |
if disable_colors: |
36 | 42 |
disable_color() |
37 | 43 |
|
38 |
if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]: |
|
39 |
env.cms_pass = True |
|
44 |
if env.env.cms.hostname in \ |
|
45 |
[env.env.accounts.hostname, env.env.cyclades.hostname, |
|
46 |
env.env.pithos.hostname]: |
|
47 |
env.cms_pass = True |
|
40 | 48 |
else: |
41 |
env.cms_pass = False |
|
49 |
env.cms_pass = False
|
|
42 | 50 |
|
43 |
if env.env.accounts.hostname in [env.env.cyclades.hostname, env.env.pithos.hostname]: |
|
44 |
env.csrf_disable = True |
|
51 |
if env.env.accounts.hostname in \ |
|
52 |
[env.env.cyclades.hostname, env.env.pithos.hostname]: |
|
53 |
env.csrf_disable = True |
|
45 | 54 |
else: |
46 |
env.csrf_disable = False |
|
47 |
|
|
55 |
env.csrf_disable = False |
|
48 | 56 |
|
49 | 57 |
env.roledefs = { |
50 | 58 |
"nodes": env.env.ips, |
... | ... | |
55 | 63 |
"cms": [env.env.cms.ip], |
56 | 64 |
"mq": [env.env.mq.ip], |
57 | 65 |
"db": [env.env.db.ip], |
66 |
"mq": [env.env.mq.ip], |
|
67 |
"db": [env.env.db.ip], |
|
58 | 68 |
"ns": [env.env.ns.ip], |
59 | 69 |
"client": [env.env.client.ip], |
60 | 70 |
"router": [env.env.router.ip], |
... | ... | |
74 | 84 |
|
75 | 85 |
def install_package(package): |
76 | 86 |
debug(env.host, " * Installing package %s..." % package) |
77 |
APT_GET = "export DEBIAN_FRONTEND=noninteractive ;apt-get install -y --force-yes " |
|
87 |
apt_get = "export DEBIAN_FRONTEND=noninteractive ;" + \ |
|
88 |
"apt-get install -y --force-yes " |
|
78 | 89 |
|
79 | 90 |
host_info = env.env.ips_info[env.host] |
80 | 91 |
env.env.update_packages(host_info.os) |
81 | 92 |
if ast.literal_eval(env.env.use_local_packages): |
82 | 93 |
with settings(warn_only=True): |
83 |
deb = local("ls %s/%s*%s_all.deb" % (env.env.packages, package, host_info.os), |
|
94 |
deb = local("ls %s/%s*%s_all.deb" |
|
95 |
% (env.env.packages, package, host_info.os), |
|
84 | 96 |
capture=True) |
85 | 97 |
if deb: |
86 |
debug(env.host, " * Package %s found in %s..." % (package, env.env.packages)) |
|
98 |
debug(env.host, |
|
99 |
" * Package %s found in %s..." |
|
100 |
% (package, env.env.packages)) |
|
87 | 101 |
put(deb, "/tmp/") |
88 |
try_run("dpkg -i /tmp/%s || " % os.path.basename(deb) + APT_GET + "-f") |
|
102 |
try_run("dpkg -i /tmp/%s || " |
|
103 |
% os.path.basename(deb) + apt_get + "-f") |
|
89 | 104 |
try_run("rm /tmp/%s" % os.path.basename(deb)) |
90 | 105 |
return |
91 | 106 |
|
92 | 107 |
info = getattr(env.env, package) |
93 |
if info in ["squeeze-backports", "squeeze", "stable", "testing", "unstable", "wheezy"]: |
|
94 |
APT_GET += " -t %s %s " % (info, package) |
|
108 |
if info in \ |
|
109 |
["squeeze-backports", "squeeze", "stable", |
|
110 |
"testing", "unstable", "wheezy"]: |
|
111 |
apt_get += " -t %s %s " % (info, package) |
|
95 | 112 |
elif info: |
96 |
APT_GET += " %s=%s " % (package, info)
|
|
113 |
apt_get += " %s=%s " % (package, info)
|
|
97 | 114 |
else: |
98 |
APT_GET += package
|
|
115 |
apt_get += package
|
|
99 | 116 |
|
100 |
try_run(APT_GET)
|
|
117 |
try_run(apt_get)
|
|
101 | 118 |
|
102 | 119 |
return |
103 | 120 |
|
104 | 121 |
|
105 | 122 |
@roles("ns") |
106 | 123 |
def update_ns_for_ganeti(): |
107 |
debug(env.host, "Updating name server entries for backend %s..." % env.env.cluster.fqdn) |
|
124 |
debug(env.host, |
|
125 |
"Updating name server entries for backend %s..." |
|
126 |
% env.env.cluster.fqdn) |
|
108 | 127 |
update_arecord(env.env.cluster) |
109 | 128 |
update_ptrrecord(env.env.cluster) |
110 | 129 |
try_run("/etc/init.d/bind9 restart") |
... | ... | |
144 | 163 |
""".format(host.ptrrecord, filename) |
145 | 164 |
try_run(cmd) |
146 | 165 |
|
166 |
|
|
147 | 167 |
@roles("nodes") |
148 | 168 |
def apt_get_update(): |
149 | 169 |
debug(env.host, "apt-get update....") |
150 | 170 |
try_run("apt-get update") |
151 | 171 |
|
172 |
|
|
152 | 173 |
@roles("ns") |
153 | 174 |
def setup_ns(): |
154 | 175 |
debug(env.host, "Setting up name server..") |
... | ... | |
159 | 180 |
install_package("bind9") |
160 | 181 |
tmpl = "/etc/bind/named.conf.local" |
161 | 182 |
replace = { |
162 |
"domain": env.env.domain, |
|
163 |
}
|
|
183 |
"domain": env.env.domain,
|
|
184 |
} |
|
164 | 185 |
custom = customize_settings_from_tmpl(tmpl, replace) |
165 | 186 |
put(custom, tmpl) |
166 | 187 |
|
167 | 188 |
try_run("mkdir -p /etc/bind/zones") |
168 | 189 |
tmpl = "/etc/bind/zones/example.com" |
169 | 190 |
replace = { |
170 |
"domain": env.env.domain, |
|
171 |
"ns_node_ip": env.env.ns.ip, |
|
172 |
}
|
|
191 |
"domain": env.env.domain,
|
|
192 |
"ns_node_ip": env.env.ns.ip,
|
|
193 |
} |
|
173 | 194 |
custom = customize_settings_from_tmpl(tmpl, replace) |
174 | 195 |
remote = "/etc/bind/zones/" + env.env.domain |
175 | 196 |
put(custom, remote) |
... | ... | |
177 | 198 |
try_run("mkdir -p /etc/bind/rev") |
178 | 199 |
tmpl = "/etc/bind/rev/synnefo.in-addr.arpa.zone" |
179 | 200 |
replace = { |
180 |
"domain": env.env.domain, |
|
181 |
}
|
|
201 |
"domain": env.env.domain,
|
|
202 |
} |
|
182 | 203 |
custom = customize_settings_from_tmpl(tmpl, replace) |
183 | 204 |
put(custom, tmpl) |
184 | 205 |
|
185 | 206 |
tmpl = "/etc/bind/named.conf.options" |
186 | 207 |
replace = { |
187 |
"NODE_IPS": ";".join(env.env.ips), |
|
188 |
}
|
|
208 |
"NODE_IPS": ";".join(env.env.ips),
|
|
209 |
} |
|
189 | 210 |
custom = customize_settings_from_tmpl(tmpl, replace) |
190 | 211 |
put(custom, tmpl, mode=0644) |
191 | 212 |
|
... | ... | |
206 | 227 |
for n, info in env.env.nodes_info.iteritems(): |
207 | 228 |
try_run("ping -c 1 " + info.ip, True) |
208 | 229 |
|
230 |
|
|
209 | 231 |
@roles("nodes") |
210 | 232 |
def check_dns(): |
211 | 233 |
debug(env.host, "Checking fqdns for synnefo..") |
... | ... | |
215 | 237 |
for n, info in env.env.roles.iteritems(): |
216 | 238 |
try_run("ping -c 1 " + info.fqdn, True) |
217 | 239 |
|
240 |
|
|
218 | 241 |
@roles("nodes") |
219 | 242 |
def check_connectivity(): |
220 | 243 |
debug(env.host, "Checking internet connectivity..") |
... | ... | |
231 | 254 |
@roles("ips") |
232 | 255 |
def add_keys(): |
233 | 256 |
if not env.key_inject: |
234 |
debug(env.host, "Skipping ssh keys injection..") |
|
235 |
return |
|
257 |
debug(env.host, "Skipping ssh keys injection..")
|
|
258 |
return
|
|
236 | 259 |
else: |
237 |
debug(env.host, "Adding rsa/dsa keys..") |
|
260 |
debug(env.host, "Adding rsa/dsa keys..")
|
|
238 | 261 |
try_run("mkdir -p /root/.ssh") |
239 | 262 |
cmd = """ |
240 | 263 |
for f in $(ls /root/.ssh/*); do |
... | ... | |
245 | 268 |
files = ["authorized_keys", "id_dsa", "id_dsa.pub", |
246 | 269 |
"id_rsa", "id_rsa.pub"] |
247 | 270 |
for f in files: |
248 |
tmpl = "/root/.ssh/" + f |
|
249 |
replace = {} |
|
250 |
custom = customize_settings_from_tmpl(tmpl, replace) |
|
251 |
put(custom, tmpl, mode=0600) |
|
271 |
tmpl = "/root/.ssh/" + f
|
|
272 |
replace = {}
|
|
273 |
custom = customize_settings_from_tmpl(tmpl, replace)
|
|
274 |
put(custom, tmpl, mode=0600)
|
|
252 | 275 |
|
253 | 276 |
cmd = """ |
254 | 277 |
if [ -e /root/.ssh/authorized_keys.bak ]; then |
... | ... | |
258 | 281 |
debug(env.host, "Updating exising authorized keys..") |
259 | 282 |
try_run(cmd) |
260 | 283 |
|
284 |
|
|
261 | 285 |
@roles("ips") |
262 | 286 |
def setup_resolv_conf(): |
263 | 287 |
debug(env.host, "Tweak /etc/resolv.conf...") |
... | ... | |
269 | 293 |
try_run("cp /etc/resolv.conf /etc/resolv.conf.bak") |
270 | 294 |
tmpl = "/etc/resolv.conf" |
271 | 295 |
replace = { |
272 |
"domain": env.env.domain, |
|
273 |
"ns_node_ip": env.env.ns.ip, |
|
274 |
}
|
|
296 |
"domain": env.env.domain,
|
|
297 |
"ns_node_ip": env.env.ns.ip,
|
|
298 |
} |
|
275 | 299 |
custom = customize_settings_from_tmpl(tmpl, replace) |
276 | 300 |
try: |
277 |
put(custom, tmpl) |
|
301 |
put(custom, tmpl)
|
|
278 | 302 |
except: |
279 |
pass |
|
303 |
pass
|
|
280 | 304 |
try_run("chattr +i /etc/resolv.conf") |
281 | 305 |
|
282 | 306 |
|
... | ... | |
295 | 319 |
|
296 | 320 |
def try_run(cmd, abort=False): |
297 | 321 |
try: |
298 |
if env.local: |
|
299 |
return local(cmd, capture=True) |
|
300 |
else: |
|
301 |
return run(cmd) |
|
322 |
if env.local:
|
|
323 |
return local(cmd, capture=True)
|
|
324 |
else:
|
|
325 |
return run(cmd)
|
|
302 | 326 |
except: |
303 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
304 |
if abort: |
|
305 |
raise |
|
327 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
328 |
if abort: |
|
329 |
raise |
|
330 |
|
|
306 | 331 |
|
307 | 332 |
def create_bridges(): |
308 | 333 |
debug(env.host, " * Creating bridges...") |
... | ... | |
315 | 340 |
|
316 | 341 |
def connect_bridges(): |
317 | 342 |
debug(env.host, " * Connecting bridges...") |
318 |
cmd = """ |
|
319 |
brctl addif {0} {1} |
|
320 |
""".format(env.env.common_bridge, env.env.public_iface) |
|
343 |
#cmd = """
|
|
344 |
#brctl addif {0} {1}
|
|
345 |
#""".format(env.env.common_bridge, env.env.public_iface)
|
|
321 | 346 |
#try_run(cmd) |
322 | 347 |
|
323 | 348 |
|
... | ... | |
363 | 388 |
try_run(cmd) |
364 | 389 |
host_info = env.env.ips_info[env.host] |
365 | 390 |
if host_info.os == "squeeze": |
366 |
tmpl = "/etc/apt/sources.list.d/synnefo.squeeze.list" |
|
391 |
tmpl = "/etc/apt/sources.list.d/synnefo.squeeze.list"
|
|
367 | 392 |
else: |
368 |
tmpl = "/etc/apt/sources.list.d/synnefo.wheezy.list" |
|
393 |
tmpl = "/etc/apt/sources.list.d/synnefo.wheezy.list"
|
|
369 | 394 |
replace = {} |
370 | 395 |
custom = customize_settings_from_tmpl(tmpl, replace) |
371 | 396 |
put(custom, tmpl) |
... | ... | |
444 | 469 |
try_run(cmd) |
445 | 470 |
try_run("/etc/init.d/postgresql restart") |
446 | 471 |
|
472 |
|
|
447 | 473 |
@roles("db") |
448 | 474 |
def setup_db(): |
449 | 475 |
debug(env.host, "Setting up DataBase server...") |
... | ... | |
522 | 548 |
} |
523 | 549 |
custom = customize_settings_from_tmpl(tmpl, replace) |
524 | 550 |
put(custom, tmpl, mode=0644) |
525 |
try_run("mkdir -p {0}; chown root:www-data {0}; chmod 775 {0}".format(env.env.mail_dir)) |
|
551 |
try_run("mkdir -p {0}; chown root:www-data {0}; chmod 775 {0}".format( |
|
552 |
env.env.mail_dir)) |
|
526 | 553 |
try_run("/etc/init.d/gunicorn restart") |
527 | 554 |
|
555 |
|
|
528 | 556 |
@roles("accounts") |
529 | 557 |
def astakos_loaddata(): |
530 | 558 |
debug(env.host, " * Loading initial data to astakos...") |
... | ... | |
555 | 583 |
@roles("accounts") |
556 | 584 |
def add_user(): |
557 | 585 |
debug(env.host, " * adding user %s to astakos..." % env.env.user_email) |
558 |
email=env.env.user_email
|
|
559 |
name=env.env.user_name
|
|
560 |
lastname=env.env.user_lastname
|
|
561 |
passwd=env.env.user_passwd
|
|
586 |
email = env.env.user_email
|
|
587 |
name = env.env.user_name
|
|
588 |
lastname = env.env.user_lastname
|
|
589 |
passwd = env.env.user_passwd
|
|
562 | 590 |
cmd = """ |
563 | 591 |
snf-manage user-add {0} {1} {2} |
564 | 592 |
""".format(email, name, lastname) |
... | ... | |
574 | 602 |
@roles("accounts") |
575 | 603 |
def activate_user(user_email=None): |
576 | 604 |
if not user_email: |
577 |
user_email = env.env.user_email |
|
605 |
user_email = env.env.user_email
|
|
578 | 606 |
debug(env.host, " * Activate user %s..." % user_email) |
579 | 607 |
with settings(host_string=env.env.db.ip): |
580 | 608 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(user_email) |
... | ... | |
585 | 613 |
""".format(uid) |
586 | 614 |
try_run(cmd) |
587 | 615 |
|
616 |
|
|
588 | 617 |
@roles("accounts") |
589 | 618 |
def setup_astakos(): |
590 | 619 |
debug(env.host, "Setting up snf-astakos-app...") |
... | ... | |
597 | 626 |
|
598 | 627 |
tmpl = "/etc/synnefo/astakos.conf" |
599 | 628 |
replace = { |
600 |
"ACCOUNTS": env.env.accounts.fqdn, |
|
601 |
"domain": env.env.domain, |
|
602 |
"CYCLADES": env.env.cyclades.fqdn, |
|
603 |
"PITHOS": env.env.pithos.fqdn, |
|
629 |
"ACCOUNTS": env.env.accounts.fqdn,
|
|
630 |
"domain": env.env.domain,
|
|
631 |
"CYCLADES": env.env.cyclades.fqdn,
|
|
632 |
"PITHOS": env.env.pithos.fqdn,
|
|
604 | 633 |
} |
605 | 634 |
custom = customize_settings_from_tmpl(tmpl, replace) |
606 | 635 |
put(custom, tmpl, mode=0644) |
607 | 636 |
if env.csrf_disable: |
608 |
cmd = """ |
|
637 |
cmd = """
|
|
609 | 638 |
cat <<EOF >> /etc/synnefo/astakos.conf |
610 | 639 |
try: |
611 | 640 |
MIDDLEWARE_CLASSES.remove('django.middleware.csrf.CsrfViewMiddleware') |
... | ... | |
613 | 642 |
pass |
614 | 643 |
EOF |
615 | 644 |
""" |
616 |
try_run(cmd) |
|
645 |
try_run(cmd)
|
|
617 | 646 |
|
618 | 647 |
try_run("/etc/init.d/gunicorn restart") |
619 | 648 |
|
... | ... | |
627 | 656 |
|
628 | 657 |
@roles("accounts") |
629 | 658 |
def get_service_details(service="pithos"): |
630 |
debug(env.host, " * Getting registered details for %s service..." % service) |
|
659 |
debug(env.host, |
|
660 |
" * Getting registered details for %s service..." % service) |
|
631 | 661 |
result = try_run("snf-manage component-list") |
632 | 662 |
r = re.compile(r".*%s.*" % service, re.M) |
633 | 663 |
service_id, _, _, service_token = r.search(result).group().split() |
... | ... | |
638 | 668 |
@roles("db") |
639 | 669 |
def get_auth_token_from_db(user_email=None): |
640 | 670 |
if not user_email: |
641 |
user_email=env.env.user_email |
|
642 |
debug(env.host, " * Getting authentication token and uuid for user %s..." % user_email) |
|
671 |
user_email = env.env.user_email |
|
672 |
debug(env.host, |
|
673 |
" * Getting authentication token and uuid for user %s..." |
|
674 |
% user_email) |
|
643 | 675 |
cmd = """ |
644 |
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 |
|
645 |
su - postgres -c "psql -w -d snf_apps -f /tmp/psqlcmd" |
|
646 |
""".format(user_email) |
|
676 |
echo "select id, auth_token, uuid, email from auth_user, im_astakosuser \ |
|
677 |
where auth_user.id = im_astakosuser.user_ptr_id and auth_user.email = '{0}';" \ |
|
678 |
> /tmp/psqlcmd |
|
679 |
su - postgres -c "psql -w -d snf_apps -f /tmp/psqlcmd" |
|
680 |
""".format(user_email) |
|
647 | 681 |
|
648 | 682 |
result = try_run(cmd) |
649 | 683 |
r = re.compile(r"(\d+)[ |]*(\S+)[ |]*(\S+)[ |]*" + user_email, re.M) |
... | ... | |
658 | 692 |
def cms_loaddata(): |
659 | 693 |
debug(env.host, " * Loading cms initial data...") |
660 | 694 |
if env.cms_pass: |
661 |
debug(env.host, "Aborting. Prerequisites not met.") |
|
662 |
return |
|
695 |
debug(env.host, "Aborting. Prerequisites not met.")
|
|
696 |
return
|
|
663 | 697 |
tmpl = "/tmp/sites.json" |
664 | 698 |
replace = {} |
665 | 699 |
custom = customize_settings_from_tmpl(tmpl, replace) |
... | ... | |
682 | 716 |
def setup_cms(): |
683 | 717 |
debug(env.host, "Setting up cms...") |
684 | 718 |
if env.cms_pass: |
685 |
debug(env.host, "Aborting. Prerequisites not met.") |
|
686 |
return |
|
719 |
debug(env.host, "Aborting. Prerequisites not met.")
|
|
720 |
return
|
|
687 | 721 |
with settings(hide("everything")): |
688 | 722 |
try_run("ping -c1 accounts." + env.env.domain) |
689 | 723 |
setup_gunicorn() |
... | ... | |
699 | 733 |
put(custom, tmpl, mode=0644) |
700 | 734 |
try_run("/etc/init.d/gunicorn restart") |
701 | 735 |
|
702 |
|
|
703 | 736 |
cmd = """ |
704 | 737 |
snf-manage syncdb |
705 | 738 |
snf-manage migrate --delete-ghost-migrations |
... | ... | |
723 | 756 |
@roles("nodes") |
724 | 757 |
def setup_nfs_clients(): |
725 | 758 |
if env.host == env.env.pithos.ip: |
726 |
return |
|
759 |
return
|
|
727 | 760 |
|
728 | 761 |
host_info = env.env.ips_info[env.host] |
729 | 762 |
debug(env.host, " * Mounting pithos NFS mount point...") |
... | ... | |
734 | 767 |
|
735 | 768 |
install_package("nfs-common") |
736 | 769 |
for d in [env.env.pithos_dir, env.env.image_dir]: |
737 |
try_run("mkdir -p " + d) |
|
738 |
cmd = """ |
|
739 |
echo "{0}:{1} {1} nfs defaults,rw,noatime,rsize=131072,wsize=131072,timeo=14,intr,noacl" >> /etc/fstab |
|
740 |
""".format(env.env.pithos.ip, d) |
|
741 |
try_run(cmd) |
|
742 |
try_run("mount " + d) |
|
770 |
try_run("mkdir -p " + d) |
|
771 |
cmd = """ |
|
772 |
echo "{0}:{1} {1} nfs defaults,rw,noatime,rsize=131072,\ |
|
773 |
wsize=131072,timeo=14,intr,noacl" >> /etc/fstab |
|
774 |
""".format(env.env.pithos.ip, d) |
|
775 |
try_run(cmd) |
|
776 |
try_run("mount " + d) |
|
777 |
|
|
743 | 778 |
|
744 | 779 |
@roles("pithos") |
745 | 780 |
def update_nfs_exports(ip): |
746 | 781 |
tmpl = "/tmp/exports" |
747 | 782 |
replace = { |
748 |
"pithos_dir": env.env.pithos_dir, |
|
749 |
"image_dir": env.env.image_dir, |
|
750 |
"ip": ip, |
|
751 |
}
|
|
783 |
"pithos_dir": env.env.pithos_dir,
|
|
784 |
"image_dir": env.env.image_dir,
|
|
785 |
"ip": ip,
|
|
786 |
} |
|
752 | 787 |
custom = customize_settings_from_tmpl(tmpl, replace) |
753 | 788 |
put(custom, tmpl) |
754 | 789 |
try_run("cat %s >> /etc/exports" % tmpl) |
755 | 790 |
try_run("/etc/init.d/nfs-kernel-server restart") |
756 | 791 |
|
792 |
|
|
757 | 793 |
@roles("pithos") |
758 | 794 |
def setup_nfs_server(): |
759 | 795 |
debug(env.host, " * Setting up NFS server for pithos...") |
... | ... | |
845 | 881 |
result = try_run(cmd) |
846 | 882 |
cmd = """ |
847 | 883 |
echo "{0} {1}{2} write" >> /var/lib/ganeti/rapi/users |
848 |
""".format(env.env.synnefo_user, '{ha1}',result) |
|
884 |
""".format(env.env.synnefo_user, '{ha1}', result)
|
|
849 | 885 |
try_run(cmd) |
850 | 886 |
try_run("/etc/init.d/ganeti restart") |
851 | 887 |
|
888 |
|
|
852 | 889 |
@roles("master") |
853 | 890 |
def add_nodes(): |
854 | 891 |
nodes = env.env.cluster_nodes.split(",") |
... | ... | |
857 | 894 |
for n in nodes: |
858 | 895 |
add_node(n) |
859 | 896 |
|
897 |
|
|
860 | 898 |
@roles("master") |
861 | 899 |
def add_node(node): |
862 | 900 |
node_info = env.env.nodes_info[node] |
863 | 901 |
debug(env.host, " * Adding node %s to Ganeti backend..." % node_info.fqdn) |
864 |
cmd = "gnt-node add --no-ssh-key-check --master-capable=yes --vm-capable=yes " + node_info.fqdn |
|
902 |
cmd = "gnt-node add --no-ssh-key-check --master-capable=yes " + \ |
|
903 |
"--vm-capable=yes " + node_info.fqdn |
|
865 | 904 |
try_run(cmd) |
866 | 905 |
|
906 |
|
|
867 | 907 |
@roles("ganeti") |
868 | 908 |
def enable_drbd(): |
869 | 909 |
if env.enable_drbd: |
870 | 910 |
debug(env.host, " * Enabling DRBD...") |
871 | 911 |
try_run("modprobe drbd minor_count=255 usermode_helper=/bin/true") |
872 |
try_run("echo drbd minor_count=255 usermode_helper=/bin/true >> /etc/modules") |
|
912 |
try_run("echo drbd minor_count=255 usermode_helper=/bin/true " + |
|
913 |
">> /etc/modules") |
|
914 |
|
|
873 | 915 |
|
874 | 916 |
@roles("master") |
875 | 917 |
def setup_drbd_dparams(): |
876 | 918 |
if env.enable_drbd: |
877 |
debug(env.host, " * Twicking drbd related disk parameters in Ganeti...") |
|
919 |
debug(env.host, |
|
920 |
" * Twicking drbd related disk parameters in Ganeti...") |
|
878 | 921 |
cmd = """ |
879 | 922 |
gnt-cluster modify --disk-parameters=drbd:metavg={0} |
880 | 923 |
gnt-group modify --disk-parameters=drbd:metavg={0} default |
881 | 924 |
""".format(env.env.vg) |
882 | 925 |
try_run(cmd) |
883 | 926 |
|
927 |
|
|
884 | 928 |
@roles("master") |
885 | 929 |
def enable_lvm(): |
886 | 930 |
if env.enable_lvm: |
... | ... | |
893 | 937 |
debug(env.host, " * Disabling LVM...") |
894 | 938 |
try_run("gnt-cluster modify --no-lvm-storage") |
895 | 939 |
|
940 |
|
|
896 | 941 |
@roles("master") |
897 | 942 |
def destroy_cluster(): |
898 | 943 |
debug(env.host, " * Destroying Ganeti cluster...") |
... | ... | |
900 | 945 |
allnodes = env.env.cluster_hostnames[:] |
901 | 946 |
allnodes.remove(env.host) |
902 | 947 |
for n in allnodes: |
903 |
host_info = env.env.ips_info[host]
|
|
904 |
debug(env.host, " * Removing node %s..." % n) |
|
905 |
cmd = "gnt-node remove " + host_info.fqdn |
|
906 |
try_run(cmd) |
|
948 |
host_info = env.env.ips_info[env.host]
|
|
949 |
debug(env.host, " * Removing node %s..." % n)
|
|
950 |
cmd = "gnt-node remove " + host_info.fqdn
|
|
951 |
try_run(cmd)
|
|
907 | 952 |
try_run("gnt-cluster destroy --yes-do-it") |
908 | 953 |
|
909 | 954 |
|
... | ... | |
920 | 965 |
extra = " --no-lvm-storage --no-drbd-storage " |
921 | 966 |
cmd = """ |
922 | 967 |
gnt-cluster init --enabled-hypervisors=kvm \ |
923 |
{0} \ |
|
924 |
--nic-parameters link={1},mode=bridged \ |
|
925 |
--master-netdev {2} \ |
|
926 |
--default-iallocator hail \ |
|
927 |
--hypervisor-parameters kvm:kernel_path=,vnc_bind_address=0.0.0.0 \ |
|
928 |
--no-ssh-init --no-etc-hosts \ |
|
929 |
{3} |
|
930 |
|
|
968 |
{0} \ |
|
969 |
--nic-parameters link={1},mode=bridged \ |
|
970 |
--master-netdev {2} \ |
|
971 |
--default-iallocator hail \ |
|
972 |
--hypervisor-parameters kvm:kernel_path=,vnc_bind_address=0.0.0.0 \ |
|
973 |
--no-ssh-init --no-etc-hosts \ |
|
974 |
{3} |
|
931 | 975 |
""".format(extra, env.env.common_bridge, |
932 | 976 |
env.env.cluster_netdev, env.env.cluster.fqdn) |
933 | 977 |
try_run(cmd) |
... | ... | |
991 | 1035 |
def setup_iptables(): |
992 | 1036 |
debug(env.host, " * Setting up iptables to mangle DHCP requests...") |
993 | 1037 |
cmd = """ |
994 |
iptables -t mangle -A PREROUTING -i br+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42 |
|
995 |
iptables -t mangle -A PREROUTING -i tap+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42 |
|
996 |
iptables -t mangle -A PREROUTING -i prv+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42 |
|
997 |
|
|
998 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 133 -j NFQUEUE --queue-num 43 |
|
999 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j NFQUEUE --queue-num 44 |
|
1038 |
iptables -t mangle -A PREROUTING -i br+ -p udp -m udp --dport 67 \ |
|
1039 |
-j NFQUEUE --queue-num 42 |
|
1040 |
iptables -t mangle -A PREROUTING -i tap+ -p udp -m udp --dport 67 \ |
|
1041 |
-j NFQUEUE --queue-num 42 |
|
1042 |
iptables -t mangle -A PREROUTING -i prv+ -p udp -m udp --dport 67 \ |
|
1043 |
-j NFQUEUE --queue-num 42 |
|
1044 |
|
|
1045 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 \ |
|
1046 |
--icmpv6-type 133 -j NFQUEUE --queue-num 43 |
|
1047 |
ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 \ |
|
1048 |
--icmpv6-type 135 -j NFQUEUE --queue-num 44 |
|
1000 | 1049 |
""" |
1001 | 1050 |
try_run(cmd) |
1002 | 1051 |
|
1052 |
|
|
1003 | 1053 |
@roles("ganeti") |
1004 | 1054 |
def setup_network(): |
1005 |
debug(env.host, "Setting up networking for Ganeti instances (nfdhcpd, etc.)...") |
|
1055 |
debug(env.host, |
|
1056 |
"Setting up networking for Ganeti instances (nfdhcpd, etc.)...") |
|
1006 | 1057 |
install_package("nfqueue-bindings-python") |
1007 | 1058 |
install_package("nfdhcpd") |
1008 | 1059 |
tmpl = "/etc/nfdhcpd/nfdhcpd.conf" |
1009 | 1060 |
replace = { |
1010 |
"ns_node_ip": env.env.ns.ip |
|
1011 |
}
|
|
1061 |
"ns_node_ip": env.env.ns.ip
|
|
1062 |
} |
|
1012 | 1063 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1013 | 1064 |
put(custom, tmpl) |
1014 | 1065 |
try_run("/etc/init.d/nfdhcpd restart") |
1015 | 1066 |
|
1016 | 1067 |
install_package("snf-network") |
1017 | 1068 |
cmd = """ |
1018 |
sed -i 's/MAC_MASK.*/MAC_MASK = ff:ff:f0:00:00:00/' /etc/default/snf-network
|
|
1069 |
sed -i 's/MAC_MASK.*/MAC_MASK = ff:ff:f0:00:00:00/' /etc/default/snf-network |
|
1019 | 1070 |
""" |
1020 | 1071 |
try_run(cmd) |
1021 | 1072 |
|
... | ... | |
1096 | 1147 |
|
1097 | 1148 |
@roles("cyclades") |
1098 | 1149 |
def get_backend_id(cluster_name="ganeti1.synnefo.deploy.local"): |
1099 |
backend_id = try_run("snf-manage backend-list 2>/dev/null | grep %s | awk '{print $1}'" % cluster_name) |
|
1150 |
backend_id = try_run("snf-manage backend-list 2>/dev/null " + |
|
1151 |
"| grep %s | awk '{print $1}'" % cluster_name) |
|
1100 | 1152 |
return backend_id |
1101 | 1153 |
|
1102 | 1154 |
|
1103 | 1155 |
@roles("cyclades") |
1104 | 1156 |
def add_backend(): |
1105 |
debug(env.host, "adding %s ganeti backend to cyclades..." % env.env.cluster.fqdn) |
|
1157 |
debug(env.host, |
|
1158 |
"adding %s ganeti backend to cyclades..." % env.env.cluster.fqdn) |
|
1106 | 1159 |
with settings(hide("everything")): |
1107 | 1160 |
try_run("ping -c1 " + env.env.cluster.fqdn) |
1108 | 1161 |
cmd = """ |
... | ... | |
1113 | 1166 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
1114 | 1167 |
try_run("snf-manage backend-modify --drained=False " + backend_id) |
1115 | 1168 |
|
1169 |
|
|
1116 | 1170 |
@roles("cyclades") |
1117 | 1171 |
def pin_user_to_backend(user_email): |
1118 | 1172 |
backend_id = get_backend_id(env.env.cluster.fqdn) |
... | ... | |
1121 | 1175 |
cat <<EOF >> /etc/synnefo/cyclades.conf |
1122 | 1176 |
|
1123 | 1177 |
BACKEND_PER_USER = { |
1124 |
'%s': %s,
|
|
1178 |
'{0}': {1},
|
|
1125 | 1179 |
} |
1126 | 1180 |
|
1127 | 1181 |
EOF |
1128 | 1182 |
/etc/init.d/gunicorn restart |
1129 |
""" % (user_email, backend_id)
|
|
1183 |
""".format(user_email, backend_id)
|
|
1130 | 1184 |
try_run(cmd) |
1131 | 1185 |
|
1186 |
|
|
1132 | 1187 |
@roles("cyclades") |
1133 | 1188 |
def add_pools(): |
1134 |
debug(env.host, " * Creating pools of resources (brigdes, mac prefixes) in cyclades...") |
|
1135 |
try_run("snf-manage pool-create --type=mac-prefix --base=aa:00:0 --size=65536") |
|
1189 |
debug(env.host, |
|
1190 |
" * Creating pools of resources (brigdes, mac prefixes) " + |
|
1191 |
"in cyclades...") |
|
1192 |
try_run("snf-manage pool-create --type=mac-prefix " + |
|
1193 |
"--base=aa:00:0 --size=65536") |
|
1136 | 1194 |
try_run("snf-manage pool-create --type=bridge --base=prv --size=20") |
1137 | 1195 |
|
1138 | 1196 |
|
... | ... | |
1159 | 1217 |
debug(env.host, " * Registering services to astakos...") |
1160 | 1218 |
for service in ["cyclades", "pithos", "astakos"]: |
1161 | 1219 |
filename = "%s_services.json" % service |
1162 |
put(filename +".local", filename) |
|
1220 |
put(filename + ".local", filename)
|
|
1163 | 1221 |
cmd = "snf-manage service-import --json=%s" % filename |
1164 | 1222 |
run(cmd) |
1165 | 1223 |
|
... | ... | |
1202 | 1260 |
try_run(cmd) |
1203 | 1261 |
try_run("/etc/init.d/vncauthproxy restart") |
1204 | 1262 |
|
1263 |
|
|
1205 | 1264 |
@roles("client") |
1206 | 1265 |
def setup_kamaki(): |
1207 | 1266 |
debug(env.host, "Setting up kamaki client...") |
... | ... | |
1211 | 1270 |
try_run("ping -c1 pithos." + env.env.domain) |
1212 | 1271 |
|
1213 | 1272 |
with settings(host_string=env.env.db.ip): |
1214 |
uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email) |
|
1273 |
uid, user_auth_token, user_uuid = \ |
|
1274 |
get_auth_token_from_db(env.env.user_email) |
|
1215 | 1275 |
|
1216 | 1276 |
install_package("python-progress") |
1217 | 1277 |
install_package("kamaki") |
... | ... | |
1222 | 1282 |
try_run(cmd) |
1223 | 1283 |
try_run("kamaki file create images") |
1224 | 1284 |
|
1285 |
|
|
1225 | 1286 |
@roles("client") |
1226 | 1287 |
def upload_image(image="debian_base.diskdump"): |
1227 | 1288 |
debug(env.host, " * Uploading initial image to pithos...") |
... | ... | |
1229 | 1290 |
try_run("wget {0} -O /tmp/{1}".format(env.env.debian_base_url, image)) |
1230 | 1291 |
try_run("kamaki file upload --container images /tmp/{0} {0}".format(image)) |
1231 | 1292 |
|
1293 |
|
|
1232 | 1294 |
@roles("client") |
1233 | 1295 |
def register_image(image="debian_base.diskdump"): |
1234 | 1296 |
debug(env.host, " * Register image to plankton...") |
1235 | 1297 |
# with settings(host_string=env.env.db.ip): |
1236 |
# uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email) |
|
1298 |
# uid, user_auth_token, user_uuid = \ |
|
1299 |
# get_auth_token_from_db(env.env.user_email) |
|
1237 | 1300 |
|
1238 | 1301 |
image_location = "images:{0}".format(image) |
1239 | 1302 |
cmd = """ |
1240 | 1303 |
sleep 5 |
1241 |
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 |
|
1304 |
kamaki image register "Debian Base" {0} --public --disk-format=diskdump \ |
|
1305 |
--property OSFAMILY=linux --property ROOT_PARTITION=1 \ |
|
1306 |
--property description="Debian Squeeze Base System" \ |
|
1307 |
--property size=450M --property kernel=2.6.32 \ |
|
1308 |
--property GUI="No GUI" --property sortorder=1 \ |
|
1309 |
--property USERS=root --property OS=debian |
|
1242 | 1310 |
""".format(image_location) |
1243 | 1311 |
try_run(cmd) |
1244 | 1312 |
|
1313 |
|
|
1245 | 1314 |
@roles("client") |
1246 | 1315 |
def setup_burnin(): |
1247 | 1316 |
debug(env.host, "Setting up burnin testing tool...") |
1248 | 1317 |
install_package("kamaki") |
1249 | 1318 |
install_package("snf-tools") |
1250 | 1319 |
|
1320 |
|
|
1251 | 1321 |
@roles("pithos") |
1252 | 1322 |
def add_image_locally(): |
1253 |
debug(env.host, " * Getting image locally in order snf-image to use it directly..") |
|
1323 |
debug(env.host, |
|
1324 |
" * Getting image locally in order snf-image to use it directly..") |
|
1254 | 1325 |
image = "debian_base.diskdump" |
1255 |
try_run("wget {0} -O {1}/{2}".format(env.env.debian_base_url, env.env.image_dir, image)) |
|
1326 |
try_run("wget {0} -O {1}/{2}".format( |
|
1327 |
env.env.debian_base_url, env.env.image_dir, image)) |
|
1256 | 1328 |
|
1257 | 1329 |
|
1258 | 1330 |
@roles("master") |
1259 | 1331 |
def gnt_instance_add(name="test"): |
1260 | 1332 |
debug(env.host, " * Adding test instance to Ganeti...") |
1261 |
osp="""img_passwd=gamwtosecurity,img_format=diskdump,img_id=debian_base,img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"1"}'""" |
|
1333 |
osp = """img_passwd=gamwtosecurity,\ |
|
1334 |
img_format=diskdump,img_id=debian_base,\ |
|
1335 |
img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"1"}'""" |
|
1262 | 1336 |
cmd = """ |
1263 |
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} |
|
1337 |
gnt-instance add -o snf-image+default --os-parameters {0} \ |
|
1338 |
-t plain --disk 0:size=1G --no-name-check --no-ip-check \ |
|
1339 |
--net 0:ip=pool,network=test --no-install \ |
|
1340 |
--hypervisor-parameters kvm:machine_version=pc-1.0 {1} |
|
1264 | 1341 |
""".format(osp, name) |
1265 | 1342 |
try_run(cmd) |
1266 | 1343 |
|
1344 |
|
|
1267 | 1345 |
@roles("master") |
1268 |
def gnt_network_add(name="test", subnet="10.0.0.0/26", gw="10.0.0.1", mode="bridged", link="br0"): |
|
1346 |
def gnt_network_add(name="test", subnet="10.0.0.0/26", gw="10.0.0.1", |
|
1347 |
mode="bridged", link="br0"): |
|
1269 | 1348 |
debug(env.host, " * Adding test network to Ganeti...") |
1270 | 1349 |
cmd = """ |
1271 | 1350 |
gnt-network add --network={1} --gateway={2} {0} |
... | ... | |
1273 | 1352 |
""".format(name, subnet, gw, mode, link) |
1274 | 1353 |
try_run(cmd) |
1275 | 1354 |
|
1355 |
|
|
1276 | 1356 |
@roles("ips") |
1277 | 1357 |
def test(): |
1278 | 1358 |
debug(env.host, "Testing...") |
Also available in: Unified diff