Commit f6532cfc authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis
Browse files

deploy: Add config module

This module reads the configuration and includes
several methods for extracting info. It gets
initialized with the command line arguments.

It reads the DEFAULT section of synnefo, vcluster, and deploy conf
files and evaluates their options in a sense that once it gets
imported, one has easy access to generic configuration variables,
e.g. config.synnefo_user.

On the other hand the setups, nodes, ganeti and packages conf files
are proper ConfigParser files with sections and default values.

nodes: All info needed for each node.
ganeti: All info needed for each cluster.
setups: All role-nodes mappings for each setup and each cluster.
packages: All special package versions for each OS.

The get_info() helper method gets a node or cluster identifier
(e.g. node2, ganeti1) and returns a FQDN object with all related
options as attributes.

The get_package() helper method is used to get the special version
(if any) of a package.
Signed-off-by: default avatarDimitris Aragiorgis <>
parent 5cfb352a
# Copyright (C) 2010-2014 GRNET S.A.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
import ConfigParser
import sys
import os
import ipaddr
from snfdeploy.lib import evaluate, get_hostname, get_netinfo, \
get_default_route, getlist, getbool, disable_color, FQDN
config = sys.modules[__name__]
"nodes", "setups",
"synnefo", "ganeti",
"packages", "deploy", "vcluster",
def _autoconf():
return {
"name": get_hostname(),
"ip": get_netinfo()[0],
"public_iface": get_default_route()[1],
def _read_config(f):
cfg = ConfigParser.ConfigParser()
cfg.optionxform = str
filename = os.path.join(config.confdir, f) + ".conf"
return cfg
def get(setup_or_cluster, role):
assert setup_or_cluster and role
value = config.setups.get(setup_or_cluster, role)
return getlist(value)
def get_info(cluster=None, node=None):
if cluster:
return get_cluster_info(cluster)
if node:
return get_node_info(node)
def get_single_node_role_info(setup, role):
assert setup and role
nodes = get(setup, role)
assert len(nodes) == 1
return get_node_info(nodes[0])
def get_package(package, os="debian"):
return config.packages.get(os, package)
except ConfigParser.NoOptionError:
return None
def print_config():
for f in CONF_FILES:
getattr(config, f).write(sys.stdout)
def get_cluster_info(cluster):
options = dict(config.ganeti.items(cluster))
info = FQDN(**options)
return info
def _get_node_info(node):
info = dict(config.nodes.items(node))
if config.autoconf:
"node": node
return info
def get_node_info(node):
info = _get_node_info(node)
return FQDN(**info)
def init(args):
config.confdir = args.confdir
config.autoconf = args.autoconf
# Import all .conf files
for f in CONF_FILES:
setattr(config, f, _read_config(f))
# This is done here in order to have easy access
# to configuration options
evaluate(config, **config.deploy.defaults())
evaluate(config, **config.vcluster.defaults())
evaluate(config, **config.synnefo.defaults())
# Override conf file settings if
# --templates-dir and --state-dir args are passed
if args.template_dir:
config.template_dir = args.template_dir
if args.state_dir:
config.state_dir = args.state_dir
config.dry_run = args.dry_run
config.force = args.force
config.ssh_key = args.ssh_key
config.mem = args.mem
config.vnc = args.vnc
config.smp = args.smp
config.jsonfile = "/tmp/service.json"
if args.disable_colors:
config.testing_vm = getbool(config.testing_vm)
config.use_local_packages = getbool(config.use_local_packages)
config.create_extra_disk = getbool(config.create_extra_disk) = ipaddr.IPNetwork(config.subnet)
config.all_nodes = config.nodes.sections()
config.all_ips = [get_node_info(node).ip
for node in config.all_nodes]
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