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

Commit

Permalink
Merge pull request #122 from napalm-automation/value_fixes
Browse files Browse the repository at this point in the history
Value fixes
  • Loading branch information
dbarrosop committed Feb 3, 2018
2 parents 3d64c55 + adfd750 commit 2b761fe
Show file tree
Hide file tree
Showing 51 changed files with 653 additions and 87 deletions.
62 changes: 62 additions & 0 deletions docs/_dynamic/examples_leaf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. _examples_leaf:

Examples - leaf
===============

{% for e in examples %}
{{ e.example.documentation.title }}
{{ "-" * e.example.documentation.title|length }}

{{ e.example.documentation.summary }}

Original data
_____________

.. code::

{{ e.mocked|indent }}

{{ e.example.documentation.data|default("") }}

Parser rule
___________

.. code-block:: yaml

{{ e.example.rule|to_yaml|indent }}

{{ e.example.documentation.rule|default("") }}

Result
______

{{ e.example.documentation.result|default("") }}

{% for case in e.example.data %}

Example {{loop.index}}
^^^^^^^^^^

.. code-block:: yaml

{{ case|to_yaml|indent }}

.. raw:: html

<div><table border="1" class="docutils">
<tr>
<th class="head">block</th>
<th class="head">value</th>
</tr>
<tbody>
{% for r in e.example.expected[loop.index0] %}
<tr>
<td style="vertical-align: top;">{{ e.example.blocks[loop.index0]|escape }}</pre></td>
<td style="vertical-align: top;">{{ r }}</pre></td>
</tr>
{% endfor %}
</tbody>
</table></div>

{% endfor %}
{% endfor %}
14 changes: 12 additions & 2 deletions docs/_dynamic/parser_directives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
On <b>lists</b> regexp will be applied over the key. Use it to filter results and capture extra data.</br>
On <b>leaves</b>, regexp will assign as value the capture group <code class="docutils literal">value</code>
- name: value
- name: pre
available_on: leaf
description: |
Post processing/formatting of the value
Pre processing/formatting of the value. Useful when you want to statically set it based on ``when`` conditions or from values extracted previously in parent containers/leaves/lists.
- name: post
available_on: leaf
description: |
Post processing/formatting of the value. Useful when you need to combine data extracted in a regular expression or post-process it with a jinja2 filter to transform the value.
- name: map
available_on: leaf
Expand All @@ -59,3 +64,8 @@
description: |
This attribute is specific to the XMLParser. XML documents can add information in the form of attributes.
You can complement a <code class="docutils literal">path</code> with this field to extract the attribute from the element found in <code class="docutils literal">path</code>.
- name: pdb
abialble_on: list, container, leaf
description: |
Start ``pdb`` for debugging.
1 change: 0 additions & 1 deletion docs/developers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ WIP. Information here is a bit chaotic, sorry about that.
:maxdepth: 1

profiles
profiles/index
writing_profiles
parsers/index
translators
Expand Down
7 changes: 6 additions & 1 deletion docs/developers/parsers/dynamic_directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@
<td style="vertical-align: top;"> list, leaf</td>
<td style="vertical-align: top;"> On <b>lists</b> regexp will be applied over the key. Use it to filter results and capture extra data.</br>
On <b>leaves</b>, regexp will assign as value the capture group <code class="docutils literal">value</code></td>
</tr>
<tr>
<th style="vertical-align: top;"> pre</th>
<td style="vertical-align: top;"> leaf</td>
<td style="vertical-align: top;"> Pre processing/formatting of the value. Useful when you want to statically set it based on ``when`` conditions or from values extracted previously in parent containers/leaves/lists.</td>
</tr>
<tr>
<th style="vertical-align: top;"> value</th>
<td style="vertical-align: top;"> leaf</td>
<td style="vertical-align: top;"> Post processing/formatting of the value</td>
<td style="vertical-align: top;"> Post processing/formatting of the value. Useful when you need to combine data extracted in a regular expression or post-process it with a jinja2 filter to transform the value.</td>
</tr>
<tr>
<th style="vertical-align: top;"> map</th>
Expand Down
183 changes: 183 additions & 0 deletions docs/developers/parsers/examples_leaf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
.. _examples_leaf:

Examples - leaf
===============

Parsing metric style for junos ISIS level
-----------------------------------------

Junos sometimes indicates the value of something not by using an element with a specific value but by the presence of it. For instance, the metric style of an ISIS level can either be NARROW or WIDE but instead of indicating explicitly junos will do it with the presence or not of the element ``</wide-metrics-only>``.


Original data
_____________

.. code::
<configuration>
<isis>
<level>
<name>1</name>
<wide-metrics-only/>
</level>
<level>
<name>2</name>
<preference>50</preference>
</level>
<interface>
<name>ge-0/0/0.0</name>
<point-to-point/>
</interface>
<interface>
<name>ge-0/0/1.0</name>
<point-to-point/>
</interface>
<interface>
<name>ge-0/0/2.0</name>
<point-to-point/>
</interface>
<interface>
<name>ge-0/0/3.0</name>
<point-to-point/>
</interface>
<interface>
<name>lo0.0</name>
</interface>
</isis>
</configuration>
Parser rule
___________

.. code-block:: yaml
- default: NARROW_METRIC
path: wide-metrics-only
post: WIDE_METRIC
present: true
Result
______




Example 1
^^^^^^^^^^

.. code-block:: yaml
extra_vars: {}
keys: {}
.. raw:: html

<div><table border="1" class="docutils">
<tr>
<th class="head">block</th>
<th class="head">value</th>
</tr>
<tbody>
<tr>
<td style="vertical-align: top;">&lt;level&gt; &lt;name&gt;1&lt;/name&gt; &lt;wide-metrics-only/&gt; &lt;/level&gt;</pre></td>
<td style="vertical-align: top;">WIDE_METRIC</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">&lt;level&gt; &lt;name&gt;2&lt;/name&gt; &lt;preference&gt;50&lt;/preference&gt; &lt;/level&gt;</pre></td>
<td style="vertical-align: top;">NARROW_METRIC</pre></td>
</tr>
</tbody>
</table></div>

Parse EOS privilege:role
------------------------

The role in eos is the combination of the privilege level and the role itself. In this example we should how to use a regular expression to capture data and postprocess it to set the correct role.


Original data
_____________

.. code::
username test1 privilege 1 nopassword
username test2 privilege 1 secret sha512 $6$WL/ibPpzPJ/C7c/E$.bVF08dYhlNp0rxER0P3SNdsA2wUtK2Ru1YuKkRRZQGl609DA1JvX.dSFgKXaq.LWjDRlZoHudfk7hamod0Th/
username test3 privilege 15 role network-operator secret sha512 $6$Vd6.7k2FybfsTKKp$S.AHfdwicaWEoA41sPd6ZXOOdruJMrKJh70WNfiX/eZKH1oYBtFz9VbrPlYNDkhM/pi54gcYKH2hviy/xrUav.
username test4 privilege 1 secret 5 $1$NKhJ$PUfYNtJF2tIneEBZztchy.
username test5 privilege 15 secret sha512 $6$d3fdbbZBrhplknVB$FILKNelLURwd/xT74ktjxJ4XP1vTfJ53H7OWJHgAqeuY/lF3BDyP3SWpH/MeBRnl7lLi8hU2oy6hkbnB7jvtA.
username test6 privilege 1 role network-admin secret sha512 $6$zaalm5RTm6/26XVS$I/f3kmOqfvTbjwjzepCe1O9eYfPJRdUrRLe9NoMsbgNz9T48nj0AlOsm2LmoFp6aI5B6Q/xlseJdNrTL/jiXH0
username test7 privilege 15 role network-admin secret 5 $1$NKhJ$PUfYNtJF2tIneEBZztchy.
Parser rule
___________

.. code-block:: yaml
- path: privilege
post: '{{ extra_vars.privilege }}:{{ extra_vars.role }}'
regexp: (?P<value>(?P<privilege>\d+).*role (?P<role>\S+)) secret
- path: privilege
post: '{{ value }}:network-operator'
regexp: (?P<value>\d+)
Result
______




Example 1
^^^^^^^^^^

.. code-block:: yaml
extra_vars: {}
keys: {}
.. raw:: html

<div><table border="1" class="docutils">
<tr>
<th class="head">block</th>
<th class="head">value</th>
</tr>
<tbody>
<tr>
<td style="vertical-align: top;">username test1 privilege 1 nopassword</pre></td>
<td style="vertical-align: top;">1:network-operator</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test2 privilege 1 secret sha512 $6$WL/ibPpzPJ/C7c/E$.bVF08dYhlNp0rxER0P3SNdsA2wUtK2Ru1YuKkRRZQGl609DA1JvX.dSFgKXaq.LWjDRlZoHudfk7hamod0Th/</pre></td>
<td style="vertical-align: top;">1:network-operator</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test3 privilege 15 role network-operator secret sha512 $6$Vd6.7k2FybfsTKKp$S.AHfdwicaWEoA41sPd6ZXOOdruJMrKJh70WNfiX/eZKH1oYBtFz9VbrPlYNDkhM/pi54gcYKH2hviy/xrUav.</pre></td>
<td style="vertical-align: top;">15:network-operator</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test4 privilege 1 secret 5 $1$NKhJ$PUfYNtJF2tIneEBZztchy.</pre></td>
<td style="vertical-align: top;">1:network-operator</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test5 privilege 15 secret sha512 $6$d3fdbbZBrhplknVB$FILKNelLURwd/xT74ktjxJ4XP1vTfJ53H7OWJHgAqeuY/lF3BDyP3SWpH/MeBRnl7lLi8hU2oy6hkbnB7jvtA.</pre></td>
<td style="vertical-align: top;">15:network-operator</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test6 privilege 1 role network-admin secret sha512 $6$zaalm5RTm6/26XVS$I/f3kmOqfvTbjwjzepCe1O9eYfPJRdUrRLe9NoMsbgNz9T48nj0AlOsm2LmoFp6aI5B6Q/xlseJdNrTL/jiXH0</pre></td>
<td style="vertical-align: top;">1:network-admin</pre></td>
</tr>
<tr>
<td style="vertical-align: top;">username test7 privilege 15 role network-admin secret 5 $1$NKhJ$PUfYNtJF2tIneEBZztchy.</pre></td>
<td style="vertical-align: top;">15:network-admin</pre></td>
</tr>
</tbody>
</table></div>

Loading

0 comments on commit 2b761fe

Please sign in to comment.