-
Notifications
You must be signed in to change notification settings - Fork 44
add post-process-filter attribute to text parser #59
add post-process-filter attribute to text parser #59
Conversation
Overall looks great :)
Sounds good, it's going to require some parsing but it should be fine. |
As I don't really want to reinvent a Jinja2 template parser I tried to make the value under
The value of For this to work I had to make a change in |
napalm_yang/parsers/text.py
Outdated
@@ -30,6 +31,13 @@ def _parse_list_block(cls, mapping): | |||
else: | |||
key = extra_vars.pop("key") | |||
|
|||
if post_process_filter: | |||
from napalm_yang.helpers import template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, move the import to the top of the file for consistenct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't :( I'll get a circular import in that case, because of:
https://github.com/napalm-automation/napalm-yang/blob/dbarrosop/include/napalm_yang/helpers.py#L3
I can split helpers.py
into two modules - one with functions dealing with YANG files/parsers (maybe keep them in helpers.py
) and another that resolves/renders rules (move _resolve_rule()
, resolve_rule()´ and
template()´ into rules.py
). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best solution would be to move get_parser
to here then:
@@ -30,6 +31,13 @@ def _parse_list_block(cls, mapping): | |||
else: | |||
key = extra_vars.pop("key") | |||
|
|||
if post_process_filter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind implementing this on the xmlparser as well, please?
Great idea :) Just had a couple of tiny little comments. Would be great if you could add a note to the docs as well. |
Thanks! I'll do xmlparser and docs later today. |
I have also moved this PR to |
Done! (hopefully :) Two questions regarding XMLParser:
|
That was a backwards compatibility hack when I was migrating the parsers from dicts to lists. We could remove it now. I will probably rewrite the parsers and try to simplify them so don't worry about that.
napalm-yang/napalm_yang/mappings/junos/parsers/config/openconfig-network-instance/includes/bgp.yaml Line 357 in fb1f90a
Line 13 in fb1f90a
:) |
This is great! Thanks for the PR :) |
Ah! Then I feel |
Yeah, makes sense. I am trying to improve the docs to spot this kind of inconsistencies and to make everything easier to understand (current docs are terrible). Still struggling so feedback is welcome: |
* develop: (74 commits) add post-process-filter attribute to text parser (napalm-automation#59) Allow each parser to modify native on start (napalm-automation#28) Updated CHANGELOG Updated docs Removed negate_recursively as it's unnecessary Added network-instance/junos translator Added reuse and replace_on_merge When using lists of actions allow advancing containers in xml Added _translate_leaf_map Added config parser for network-instances/junos Added missing key Various improvement to xml parser Minor fix to network-instance/eos Added tests for network-instance/eos Added network-instance parser/translator for EOS We can now remove elements recursively in cases where the nesting of YANG model doesnt reflect the nesting in native configuration Minor fixes to the logic of the lists Propagate attribute name rather than yang_name Adapted network instances model to lists Find translation point per rule as before ... Conflicts: napalm_yang/helpers.py napalm_yang/parser.py
As discussed on NTC slack.
Just the most basic version for now. Looking forward for notes :)
One thing that came to mind would be ability to pass arguments to jinja filters in DSL. And support the same syntax as Jinja2. Something like:
Where
truncate
is the name of the filter called and64
would be an extra argument passed to it along with the key.What do you think?