Revision 68d6d24b
b/snf-deploy/snfdeploy/fabfile.py | ||
---|---|---|
15 | 15 |
import tempfile |
16 | 16 |
import ast |
17 | 17 |
from snfdeploy.lib import debug, Conf, Env, disable_color |
18 |
from snfdeploy.utils import * |
|
18 | 19 |
from snfdeploy import massedit |
19 | 20 |
|
20 | 21 |
|
... | ... | |
77 | 78 |
}) |
78 | 79 |
|
79 | 80 |
|
80 |
def install_package(package): |
|
81 |
debug(env.host, " * Installing package %s..." % package) |
|
82 |
apt_get = "export DEBIAN_FRONTEND=noninteractive ;" + \ |
|
83 |
"apt-get install -y --force-yes " |
|
84 |
|
|
85 |
host_info = env.env.ips_info[env.host] |
|
86 |
env.env.update_packages(host_info.os) |
|
87 |
if ast.literal_eval(env.env.use_local_packages): |
|
88 |
with settings(warn_only=True): |
|
89 |
deb = local("ls %s/%s*%s_*.deb" |
|
90 |
% (env.env.packages, package, host_info.os), |
|
91 |
capture=True) |
|
92 |
if deb: |
|
93 |
debug(env.host, |
|
94 |
" * Package %s found in %s..." |
|
95 |
% (package, env.env.packages)) |
|
96 |
try_put(deb, "/tmp/") |
|
97 |
try_run("dpkg -i /tmp/%s || " |
|
98 |
% os.path.basename(deb) + apt_get + "-f") |
|
99 |
try_run("rm /tmp/%s" % os.path.basename(deb)) |
|
100 |
return |
|
101 |
|
|
102 |
info = getattr(env.env, package) |
|
103 |
if info in \ |
|
104 |
["squeeze-backports", "squeeze", "stable", |
|
105 |
"testing", "unstable", "wheezy"]: |
|
106 |
apt_get += " -t %s %s " % (info, package) |
|
107 |
elif info: |
|
108 |
apt_get += " %s=%s " % (package, info) |
|
109 |
else: |
|
110 |
apt_get += package |
|
111 |
|
|
112 |
try_run(apt_get) |
|
113 |
|
|
114 |
return |
|
115 |
|
|
116 |
|
|
117 | 81 |
@roles("ns") |
118 | 82 |
def update_ns_for_ganeti(): |
119 | 83 |
debug(env.host, |
... | ... | |
324 | 288 |
try_run(cmd) |
325 | 289 |
|
326 | 290 |
|
327 |
def try_run(cmd, abort=True): |
|
328 |
try: |
|
329 |
if env.local: |
|
330 |
return local(cmd, capture=True) |
|
331 |
else: |
|
332 |
return run(cmd) |
|
333 |
except BaseException as e: |
|
334 |
if abort: |
|
335 |
fabric.utils.abort(e) |
|
336 |
else: |
|
337 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
338 |
|
|
339 |
|
|
340 |
def try_put(local_path=None, remote_path=None, abort=True, **kwargs): |
|
341 |
try: |
|
342 |
put(local_path=local_path, remote_path=remote_path, **kwargs) |
|
343 |
except BaseException as e: |
|
344 |
if abort: |
|
345 |
fabric.utils.abort(e) |
|
346 |
else: |
|
347 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
348 |
|
|
349 |
|
|
350 |
def try_get(remote_path, local_path=None, abort=True, **kwargs): |
|
351 |
try: |
|
352 |
get(remote_path, local_path=local_path, **kwargs) |
|
353 |
except BaseException as e: |
|
354 |
if abort: |
|
355 |
fabric.utils.abort(e) |
|
356 |
else: |
|
357 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
358 |
|
|
359 |
|
|
360 | 291 |
def create_bridges(): |
361 | 292 |
debug(env.host, " * Creating bridges...") |
362 | 293 |
install_package("bridge-utils") |
... | ... | |
393 | 324 |
try_run(cmd) |
394 | 325 |
|
395 | 326 |
|
396 |
def customize_settings_from_tmpl(tmpl, replace): |
|
397 |
debug(env.host, " * Customizing template %s..." % tmpl) |
|
398 |
local = env.env.templates + tmpl |
|
399 |
_, custom = tempfile.mkstemp() |
|
400 |
shutil.copyfile(local, custom) |
|
401 |
for k, v in replace.iteritems(): |
|
402 |
regex = "re.sub('%{0}%', '{1}', line)".format(k.upper(), v) |
|
403 |
massedit.edit_files([custom], [regex], dry_run=False) |
|
404 |
|
|
405 |
return custom |
|
406 |
|
|
407 |
|
|
408 | 327 |
@roles("nodes") |
409 | 328 |
def setup_apt(): |
410 | 329 |
debug(env.host, "Setting up apt sources...") |
b/snf-deploy/snfdeploy/utils.py | ||
---|---|---|
1 |
from __future__ import with_statement |
|
2 |
from fabric.api import hide, env, settings, local, roles |
|
3 |
from fabric.operations import run, put, get |
|
4 |
import fabric |
|
5 |
import re |
|
6 |
import os |
|
7 |
import shutil |
|
8 |
import tempfile |
|
9 |
import ast |
|
10 |
from snfdeploy.lib import debug, Conf, Env, disable_color |
|
11 |
from snfdeploy import massedit |
|
12 |
|
|
13 |
|
|
14 |
def abort(action): |
|
15 |
def inner(*args, **kwargs): |
|
16 |
try: |
|
17 |
return action(*args, **kwargs) |
|
18 |
except BaseException as e: |
|
19 |
abort = kwargs.get("abort", True) |
|
20 |
if not abort: |
|
21 |
debug(env.host, "WARNING: command failed. Continuing anyway...") |
|
22 |
else: |
|
23 |
fabric.utils.abort(e) |
|
24 |
return inner |
|
25 |
|
|
26 |
|
|
27 |
@abort |
|
28 |
def try_get(remote_path, local_path=None, **kwargs): |
|
29 |
get(remote_path, local_path=local_path, **kwargs) |
|
30 |
|
|
31 |
|
|
32 |
@abort |
|
33 |
def try_put(local_path=None, remote_path=None, **kwargs): |
|
34 |
put(local_path=local_path, remote_path=remote_path, **kwargs) |
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
@abort |
|
39 |
def try_run(cmd, **kwargs): |
|
40 |
if env.local: |
|
41 |
return local(cmd, capture=True) |
|
42 |
else: |
|
43 |
return run(cmd) |
|
44 |
|
|
45 |
|
|
46 |
def install_package(package): |
|
47 |
debug(env.host, " * Installing package %s..." % package) |
|
48 |
apt_get = "export DEBIAN_FRONTEND=noninteractive ;" + \ |
|
49 |
"apt-get install -y --force-yes " |
|
50 |
|
|
51 |
host_info = env.env.ips_info[env.host] |
|
52 |
env.env.update_packages(host_info.os) |
|
53 |
if ast.literal_eval(env.env.use_local_packages): |
|
54 |
with settings(warn_only=True): |
|
55 |
deb = local("ls %s/%s*%s_*.deb" |
|
56 |
% (env.env.packages, package, host_info.os), |
|
57 |
capture=True) |
|
58 |
if deb: |
|
59 |
debug(env.host, |
|
60 |
" * Package %s found in %s..." |
|
61 |
% (package, env.env.packages)) |
|
62 |
try_put(deb, "/tmp/") |
|
63 |
try_run("dpkg -i /tmp/%s || " |
|
64 |
% os.path.basename(deb) + apt_get + "-f") |
|
65 |
try_run("rm /tmp/%s" % os.path.basename(deb)) |
|
66 |
return |
|
67 |
|
|
68 |
info = getattr(env.env, package) |
|
69 |
if info in \ |
|
70 |
["squeeze-backports", "squeeze", "stable", |
|
71 |
"testing", "unstable", "wheezy"]: |
|
72 |
apt_get += " -t %s %s " % (info, package) |
|
73 |
elif info: |
|
74 |
apt_get += " %s=%s " % (package, info) |
|
75 |
else: |
|
76 |
apt_get += package |
|
77 |
|
|
78 |
try_run(apt_get) |
|
79 |
|
|
80 |
return |
|
81 |
|
|
82 |
|
|
83 |
def customize_settings_from_tmpl(tmpl, replace): |
|
84 |
debug(env.host, " * Customizing template %s..." % tmpl) |
|
85 |
local = env.env.templates + tmpl |
|
86 |
_, custom = tempfile.mkstemp() |
|
87 |
shutil.copyfile(local, custom) |
|
88 |
for k, v in replace.iteritems(): |
|
89 |
regex = "re.sub('%{0}%', '{1}', line)".format(k.upper(), v) |
|
90 |
massedit.edit_files([custom], [regex], dry_run=False) |
|
91 |
|
|
92 |
return custom |
|
93 |
|
|
94 |
|
Also available in: Unified diff