Fixes VCA deletion in NS termination
[osm/LCM.git] / osm_lcm / prometheus.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2020 Telefonica S.A.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17 ##
18
19 import yaml
20 from osm_lcm.lcm_utils import LcmException
21 from jinja2 import Template, TemplateError, TemplateNotFound, TemplateSyntaxError
22
23 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
24
25
26 def parse_job(job_data: str, variables: dict) -> dict:
27 try:
28 template = Template(job_data)
29 job_parsed = template.render(variables or {})
30 return yaml.safe_load(job_parsed)
31 except (TemplateError, TemplateNotFound, TemplateSyntaxError) as e:
32 # TODO yaml exceptions
33 raise LcmException(
34 "Error parsing Jinja2 to prometheus job. job_data={}, variables={}. Error={}".format(
35 job_data, variables, e
36 )
37 )