Commit 2e6476b7 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

deploy: use execute() instead of fab

This way we have a unique execution environment between
snf-deploy script and fabfile. Arguments and options
are handled way more easily. Get rid of the twisted code
that was passing command line arguments to fabric.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent 3af3980e
......@@ -13,6 +13,8 @@ import subprocess
import imp
import ast
from snfdeploy.lib import *
from snfdeploy import fabfile
from fabric.api import hide, env, settings, local, roles, execute, show
def print_available_actions(command):
......@@ -243,51 +245,38 @@ def fabcommand(args, env, actions, nodes=[]):
"everything": ["warnings", "running", "user", "output"]
}
hide = ",".join(level_aliases["everything"])
show = None
lhide = level_aliases["everything"]
lshow = []
if args.verbose == 1:
show = ",".join(levels[:3])
hide = ",".join(levels[3:])
lshow = levels[:3]
lhide = levels[3:]
elif args.verbose == 2:
show = ",".join(levels[:4])
hide = ",".join(levels[4:])
lshow = levels[:4]
lhide = levels[4:]
elif args.verbose >= 3 or args.debug:
show = ",".join(levels)
hide = None
lshow = levels
lhide = []
if args.ssh_key:
fabcmd = "fab -i %s " % args.ssh_key
else:
fabcmd = "fab "
fabcmd += " --fabfile /usr/share/pyshared/snfdeploy/fabfile.py \
setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
autoconf={4},disable_colors={5},key_inject={6} \
".format(args.confdir, env.packages, env.templates, args.cluster_name,
args.autoconf, args.disable_colors, args.key_inject)
# fabcmd += " --fabfile {4}/fabfile.py \
# setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
# autoconf={5},disable_colors={6},key_inject={7} \
# ".format(args.confdir, env.packages, env.templates, args.cluster_name,
# env.lib, args.autoconf, args.disable_colors, args.key_inject)
if nodes:
hosts = [env.nodes_info[n].hostname for n in nodes]
actions = [a + ':hosts="%s"' % ";".join(hosts) for a in actions]
extra = " ".join(actions)
fabcmd += extra
if show:
fabcmd += " --show %s " % show
if hide:
fabcmd += " --hide %s " % hide
# print("snf-deploy run " + " ".join(actions) + " -vvv")
print(fabcmd)
ips = [env.nodes_info[n].ip for n in nodes]
if not args.dry_run:
ret = os.system(fabcmd)
if ret != 0:
status = "exit with status %s" % ret
sys.exit(status)
fabfile.setup_env(args)
with settings(hide(*lhide), show(*lshow)):
print " ".join(actions)
for a in actions:
fn = getattr(fabfile, a)
if not args.dry_run:
if nodes:
execute(fn, hosts=ips)
else:
execute(fn)
def cluster(args, env):
......@@ -572,7 +561,7 @@ def add_node(args, env):
def main():
args = parse_options()
conf = Conf.configure(args.confdir, args.cluster_name, args, args.autoconf)
conf = Conf(args)
env = Env(conf)
create_dir(env.run, False)
......
......@@ -18,28 +18,21 @@ from snfdeploy.lib import debug, Conf, Env, disable_color
from snfdeploy import massedit
def setup_env(confdir="conf", packages="packages", templates="files",
cluster_name="ganeti1", autoconf=False, disable_colors=False,
key_inject=False):
def setup_env(args):
"""Setup environment"""
print("Loading configuration for synnefo...")
print(" * Using config files under %s..." % confdir)
print(" * Using %s and %s for packages and templates accordingly..."
% (packages, templates))
autoconf = ast.literal_eval(autoconf)
disable_colors = ast.literal_eval(disable_colors)
env.key_inject = ast.literal_eval(key_inject)
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name,
autoconf=autoconf)
conf = Conf(args)
env.env = Env(conf)
env.local = autoconf
env.local = args.autoconf
env.key_inject = args.key_inject
env.password = env.env.password
env.user = env.env.user
env.shell = "/bin/bash -c"
env.key_filename = args.ssh_key
if disable_colors:
if args.disable_colors:
disable_color()
if env.env.cms.hostname in \
......
......@@ -146,14 +146,36 @@ class Conf(object):
"synnefo": ["cred", "synnefo", "roles"],
"squeeze": ["debian", "ganeti", "synnefo", "other"],
"wheezy": ["debian", "ganeti", "synnefo", "other"],
"ganeti": [],
}
confdir = "/etc/snf-deploy"
def __init__(self, confdir, cluster_name):
self.confdir = confdir
def get_ganeti(self, cluster_name):
self.files["ganeti"] = [cluster_name]
def __init__(self, args):
self.confdir = args.confdir
self.get_ganeti(args.cluster_name)
for f in self.files.keys():
setattr(self, f, self.read_config(f))
for f, sections in self.files.iteritems():
for s in sections:
for k, v in self.get_section(f, s):
if getattr(args, k, None):
self.set(f, s, k, getattr(args, k))
if args.autoconf:
self.autoconf()
def autoconf(self):
#domain = get_domain()
#if domain:
# self.nodes.set("network", "domain", get_domain())
# self.nodes.set("network", "subnet", "/".join(get_netinfo()))
# self.nodes.set("network", "gateway", get_default_route()[0])
self.nodes.set("hostnames", "node1", get_hostname())
self.nodes.set("ips", "node1", get_netinfo()[0])
self.nodes.set("info", "nodes", "node1")
self.nodes.set("info", "public_iface", get_default_route()[1])
def read_config(self, f):
config = ConfigParser.ConfigParser()
......@@ -178,37 +200,6 @@ class Conf(object):
for f in self.files.keys():
getattr(self, f).write(sys.stdout)
def _configure(self, args):
for f, sections in self.files.iteritems():
for s in sections:
for k, v in self.get_section(f, s):
if getattr(args, k, None):
self.set(f, s, k, getattr(args, k))
@classmethod
def configure(cls, confdir="/etc/snf-deploy",
cluster_name="ganeti1", args=None, autoconf=False):
conf = cls(confdir, cluster_name)
if args:
conf._configure(args)
if autoconf:
conf.autoconf()
return conf
def autoconf(self):
#domain = get_domain()
#if domain:
# self.nodes.set("network", "domain", get_domain())
# self.nodes.set("network", "subnet", "/".join(get_netinfo()))
# self.nodes.set("network", "gateway", get_default_route()[0])
self.nodes.set("hostnames", "node1", get_hostname())
self.nodes.set("ips", "node1", get_netinfo()[0])
self.nodes.set("info", "nodes", "node1")
self.nodes.set("info", "public_iface", get_default_route()[1])
def debug(host, msg):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment