blob: ab9ec8cfdc631f2917135071841b5576aad5cc16 [file] [log] [blame]
gstepanov725cc302015-02-09 15:08:06 +02001import os
koder aka kdanilove06762a2015-03-22 23:32:09 +02002import yaml
koder aka kdanilov66839a92015-04-11 13:22:31 +03003
4from petname import Generate as pet_generate
gstepanov725cc302015-02-09 15:08:06 +02005
stgleb75c70412015-02-17 02:52:00 +02006
koder aka kdanilov66839a92015-04-11 13:22:31 +03007cfg_dict = {}
gstepanovc82391e2015-03-17 15:46:36 +02008
9
koder aka kdanilov66839a92015-04-11 13:22:31 +030010def load_config(file_name):
11 global cfg_dict
12 first_load = len(cfg_dict) == 0
13 cfg_dict.update(yaml.load(open(file_name).read()))
gstepanov5f936df2015-03-18 19:15:59 +020014
koder aka kdanilov66839a92015-04-11 13:22:31 +030015 if first_load:
16 var_dir = cfg_dict.get('internal', {}).get('var_dir_root', '/tmp')
gstepanov5f936df2015-03-18 19:15:59 +020017
koder aka kdanilov66839a92015-04-11 13:22:31 +030018 while True:
19 dr = os.path.join(var_dir, pet_generate(2, "_"))
20 if not os.path.exists(dr):
21 break
gstepanov5f936df2015-03-18 19:15:59 +020022
koder aka kdanilov66839a92015-04-11 13:22:31 +030023 cfg_dict['var_dir'] = dr
24 os.makedirs(cfg_dict['var_dir'])
gstepanov5f936df2015-03-18 19:15:59 +020025
koder aka kdanilov66839a92015-04-11 13:22:31 +030026 cfg_dict['charts_img_path'] = os.path.join(cfg_dict['var_dir'], 'charts')
27 os.makedirs(cfg_dict['charts_img_path'])
gstepanovb3c78962015-03-20 15:47:58 +020028
koder aka kdanilov66839a92015-04-11 13:22:31 +030029 cfg_dict['vm_ids_fname'] = os.path.join(cfg_dict['var_dir'], 'os_vm_ids')
30 cfg_dict['report'] = os.path.join(cfg_dict['var_dir'], 'report.html')
koder aka kdanilovf4b82c22015-04-11 13:35:25 +030031 cfg_dict['log_file'] = os.path.join(cfg_dict['var_dir'], 'log.txt')