timmy/conf.py

55 lines
1.7 KiB
Python

import yaml
import logging
import sys
from nodefilter import NodeFilter
class Conf(object):
"""Configuration parameters"""
hard_filter = None
soft_filter = NodeFilter()
ssh = {'opts': '-oConnectTimeout=2 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=error -lroot -oBatchMode=yes',
'vars': 'OPENRC=/root/openrc IPTABLES_STR="iptables -nvL"'}
cluster = None
fuelip = 'localhost'
outdir = '/tmp/timmy/info'
timeout = 15
rqdir = './rq'
compress_timeout = 3600
archives = '/tmp/timmy/archives'
cmds_archive = ''
log_files = {}
log_files['filter'] = {'default': {'include': '.log', 'exclude': None}}
log_files['path'] = '/var/log/'
def __init__(self, **entries):
self.__dict__.update(entries)
if 'hard_filter' in entries:
self.hard_filter = NodeFilter(**entries['hard_filter'])
if 'soft_filter' in entries:
self.soft_filter = NodeFilter(**entries['soft_filter'])
@staticmethod
def load_conf(filename):
try:
with open(filename, 'r') as f:
conf = yaml.load(f)
except IOError as e:
logging.error("I/O error(%s): %s" % (e.errno, e.strerror))
sys.exit(1)
except ValueError:
logging.error("Could not convert data")
sys.exit(1)
except yaml.parser.ParserError as e:
logging.error("Could not parse %s:\n%s" %(filename, str(e)))
sys.exit(1)
except:
logging.error("Unexpected error: %s" % sys.exc_info()[0])
sys.exit(1)
logging.info(conf)
return Conf(**conf)
if __name__ == '__main__':
conf = Conf.load_conf('config.yaml')
print(yaml.dump(conf))