Revision 2ede0463
b/snf-deploy/fabfile.py | ||
---|---|---|
8 | 8 |
from __future__ import with_statement |
9 | 9 |
from fabric.api import hide, env, settings, local, roles |
10 | 10 |
from fabric.operations import run, put, get |
11 |
import fabric |
|
11 | 12 |
import re |
12 | 13 |
import os |
13 | 14 |
import shutil |
... | ... | |
98 | 99 |
debug(env.host, |
99 | 100 |
" * Package %s found in %s..." |
100 | 101 |
% (package, env.env.packages)) |
101 |
put(deb, "/tmp/") |
|
102 |
try_put(deb, "/tmp/")
|
|
102 | 103 |
try_run("dpkg -i /tmp/%s || " |
103 | 104 |
% os.path.basename(deb) + apt_get + "-f") |
104 | 105 |
try_run("rm /tmp/%s" % os.path.basename(deb)) |
... | ... | |
183 | 184 |
"domain": env.env.domain, |
184 | 185 |
} |
185 | 186 |
custom = customize_settings_from_tmpl(tmpl, replace) |
186 |
put(custom, tmpl) |
|
187 |
try_put(custom, tmpl)
|
|
187 | 188 |
|
188 | 189 |
try_run("mkdir -p /etc/bind/zones") |
189 | 190 |
tmpl = "/etc/bind/zones/example.com" |
... | ... | |
193 | 194 |
} |
194 | 195 |
custom = customize_settings_from_tmpl(tmpl, replace) |
195 | 196 |
remote = "/etc/bind/zones/" + env.env.domain |
196 |
put(custom, remote) |
|
197 |
try_put(custom, remote)
|
|
197 | 198 |
|
198 | 199 |
try_run("mkdir -p /etc/bind/rev") |
199 | 200 |
tmpl = "/etc/bind/rev/synnefo.in-addr.arpa.zone" |
... | ... | |
201 | 202 |
"domain": env.env.domain, |
202 | 203 |
} |
203 | 204 |
custom = customize_settings_from_tmpl(tmpl, replace) |
204 |
put(custom, tmpl) |
|
205 |
try_put(custom, tmpl)
|
|
205 | 206 |
|
206 | 207 |
tmpl = "/etc/bind/named.conf.options" |
207 | 208 |
replace = { |
208 | 209 |
"NODE_IPS": ";".join(env.env.ips), |
209 | 210 |
} |
210 | 211 |
custom = customize_settings_from_tmpl(tmpl, replace) |
211 |
put(custom, tmpl, mode=0644) |
|
212 |
try_put(custom, tmpl, mode=0644)
|
|
212 | 213 |
|
213 | 214 |
for role, info in env.env.roles.iteritems(): |
214 | 215 |
if role == "ns": |
... | ... | |
225 | 226 |
def check_dhcp(): |
226 | 227 |
debug(env.host, "Checking IPs for synnefo..") |
227 | 228 |
for n, info in env.env.nodes_info.iteritems(): |
228 |
try_run("ping -c 1 " + info.ip, True)
|
|
229 |
try_run("ping -c 1 " + info.ip) |
|
229 | 230 |
|
230 | 231 |
|
231 | 232 |
@roles("nodes") |
232 | 233 |
def check_dns(): |
233 | 234 |
debug(env.host, "Checking fqdns for synnefo..") |
234 | 235 |
for n, info in env.env.nodes_info.iteritems(): |
235 |
try_run("ping -c 1 " + info.fqdn, True)
|
|
236 |
try_run("ping -c 1 " + info.fqdn) |
|
236 | 237 |
|
237 | 238 |
for n, info in env.env.roles.iteritems(): |
238 |
try_run("ping -c 1 " + info.fqdn, True)
|
|
239 |
try_run("ping -c 1 " + info.fqdn) |
|
239 | 240 |
|
240 | 241 |
|
241 | 242 |
@roles("nodes") |
242 | 243 |
def check_connectivity(): |
243 | 244 |
debug(env.host, "Checking internet connectivity..") |
244 |
try_run("ping -c 1 www.google.com", True)
|
|
245 |
try_run("ping -c 1 www.google.com") |
|
245 | 246 |
|
246 | 247 |
|
247 | 248 |
@roles("nodes") |
248 | 249 |
def check_ssh(): |
249 | 250 |
debug(env.host, "Checking password-less ssh..") |
250 | 251 |
for n, info in env.env.nodes_info.iteritems(): |
251 |
try_run("ssh " + info.fqdn + " date", True)
|
|
252 |
try_run("ssh " + info.fqdn + " date") |
|
252 | 253 |
|
253 | 254 |
|
254 | 255 |
@roles("ips") |
... | ... | |
271 | 272 |
tmpl = "/root/.ssh/" + f |
272 | 273 |
replace = {} |
273 | 274 |
custom = customize_settings_from_tmpl(tmpl, replace) |
274 |
put(custom, tmpl, mode=0600) |
|
275 |
try_put(custom, tmpl, mode=0600)
|
|
275 | 276 |
|
276 | 277 |
cmd = """ |
277 | 278 |
if [ -e /root/.ssh/authorized_keys.bak ]; then |
... | ... | |
285 | 286 |
@roles("ips") |
286 | 287 |
def setup_resolv_conf(): |
287 | 288 |
debug(env.host, "Tweak /etc/resolv.conf...") |
288 |
try_run("/etc/init.d/network-manager stop") |
|
289 |
try_run("/etc/init.d/network-manager stop", abort=False)
|
|
289 | 290 |
tmpl = "/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate" |
290 | 291 |
replace = {} |
291 | 292 |
custom = customize_settings_from_tmpl(tmpl, replace) |
292 |
put(custom, tmpl, mode=0644) |
|
293 |
try_put(custom, tmpl, mode=0644)
|
|
293 | 294 |
try_run("cp /etc/resolv.conf /etc/resolv.conf.bak") |
294 | 295 |
tmpl = "/etc/resolv.conf" |
295 | 296 |
replace = { |
... | ... | |
298 | 299 |
} |
299 | 300 |
custom = customize_settings_from_tmpl(tmpl, replace) |
300 | 301 |
try: |
301 |
put(custom, tmpl) |
|
302 |
try_put(custom, tmpl)
|
|
302 | 303 |
cmd = """ |
303 | 304 |
echo "\ |
304 | 305 |
# This has been generated automatically by snf-deploy, at |
... | ... | |
329 | 330 |
try_run(cmd) |
330 | 331 |
|
331 | 332 |
|
332 |
def try_run(cmd, abort=False):
|
|
333 |
def try_run(cmd, abort=True):
|
|
333 | 334 |
try: |
334 | 335 |
if env.local: |
335 | 336 |
return local(cmd, capture=True) |
336 | 337 |
else: |
337 | 338 |
return run(cmd) |
338 |
except: |
|
339 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
339 |
except BaseException as e: |
|
340 |
if abort: |
|
341 |
fabric.utils.abort(e) |
|
342 |
else: |
|
343 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
344 |
raise |
|
345 |
|
|
346 |
|
|
347 |
def try_put(local_path=None, remote_path=None, abort=True, **kwargs): |
|
348 |
try: |
|
349 |
put(local_path=local_path, remote_path=remote_path, **kwargs) |
|
350 |
except BaseException as e: |
|
340 | 351 |
if abort: |
352 |
fabric.utils.abort(e) |
|
353 |
else: |
|
354 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
355 |
raise |
|
356 |
|
|
357 |
|
|
358 |
def try_get(remote_path, local_path=None, abort=True, **kwargs): |
|
359 |
try: |
|
360 |
get(remote_path, local_path=local_path, **kwargs) |
|
361 |
except BaseException as e: |
|
362 |
if abort: |
|
363 |
fabric.utils.abort(e) |
|
364 |
else: |
|
365 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
341 | 366 |
raise |
342 | 367 |
|
343 | 368 |
|
... | ... | |
405 | 430 |
tmpl = "/etc/apt/sources.list.d/synnefo.wheezy.list" |
406 | 431 |
replace = {} |
407 | 432 |
custom = customize_settings_from_tmpl(tmpl, replace) |
408 |
put(custom, tmpl) |
|
433 |
try_put(custom, tmpl)
|
|
409 | 434 |
apt_get_update() |
410 | 435 |
|
411 | 436 |
|
... | ... | |
422 | 447 |
tmpl = "/etc/gunicorn.d/synnefo" |
423 | 448 |
replace = {} |
424 | 449 |
custom = customize_settings_from_tmpl(tmpl, replace) |
425 |
put(custom, tmpl, mode=0644) |
|
450 |
try_put(custom, tmpl, mode=0644)
|
|
426 | 451 |
try_run("/etc/init.d/gunicorn restart") |
427 | 452 |
|
428 | 453 |
|
... | ... | |
435 | 460 |
"HOST": host_info.fqdn, |
436 | 461 |
} |
437 | 462 |
custom = customize_settings_from_tmpl(tmpl, replace) |
438 |
put(custom, tmpl) |
|
463 |
try_put(custom, tmpl)
|
|
439 | 464 |
tmpl = "/etc/apache2/sites-available/synnefo-ssl" |
440 | 465 |
custom = customize_settings_from_tmpl(tmpl, replace) |
441 |
put(custom, tmpl) |
|
466 |
try_put(custom, tmpl)
|
|
442 | 467 |
cmd = """ |
443 | 468 |
a2enmod ssl |
444 | 469 |
a2enmod rewrite |
... | ... | |
493 | 518 |
"synnefo_db_passwd": env.env.synnefo_db_passwd, |
494 | 519 |
} |
495 | 520 |
custom = customize_settings_from_tmpl(tmpl, replace) |
496 |
put(custom, tmpl) |
|
521 |
try_put(custom, tmpl)
|
|
497 | 522 |
cmd = 'su - postgres -c "psql -w -f %s" ' % tmpl |
498 | 523 |
try_run(cmd) |
499 | 524 |
cmd = """ |
... | ... | |
535 | 560 |
"domain": env.env.domain, |
536 | 561 |
} |
537 | 562 |
custom = customize_settings_from_tmpl(tmpl, replace) |
538 |
put(custom, tmpl, mode=0644) |
|
563 |
try_put(custom, tmpl, mode=0644)
|
|
539 | 564 |
with settings(host_string=env.env.db.ip): |
540 | 565 |
host_info = env.env.ips_info[env.host] |
541 | 566 |
allow_access_in_db(host_info.ip, "all", "trust") |
... | ... | |
559 | 584 |
"MAIL_DIR": env.env.mail_dir, |
560 | 585 |
} |
561 | 586 |
custom = customize_settings_from_tmpl(tmpl, replace) |
562 |
put(custom, tmpl, mode=0644) |
|
587 |
try_put(custom, tmpl, mode=0644)
|
|
563 | 588 |
try_run("mkdir -p {0}; chown root:www-data {0}; chmod 775 {0}".format( |
564 | 589 |
env.env.mail_dir)) |
565 | 590 |
try_run("/etc/init.d/gunicorn restart") |
... | ... | |
644 | 669 |
"PITHOS": env.env.pithos.fqdn, |
645 | 670 |
} |
646 | 671 |
custom = customize_settings_from_tmpl(tmpl, replace) |
647 |
put(custom, tmpl, mode=0644) |
|
672 |
try_put(custom, tmpl, mode=0644)
|
|
648 | 673 |
if env.csrf_disable: |
649 | 674 |
cmd = """ |
650 | 675 |
cat <<EOF >> /etc/synnefo/astakos.conf |
... | ... | |
709 | 734 |
tmpl = "/tmp/sites.json" |
710 | 735 |
replace = {} |
711 | 736 |
custom = customize_settings_from_tmpl(tmpl, replace) |
712 |
put(custom, tmpl) |
|
737 |
try_put(custom, tmpl)
|
|
713 | 738 |
|
714 | 739 |
tmpl = "/tmp/page.json" |
715 | 740 |
replace = {} |
716 | 741 |
custom = customize_settings_from_tmpl(tmpl, replace) |
717 |
put(custom, tmpl) |
|
742 |
try_put(custom, tmpl)
|
|
718 | 743 |
|
719 | 744 |
cmd = """ |
720 | 745 |
snf-manage loaddata /tmp/sites.json |
... | ... | |
742 | 767 |
"ACCOUNTS": env.env.accounts.fqdn, |
743 | 768 |
} |
744 | 769 |
custom = customize_settings_from_tmpl(tmpl, replace) |
745 |
put(custom, tmpl, mode=0644) |
|
770 |
try_put(custom, tmpl, mode=0644)
|
|
746 | 771 |
try_run("/etc/init.d/gunicorn restart") |
747 | 772 |
|
748 | 773 |
cmd = """ |
... | ... | |
797 | 822 |
"ip": ip, |
798 | 823 |
} |
799 | 824 |
custom = customize_settings_from_tmpl(tmpl, replace) |
800 |
put(custom, tmpl) |
|
825 |
try_put(custom, tmpl)
|
|
801 | 826 |
try_run("cat %s >> /etc/exports" % tmpl) |
802 | 827 |
try_run("/etc/init.d/nfs-kernel-server restart") |
803 | 828 |
|
... | ... | |
837 | 862 |
"proxy": env.env.pithos.hostname == env.env.accounts.hostname |
838 | 863 |
} |
839 | 864 |
custom = customize_settings_from_tmpl(tmpl, replace) |
840 |
put(custom, tmpl, mode=0644) |
|
865 |
try_put(custom, tmpl, mode=0644)
|
|
841 | 866 |
try_run("/etc/init.d/gunicorn restart") |
842 | 867 |
|
843 | 868 |
install_package("snf-pithos-webclient") |
... | ... | |
847 | 872 |
"PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE": service_id, |
848 | 873 |
} |
849 | 874 |
custom = customize_settings_from_tmpl(tmpl, replace) |
850 |
put(custom, tmpl, mode=0644) |
|
875 |
try_put(custom, tmpl, mode=0644)
|
|
851 | 876 |
|
852 | 877 |
try_run("/etc/init.d/gunicorn restart") |
853 | 878 |
#TOFIX: the previous command lets pithos-backend create blocks and maps |
... | ... | |
1010 | 1035 |
"db_node": env.env.db.ip, |
1011 | 1036 |
} |
1012 | 1037 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1013 |
put(custom, tmpl) |
|
1038 |
try_put(custom, tmpl)
|
|
1014 | 1039 |
|
1015 | 1040 |
|
1016 | 1041 |
@roles("ganeti") |
... | ... | |
1036 | 1061 |
"mq_node": env.env.mq.ip, |
1037 | 1062 |
} |
1038 | 1063 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1039 |
put(custom, tmpl) |
|
1064 |
try_put(custom, tmpl)
|
|
1040 | 1065 |
|
1041 | 1066 |
cmd = """ |
1042 | 1067 |
sed -i 's/false/true/' /etc/default/snf-ganeti-eventd |
... | ... | |
1075 | 1100 |
"ns_node_ip": env.env.ns.ip |
1076 | 1101 |
} |
1077 | 1102 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1078 |
put(custom, tmpl) |
|
1103 |
try_put(custom, tmpl)
|
|
1079 | 1104 |
try_run("/etc/init.d/nfdhcpd restart") |
1080 | 1105 |
|
1081 | 1106 |
install_package("snf-network") |
... | ... | |
1146 | 1171 |
"proxy": env.env.cyclades.hostname == env.env.accounts.hostname |
1147 | 1172 |
} |
1148 | 1173 |
custom = customize_settings_from_tmpl(tmpl, replace) |
1149 |
put(custom, tmpl, mode=0644) |
|
1174 |
try_put(custom, tmpl, mode=0644)
|
|
1150 | 1175 |
try_run("/etc/init.d/gunicorn restart") |
1151 | 1176 |
|
1152 | 1177 |
cmd = """ |
... | ... | |
1223 | 1248 |
filename = "%s_services.json" % service |
1224 | 1249 |
cmd = "snf-manage service-export-%s > %s" % (service, filename) |
1225 | 1250 |
run(cmd) |
1226 |
get(filename, filename+".local") |
|
1251 |
try_get(filename, filename+".local")
|
|
1227 | 1252 |
|
1228 | 1253 |
|
1229 | 1254 |
@roles("accounts") |
... | ... | |
1231 | 1256 |
debug(env.host, " * Registering services to astakos...") |
1232 | 1257 |
for service in ["cyclades", "pithos", "astakos"]: |
1233 | 1258 |
filename = "%s_services.json" % service |
1234 |
put(filename + ".local", filename) |
|
1259 |
try_put(filename + ".local", filename)
|
|
1235 | 1260 |
cmd = "snf-manage service-import --json=%s" % filename |
1236 | 1261 |
run(cmd) |
1237 | 1262 |
|
Also available in: Unified diff