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 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,15 +46,25 @@ metrics = {}
services = {} services = {}
keyRequests = {} keyRequests = {}
# methods # 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(): for template,metric in TEMPLATE_FILES.items():
print(set(metric)) if set(metrics) == set(metric):
print(set(metrics[environment])) return template
if set(metrics[environment]) == set(metric): print("Problem occured: Exiting program...")
return template,metric sys.exit(0)
else:
print("Lists do not match.")
# main
def main():
# read yaml file # read yaml file
with open(os.path.join(SLOS_FOLDER_BASENAME,SLO_FILE_BASENAME)) as f: 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): 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()