working version
parent
5186de078c
commit
5877926f5f
55
convert.py
55
convert.py
|
|
@ -6,10 +6,13 @@ import yaml
|
||||||
import os
|
import os
|
||||||
from nested_lookup import nested_lookup
|
from nested_lookup import nested_lookup
|
||||||
|
|
||||||
|
|
||||||
# pre-initialization get current working directory
|
# pre-initialization get current working directory
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
# defines
|
# defines
|
||||||
|
METRIC_KEYS = 4
|
||||||
SLOS_FOLDER_BASENAME = os.path.basename("slos")
|
SLOS_FOLDER_BASENAME = os.path.basename("slos")
|
||||||
OUTPUT_FOLDER_BASENAME = os.path.basename("output")
|
OUTPUT_FOLDER_BASENAME = os.path.basename("output")
|
||||||
TEMPLATE_FOLDER_BASENAME = os.path.basename("templates")
|
TEMPLATE_FOLDER_BASENAME = os.path.basename("templates")
|
||||||
|
|
@ -25,9 +28,9 @@ TEMPLATE_FILES = {
|
||||||
"calc:service.vehicleservice_oes_fivexx_count",
|
"calc:service.vehicleservice_oes_fivexx_count",
|
||||||
"calc:service.vehicleservice_oes_request_count_total"]
|
"calc:service.vehicleservice_oes_request_count_total"]
|
||||||
}
|
}
|
||||||
|
|
||||||
SLO_FILE_BASENAME = os.path.basename("TP_FTS-example.yaml")
|
SLO_FILE_BASENAME = os.path.basename("TP_FTS-example.yaml")
|
||||||
|
|
||||||
|
|
||||||
# define entries
|
# define entries
|
||||||
slo_id = None
|
slo_id = None
|
||||||
slo_name = None
|
slo_name = None
|
||||||
|
|
@ -43,22 +46,32 @@ metrics = {}
|
||||||
services = {}
|
services = {}
|
||||||
keyRequests = {}
|
keyRequests = {}
|
||||||
|
|
||||||
# methods
|
|
||||||
def logic(metrics,environment,TEMPLATE_FILES):
|
|
||||||
for template,metric in TEMPLATE_FILES.items():
|
|
||||||
print(set(metric))
|
|
||||||
print(set(metrics[environment]))
|
|
||||||
if set(metrics[environment]) == set(metric):
|
|
||||||
return template,metric
|
|
||||||
else:
|
|
||||||
print("Lists do not match.")
|
|
||||||
|
|
||||||
# read yaml file
|
# methods
|
||||||
with open(os.path.join(SLOS_FOLDER_BASENAME,SLO_FILE_BASENAME)) as f:
|
def homogenize_metric_list(metrics):
|
||||||
|
for metric in metrics:
|
||||||
|
if len(metrics) < METRIC_KEYS:
|
||||||
|
metrics.append('')
|
||||||
|
return metrics
|
||||||
|
|
||||||
|
|
||||||
|
def template_logic(metrics,TEMPLATE_FILES):
|
||||||
|
for template,metric in TEMPLATE_FILES.items():
|
||||||
|
if set(metrics) == set(metric):
|
||||||
|
return template
|
||||||
|
print("Problem occured: Exiting program...")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
# main
|
||||||
|
def main():
|
||||||
|
|
||||||
|
# read yaml file
|
||||||
|
with open(os.path.join(SLOS_FOLDER_BASENAME,SLO_FILE_BASENAME)) as f:
|
||||||
slos = list(yaml.safe_load_all(f))
|
slos = list(yaml.safe_load_all(f))
|
||||||
|
|
||||||
# fill values
|
# fill values
|
||||||
for i,slo in enumerate(slos):
|
for i,slo in enumerate(slos):
|
||||||
slo_id = slo["slo_id"]
|
slo_id = slo["slo_id"]
|
||||||
slo_name = slo["slo_name"]
|
slo_name = slo["slo_name"]
|
||||||
module_name = re.sub(r'[^a-zA-Z ]+', '', slo_name).replace(' ', '_').replace('__', '_')
|
module_name = re.sub(r'[^a-zA-Z ]+', '', slo_name).replace(' ', '_').replace('__', '_')
|
||||||
|
|
@ -77,18 +90,19 @@ for i,slo in enumerate(slos):
|
||||||
keyRequests[environment] = '~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequests[environment]))
|
keyRequests[environment] = '~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequests[environment]))
|
||||||
environment = None
|
environment = None
|
||||||
|
|
||||||
# read template file
|
# read template file
|
||||||
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_FOLDER_BASENAME),
|
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_FOLDER_BASENAME),
|
||||||
trim_blocks=True,
|
trim_blocks=True,
|
||||||
lstrip_blocks=True)
|
lstrip_blocks=True)
|
||||||
|
|
||||||
# create template file
|
# create template file
|
||||||
for e,environment in enumerate(environments):
|
for e,environment in enumerate(environments):
|
||||||
folder_path = os.path.join(cwd,OUTPUT_FOLDER_BASENAME,environment.replace('-','_'),"slo")
|
folder_path = os.path.join(cwd,OUTPUT_FOLDER_BASENAME,environment.replace('-','_'),"slo")
|
||||||
if not os.path.exists(folder_path):
|
if not os.path.exists(folder_path):
|
||||||
os.makedirs(folder_path)
|
os.makedirs(folder_path)
|
||||||
with open(os.path.join(folder_path,module_name+".yaml"),"w+") as file:
|
with open(os.path.join(folder_path,module_name+".yaml"),"w+") as file:
|
||||||
t,m = logic(metrics,environment,TEMPLATE_FILES)
|
t = template_logic(metrics[environment],TEMPLATE_FILES)
|
||||||
|
m = homogenize_metric_list(metrics[environment])
|
||||||
jinja_template = jinja_environment.get_template(t)
|
jinja_template = jinja_environment.get_template(t)
|
||||||
file.write(jinja_template.render(module=module_name,
|
file.write(jinja_template.render(module=module_name,
|
||||||
slo_name=slo_name,
|
slo_name=slo_name,
|
||||||
|
|
@ -102,3 +116,6 @@ for e,environment in enumerate(environments):
|
||||||
keyRequest=keyRequests[environment],
|
keyRequest=keyRequests[environment],
|
||||||
target=slo_definition_tresholds_failure,
|
target=slo_definition_tresholds_failure,
|
||||||
warning=slo_definition_tresholds_warning))
|
warning=slo_definition_tresholds_warning))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue