-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
78 lines (56 loc) · 1.86 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import argparse
import yaml
import sys
import os
import logging
logger = logging.getLogger("cbt")
cluster = {}
benchmarks = {}
def initialize(ctx):
global cluster, benchmarks
config = {}
try:
with file(ctx.config_file) as f:
map(config.update, yaml.safe_load_all(f))
except IOError, e:
raise argparse.ArgumentTypeError(str(e))
cluster = config.get('cluster', {})
benchmarks = config.get('benchmarks', {})
if not cluster:
shutdown('No cluster section found in config file, bailing.')
if not benchmarks:
shutdown('No benchmarks section found in config file, bailing.')
# set the tmp_dir if not set.
if 'tmp_dir' not in cluster:
cluster['tmp_dir'] = '/tmp/cbt.%s' % os.getpid()
# set the ceph.conf file from the commandline, yaml, or default
if ctx.conf:
cluster['conf_file'] = ctx.conf
elif 'conf_file' not in cluster:
cluster['conf_file'] = "%s/ceph.conf" % (cluster.get('conf_file'),)
if ctx.archive:
cluster['archive_dir'] = ctx.archive
def getnodes(*nodelists):
nodes = []
for nodelist in nodelists:
cur = cluster.get(nodelist, [])
if isinstance(cur, str):
nodes.append(cur)
elif isinstance(cur, dict):
nodes.extend(cur.keys())
elif isinstance(cur, list):
nodes.extend(cur)
else:
raise ValueError("Can't process nodes of type %s - unknown set type: %r",
nodelist, cur)
str_nodes = ','.join(uniquenodes(nodes))
logger.debug("Nodes : %s", str_nodes)
return str_nodes
def uniquenodes(nodes):
ret = [node for node in nodes if node]
user = cluster.get('user')
if user is not None:
ret = ['%s@%s' % (user, node) for node in ret]
return set(ret)
def shutdown(message):
sys.exit(message)