prepared: filters for nodes
This commit is contained in:
parent
a4fe3aaaee
commit
9d2e0e83b6
49
conf.py
Normal file
49
conf.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
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-gen/info'
|
||||||
|
timeout = 15
|
||||||
|
logs_archive = '/tmp/timmy-logs.tar'
|
||||||
|
rqdir = './rq'
|
||||||
|
compress_timeout = 3600
|
||||||
|
find = {'template': "-name '*.gz' -o -name '*.log' -o -name '*-[0-9]4'",
|
||||||
|
'path': '/var/log/'}
|
||||||
|
|
||||||
|
def __init__(self, **entries):
|
||||||
|
self.__dict__.update(entries)
|
||||||
|
if self.hard_filter:
|
||||||
|
self.hard_filter = NodeFilter(**self.hard_filter)
|
||||||
|
if self.soft_filter:
|
||||||
|
self.soft_filter = NodeFilter(**self.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:
|
||||||
|
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))
|
@ -4,12 +4,13 @@ ssh:
|
|||||||
fuelip: 127.0.0.1
|
fuelip: 127.0.0.1
|
||||||
rqdir: ./rq
|
rqdir: ./rq
|
||||||
logdir: ./logs
|
logdir: ./logs
|
||||||
out-dir: ../timmy-ng/info
|
outdir: ../timmy-ng/info
|
||||||
node-status: ['ready']
|
soft_filter:
|
||||||
|
status: ['ready']
|
||||||
timeout: 15
|
timeout: 15
|
||||||
find:
|
find:
|
||||||
template: -name '*.log'
|
template: -name '*.log'
|
||||||
log-files:
|
log_files:
|
||||||
default: -name '*.log'
|
default: -name '*.log'
|
||||||
by-role:
|
by-role:
|
||||||
compute: -name '*.log'
|
compute: -name '*.log'
|
||||||
|
35
default.yaml
35
default.yaml
@ -1,17 +1,18 @@
|
|||||||
ssh:
|
conf:
|
||||||
opts: -oConnectTimeout=2 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=error -lroot -oBatchMode=yes
|
ssh:
|
||||||
vars: OPENRC=/root/openrc IPTABLES_STR="iptables -nvL"
|
opts: -oConnectTimeout=2 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=error -lroot -oBatchMode=yes
|
||||||
#cluster: 0
|
vars: OPENRC=/root/openrc IPTABLES_STR="iptables -nvL"
|
||||||
fuelip: localhost
|
#cluster: 0
|
||||||
out-dir: /tmp/timmy-gen/info
|
fuelip: localhost
|
||||||
timeout: 15
|
out-dir: /tmp/timmy-gen/info
|
||||||
node-status: ['ready', 'discover']
|
timeout: 15
|
||||||
find:
|
node-status: ['ready', 'discover']
|
||||||
template: -name '*.gz' -o -name '*.log' -o -name '*-[0-9]4'
|
find:
|
||||||
path: /var/log/
|
template: -name '*.gz' -o -name '*.log' -o -name '*-[0-9]4'
|
||||||
logs-archive: /tmp/timmy-logs.tar
|
path: /var/log/
|
||||||
compress-timeout: 3600
|
logs-archive: /tmp/timmy-logs.tar
|
||||||
log-files:
|
compress-timeout: 3600
|
||||||
template: -name '*.gz' -o -name '*.log' -o -name '*-[0-9]4'
|
log-files:
|
||||||
by-role: compute, controller, mongo, ceph
|
template: -name '*.gz' -o -name '*.log' -o -name '*-[0-9]4'
|
||||||
by-node-id: 0
|
by-role: compute, controller, mongo, ceph
|
||||||
|
by-node-id: 0
|
||||||
|
28
loadconf.py
28
loadconf.py
@ -1,28 +0,0 @@
|
|||||||
import yaml
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def load_conf(filename):
|
|
||||||
try:
|
|
||||||
with open('default.yaml', 'r') as f:
|
|
||||||
conf = yaml.load(f)
|
|
||||||
with open(filename, 'r') as f:
|
|
||||||
nc = yaml.load(f)
|
|
||||||
conf.update(nc)
|
|
||||||
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:
|
|
||||||
logging.error("Unexpected error: %s" % sys.exc_info()[0])
|
|
||||||
sys.exit(1)
|
|
||||||
logging.info(conf)
|
|
||||||
return conf
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
conf = load_conf('config.yaml')
|
|
||||||
print(conf)
|
|
9
nodefilter.py
Normal file
9
nodefilter.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class NodeFilter(object):
|
||||||
|
|
||||||
|
status = ['ready', 'discover']
|
||||||
|
online = True
|
||||||
|
roles = []
|
||||||
|
node_ids = []
|
||||||
|
def __init__(self, **entries):
|
||||||
|
self.__dict__.update(entries)
|
||||||
|
|
26
nodes.py
26
nodes.py
@ -239,20 +239,20 @@ class Nodes(object):
|
|||||||
"""Class nodes """
|
"""Class nodes """
|
||||||
|
|
||||||
def __init__(self, cluster, extended, conf, destdir, filename=None):
|
def __init__(self, cluster, extended, conf, destdir, filename=None):
|
||||||
self.dirname = conf['rqdir'].rstrip('/')
|
self.dirname = conf.rqdir.rstrip('/')
|
||||||
if (not os.path.exists(self.dirname)):
|
if (not os.path.exists(self.dirname)):
|
||||||
logging.error("directory %s doesn't exist" % (self.dirname))
|
logging.error("directory %s doesn't exist" % (self.dirname))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self.files = get_dir_structure(conf['rqdir'])[os.path.basename(self.dirname)]
|
self.files = get_dir_structure(conf.rqdir)[os.path.basename(self.dirname)]
|
||||||
self.fuelip = conf['fuelip']
|
self.fuelip = conf.fuelip
|
||||||
self.sshopts = conf['ssh']['opts']
|
self.sshopts = conf.ssh['opts']
|
||||||
self.sshvars = conf['ssh']['vars']
|
self.sshvars = conf.ssh['vars']
|
||||||
self.timeout = conf['timeout']
|
self.timeout = conf.timeout
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self.destdir = destdir
|
self.destdir = destdir
|
||||||
self.get_version()
|
self.get_version()
|
||||||
self.cluster = cluster
|
self.cluster = cluster
|
||||||
self.logdir = conf['logdir']
|
self.logdir = conf.logdir
|
||||||
self.extended = extended
|
self.extended = extended
|
||||||
logging.info('extended: %s' % self.extended)
|
logging.info('extended: %s' % self.extended)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
@ -290,6 +290,8 @@ class Nodes(object):
|
|||||||
ip=self.fuelip)
|
ip=self.fuelip)
|
||||||
self.nodes = {self.fuelip: node}
|
self.nodes = {self.fuelip: node}
|
||||||
for node in self.njdata:
|
for node in self.njdata:
|
||||||
|
if self.conf.hard_filter:
|
||||||
|
pass
|
||||||
node_roles = node.get('roles')
|
node_roles = node.get('roles')
|
||||||
if not node_roles:
|
if not node_roles:
|
||||||
roles = ['None']
|
roles = ['None']
|
||||||
@ -379,7 +381,7 @@ class Nodes(object):
|
|||||||
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
||||||
node.cluster != 0):
|
node.cluster != 0):
|
||||||
continue
|
continue
|
||||||
if node.status in self.conf['node-status'] and node.online:
|
if node.status in self.conf.soft_filter.status and node.online:
|
||||||
t = threading.Thread(target=node.exec_cmd,
|
t = threading.Thread(target=node.exec_cmd,
|
||||||
args=(label,
|
args=(label,
|
||||||
self.sshvars,
|
self.sshvars,
|
||||||
@ -400,7 +402,7 @@ class Nodes(object):
|
|||||||
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
||||||
node.cluster != 0):
|
node.cluster != 0):
|
||||||
continue
|
continue
|
||||||
if node.status in self.conf['node-status'] and node.online:
|
if node.status in self.conf.soft_filter.status and node.online:
|
||||||
t = threading.Thread(target=node.du_logs,
|
t = threading.Thread(target=node.du_logs,
|
||||||
args=(label,
|
args=(label,
|
||||||
self.sshopts,
|
self.sshopts,
|
||||||
@ -493,7 +495,7 @@ class Nodes(object):
|
|||||||
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
||||||
node.cluster != 0):
|
node.cluster != 0):
|
||||||
continue
|
continue
|
||||||
if node.status in self.conf['node-status'] and node.online:
|
if node.status in self.conf.soft_filter.status and node.online:
|
||||||
t = threading.Thread(target=node.get_files,
|
t = threading.Thread(target=node.get_files,
|
||||||
args=(label,
|
args=(label,
|
||||||
self.logdir,
|
self.logdir,
|
||||||
@ -520,7 +522,7 @@ class Nodes(object):
|
|||||||
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
if (self.cluster and str(self.cluster) != str(node.cluster) and
|
||||||
node.cluster != 0):
|
node.cluster != 0):
|
||||||
continue
|
continue
|
||||||
if (node.status in self.conf['node-status'] and
|
if (node.status in self.conf.soft_filter.status and
|
||||||
node.online and str(node.node_id) != '0'):
|
node.online and str(node.node_id) != '0'):
|
||||||
t = threading.Thread(target=node.get_files,
|
t = threading.Thread(target=node.get_files,
|
||||||
args=(label,
|
args=(label,
|
||||||
@ -603,7 +605,7 @@ def main(argv=None):
|
|||||||
destdir=args.dest_dir)
|
destdir=args.dest_dir)
|
||||||
# nodes.print_nodes()
|
# nodes.print_nodes()
|
||||||
nodes.get_node_file_list()
|
nodes.get_node_file_list()
|
||||||
nodes.calculate_log_size(conf['find']['template'])
|
nodes.calculate_log_size(conf.find['template'])
|
||||||
if nodes.is_enough_space():
|
if nodes.is_enough_space():
|
||||||
nodes.get_log_files(args.out_dir)
|
nodes.get_log_files(args.out_dir)
|
||||||
nodes.launch_ssh(args.out_dir)
|
nodes.launch_ssh(args.out_dir)
|
||||||
|
28
timmy.py
28
timmy.py
@ -19,7 +19,7 @@ import argparse
|
|||||||
import nodes
|
import nodes
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import loadconf
|
from conf import Conf
|
||||||
import flock
|
import flock
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
@ -60,32 +60,32 @@ def main(argv=None):
|
|||||||
loglevel = logging.INFO
|
loglevel = logging.INFO
|
||||||
logging.basicConfig(level=loglevel,
|
logging.basicConfig(level=loglevel,
|
||||||
format='%(asctime)s %(levelname)s %(message)s')
|
format='%(asctime)s %(levelname)s %(message)s')
|
||||||
conf = loadconf.load_conf(args.config)
|
config = Conf.load_conf(args.config)
|
||||||
n = nodes.Nodes(conf=conf,
|
n = nodes.Nodes(conf=config,
|
||||||
extended=args.extended,
|
extended=args.extended,
|
||||||
cluster=args.cluster,
|
cluster=args.cluster,
|
||||||
destdir=args.dest_file)
|
destdir=args.dest_file)
|
||||||
# nodes.print_nodes()
|
# nodes.print_nodes()
|
||||||
if not args.only_logs:
|
if not args.only_logs:
|
||||||
n.get_node_file_list()
|
n.get_node_file_list()
|
||||||
n.launch_ssh(conf['out-dir'])
|
n.launch_ssh(config.outdir)
|
||||||
n.get_conf_files(conf['out-dir'])
|
n.get_conf_files(config.outdir)
|
||||||
n.create_archive_general(conf['out-dir'], '/tmp/timmy-gen.tar.bz2', 60)
|
n.create_archive_general(config.outdir, '/tmp/timmy-gen.tar.bz2', 60)
|
||||||
if args.only_logs or args.getlogs:
|
if args.only_logs or args.getlogs:
|
||||||
lock = flock.FLock('/tmp/timmy-logs.lock')
|
lock = flock.FLock('/tmp/timmy-logs.lock')
|
||||||
if not lock.lock():
|
if not lock.lock():
|
||||||
logging.warning('Unable to obtain lock, skipping "logs"-part')
|
logging.warning('Unable to obtain lock, skipping "logs"-part')
|
||||||
return 1
|
return 1
|
||||||
n.get_node_file_list()
|
n.get_node_file_list()
|
||||||
n.calculate_log_size(conf['find']['template'])
|
n.calculate_log_size(config.find['template'])
|
||||||
if n.is_enough_space():
|
if n.is_enough_space():
|
||||||
n.get_log_files(conf['out-dir'])
|
n.get_log_files(config.outdir)
|
||||||
n.create_archive_logs(conf['find']['template'],
|
n.create_archive_logs(config.find['template'],
|
||||||
conf['logs-archive'],
|
config.logs_archive,
|
||||||
conf['compress-timeout'])
|
config.compress_timeout)
|
||||||
n.add_logs_archive(conf['out-dir'], nodes.lkey,
|
n.add_logs_archive(config.outdir, nodes.lkey,
|
||||||
conf['logs-archive'], 120)
|
config.logs_archive, 120)
|
||||||
n.compress_archive(conf['logs-archive'], conf['compress-timeout'])
|
n.compress_archive(config.logs_archive, config.compress_timeout)
|
||||||
|
|
||||||
n.print_nodes()
|
n.print_nodes()
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user