1 # -*- coding: utf-8 -*-
4 # Copyright 2020 Telefonica S.A.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
20 from osm_lcm
.lcm_utils
import LcmException
21 from jinja2
import Template
, TemplateError
, TemplateNotFound
, TemplateSyntaxError
23 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
26 def parse_job(job_data
: str, variables
: dict) -> dict:
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("Error parsing Jinja2 to prometheus job. job_data={}, variables={}. Error={}".format(
34 job_data
, variables
, e
))