1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

ifupdown: networkinterfaces: not importing template engine if no mako keyword found

Ticket: CM-11807
Reviewed By: Roopa, Daniel
Testing Done:

Loading the default template engine (mako) is adding an extra overhead: 100ms
We also import the template engine even if we are dealing with a json input
The overhead is noticable when using NCLU.

With this change we are now important the template engine when a keyword is
found in the configuration file.

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
Julien Fortin
2016-07-14 20:09:42 +01:00
parent 60dfcbdf9c
commit e272efd9ab

View File

@ -60,8 +60,11 @@ class networkInterfaces():
self.interfacesfileiobuf = interfacesfileiobuf
self.interfacesfileformat = interfacesfileformat
self._filestack = [self.interfacesfile]
self._template_engine = templateEngine(template_engine,
template_lookuppath)
self._template_engine = None
self._template_engine_name = template_engine
self._template_engine_path = template_lookuppath
self._currentfile_has_template = False
self._ws_split_regex = re.compile(r'[\s\t]\s*')
@ -385,22 +388,25 @@ class networkInterfaces():
def read_filedata(self, filedata):
self._currentfile_has_template = False
# run through template engine
try:
rendered_filedata = self._template_engine.render(filedata)
if rendered_filedata is filedata:
self._currentfile_has_template = False
else:
self._currentfile_has_template = True
except Exception, e:
self._parse_error(self._currentfile, -1,
'failed to render template (%s). ' %str(e) +
'Continue without template rendering ...')
rendered_filedata = None
pass
if rendered_filedata:
self.process_interfaces(rendered_filedata)
else:
self.process_interfaces(filedata)
if filedata and '%' in filedata:
try:
self._template_engine = templateEngine(
self._template_engine_name,
self._template_engine_path)
rendered_filedata = self._template_engine.render(filedata)
if rendered_filedata is filedata:
self._currentfile_has_template = False
else:
self._currentfile_has_template = True
except Exception, e:
self._parse_error(self._currentfile, -1,
'failed to render template (%s). Continue without template rendering ...'
% str(e))
rendered_filedata = None
if rendered_filedata:
self.process_interfaces(rendered_filedata)
return
self.process_interfaces(filedata)
def read_file(self, filename, fileiobuf=None):
if fileiobuf: