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

deploy: Cleanup lib module

Remove unused Env, Status, Conf classes. Host and Alias classes have
been substituted by FQDN. The latter will be used for Node and
Cluster info.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent d783fd6e
#!/usr/bin/python
# Copyright (C) 2010-2014 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
......@@ -16,16 +14,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import time
import ipaddr
import os
import signal
import ConfigParser
import sys
import re
import random
import subprocess
import imp
import ast
HEADER = '\033[95m'
OKBLUE = '\033[94m'
......@@ -55,235 +51,59 @@ if not sys.stdout.isatty():
disable_color()
class Host(object):
def __init__(self, hostname, ip, mac, domain, os, passwd):
self.hostname = hostname
self.ip = ip
self.mac = mac
self.domain = domain
self.os = os
self.passwd = passwd
def evaluate(some_object, **kwargs):
for k, v in kwargs.items():
setattr(some_object, k, v)
@property
def fqdn(self):
return self.hostname + "." + self.domain
@property
def arecord(self):
return self.fqdn + " 300 A " + self.ip
def getlist(value):
return list(filter(None, (x.strip() for x in value.splitlines())))
@property
def ptrrecord(self):
return ".".join(raddr(self.ip)) + ".in-addr.arpa 300 PTR " + self.fqdn
@property
def cnamerecord(self):
return ""
def getbool(value):
return ast.literal_eval(value)
class Alias(Host):
def __init__(self, host, alias):
super(Alias, self).__init__(host.hostname, host.ip, host.mac,
host.domain, host.os, host.passwd)
class FQDN(object):
def __init__(self, alias=None, **kwargs):
self.alias = alias
evaluate(self, **kwargs)
self.hostname = self.name
@property
def cnamerecord(self):
return self.fqdn + " 300 CNAME " + self.hostname + "." + self.domain
@property
def ptrrecord(self):
return ""
def fqdn(self):
return self.name + "." + self.domain
@property
def arecord(self):
return ""
return self.fqdn + " 300 A " + self.ip
@property
def fqdn(self):
return self.alias + "." + self.domain
class Env(object):
def update_packages(self, os):
for section in self.conf.files[os]:
self.evaluate(os, section)
def evaluate(self, filename, section):
for k, v in self.conf.get_section(filename, section):
setattr(self, k, v)
def __init__(self, conf):
self.conf = conf
for f, sections in conf.files.iteritems():
for s in sections:
self.evaluate(f, s)
self.node2hostname = dict(conf.get_section("nodes", "hostnames"))
self.node2ip = dict(conf.get_section("nodes", "ips"))
self.node2mac = dict(conf.get_section("nodes", "macs"))
self.node2os = dict(conf.get_section("nodes", "os"))
self.node2passwd = dict(conf.get_section("nodes", "passwords"))
self.hostnames = [self.node2hostname[n]
for n in self.nodes.split(",")]
self.ips = [self.node2ip[n]
for n in self.nodes.split(",")]
self.net = ipaddr.IPNetwork(self.subnet)
self.nodes_info = {}
self.hosts_info = {}
self.ips_info = {}
for node in self.nodes.split(","):
host = Host(self.node2hostname[node],
self.node2ip[node],
self.node2mac[node], self.domain, self.node2os[node],
self.node2passwd[node])
self.nodes_info[node] = host
self.hosts_info[host.hostname] = host
self.ips_info[host.ip] = host
self.cluster = Host(self.cluster_name, self.cluster_ip, None,
self.domain, None, None)
def ptrrecord(self):
return ".".join(raddr(self.ip)) + ".in-addr.arpa 300 PTR " + self.fqdn
# This is needed because "".split(",") -> ['']
if self.cluster_nodes:
self.cluster_nodes = self.cluster_nodes.split(",")
@property
def cnamerecord(self):
if self.cname:
return self.cname + " 300 CNAME " + self.fqdn
else:
self.cluster_nodes = []
self.cluster_hostnames = [self.node2hostname[n]
for n in self.cluster_nodes]
self.cluster_ips = [self.node2ip[n]
for n in self.cluster_nodes]
self.master = self.nodes_info[self.master_node]
self.roles_info = {}
for role, node in conf.get_section("synnefo", "roles"):
self.roles_info[role] = Alias(self.nodes_info[node], role)
setattr(self, role, self.roles_info[role])
self.astakos = self.accounts
# This is the nodes that get nfs mount points
self.mount = self.ips[:]
self.mount.remove(self.pithos.ip)
return ""
@property
def cname(self):
if self.alias:
return self.alias + "." + self.domain
else:
return ""
class Status(object):
STATUSES = [
"check",
"prepare",
"install",
"restart",
"initialize",
"test",
"ok",
]
def create_section(self, ip):
try:
section = self.config.items(ip, True)
except ConfigParser.NoSectionError:
self.config.add_section(ip)
def debug(*args):
def __init__(self, env):
self.config = ConfigParser.ConfigParser()
self.config.optionxform = str
self.statusfile = os.path.join(env.state, "snf_deploy_status")
self.config.read(self.statusfile)
def check_status(self, ip, component_class):
try:
return self.config.get(ip, component_class.__name__, True)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return None
def update_status(self, ip, component_class, status):
self.create_section(ip)
self.config.set(ip, component_class.__name__, status)
def write_status(self):
with open(self.statusfile, 'wb') as configfile:
self.config.write(configfile)
class Conf(object):
files = {
"nodes": ["network", "info"],
"deploy": ["dirs", "packages", "keys", "options"],
"vcluster": ["cluster", "image", "network"],
"synnefo": ["cred", "synnefo", "roles"],
"wheezy": ["debian", "ganeti", "synnefo", "other", "archip"],
}
confdir = "/etc/snf-deploy"
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))
# Override conf file settings if
# --templates-dir and --state-dir args are passed
if args.templatesdir:
self.deploy.set("dirs", "templates", args.templatesdir)
if args.statedir:
self.deploy.set("dirs", "state", args.statedir)
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()
config.optionxform = str
filename = os.path.join(self.confdir, f) + ".conf"
config.read(filename)
return config
def set(self, conf, section, option, value):
c = getattr(self, conf)
c.set(section, option, value)
def get(self, conf, section, option):
c = getattr(self, conf)
return c.get(section, option, True)
def get_section(self, conf, section):
c = getattr(self, conf)
return c.items(section, True)
def print_config(self):
for f in self.files.keys():
getattr(self, f).write(sys.stdout)
def debug(host, msg, info=""):
print " ".join([HEADER, host, OKBLUE, msg, OKGREEN, info, ENDC])
print " ".join([
HEADER, args[0],
OKBLUE, args[1],
OKGREEN, args[2],
ENDC])
def check_pidfile(pidfile):
......
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