Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Ignore _config_format
Browse files Browse the repository at this point in the history
For the moment...
Related to #118
  • Loading branch information
mirceaulinic committed Dec 22, 2016
1 parent 1853c06 commit 374a4d1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions napalm_base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@
from napalm_base.utils.jinja_filters import CustomJinjaFilters
from napalm_base.utils import py23_compat


# ----------------------------------------------------------------------------------------------------------------------
# helper classes -- will not be exported
# ----------------------------------------------------------------------------------------------------------------------


class _MACFormat(mac_unix):
pass


_MACFormat.word_fmt = '%.2X'


# ----------------------------------------------------------------------------------------------------------------------
# callable helpers
# ----------------------------------------------------------------------------------------------------------------------


def load_template(cls, template_name, template_source=None, template_path=None,
openconfig=False, **template_vars):
used_config_format = None
if hasattr(cls, '_config_format'):
# let's hack this
# if the user set a specific configuration format, override it to `text`
# when applying the native NAPALM template
used_config_format = cls._config_format
cls._config_format = 'text'
try:
if isinstance(template_source, py23_compat.string_types):
template = jinja2.Template(template_source)
Expand Down Expand Up @@ -65,6 +74,8 @@ def load_template(cls, template_name, template_source=None, template_path=None,
for filter_name, filter_function in CustomJinjaFilters.filters().items():
environment.filters[filter_name] = filter_function

# TODO: use the `used_config_format` variable to load the right file

template = environment.get_template('{template_name}.j2'.format(
template_name=template_name
))
Expand All @@ -83,7 +94,14 @@ def load_template(cls, template_name, template_source=None, template_path=None,
error=jinjaerr.message
)
)
return cls.load_merge_candidate(config=configuration)
else:
# all good, let's merge
cls.load_merge_candidate(config=configuration)
finally:
# no matter what, let's revert config format to the previous state
if used_config_format:
cls._config_format = used_config_format
return True


def textfsm_extractor(cls, template_name, raw_text):
Expand Down

0 comments on commit 374a4d1

Please sign in to comment.