working version

master
SLW\ARNAUA 2023-02-07 13:16:26 +01:00
parent 5186de078c
commit 5877926f5f
2 changed files with 71 additions and 54 deletions

View File

@ -6,10 +6,13 @@ import yaml
import os
from nested_lookup import nested_lookup
# pre-initialization get current working directory
cwd = os.getcwd()
# defines
METRIC_KEYS = 4
SLOS_FOLDER_BASENAME = os.path.basename("slos")
OUTPUT_FOLDER_BASENAME = os.path.basename("output")
TEMPLATE_FOLDER_BASENAME = os.path.basename("templates")
@ -25,9 +28,9 @@ TEMPLATE_FILES = {
"calc:service.vehicleservice_oes_fivexx_count",
"calc:service.vehicleservice_oes_request_count_total"]
}
SLO_FILE_BASENAME = os.path.basename("TP_FTS-example.yaml")
# define entries
slo_id = None
slo_name = None
@ -43,15 +46,25 @@ metrics = {}
services = {}
keyRequests = {}
# methods
def logic(metrics,environment,TEMPLATE_FILES):
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():
print(set(metric))
print(set(metrics[environment]))
if set(metrics[environment]) == set(metric):
return template,metric
else:
print("Lists do not match.")
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:
@ -88,7 +101,8 @@ for e,environment in enumerate(environments):
if not os.path.exists(folder_path):
os.makedirs(folder_path)
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)
file.write(jinja_template.render(module=module_name,
slo_name=slo_name,
@ -102,3 +116,6 @@ for e,environment in enumerate(environments):
keyRequest=keyRequests[environment],
target=slo_definition_tresholds_failure,
warning=slo_definition_tresholds_warning))
if __name__ == "__main__":
main()