Comments (1)
Hi, check out path formatters:
For your example try to use:
<group name="interfaces.{{ interface }}">
interface {{ interface }}
<group name="other**">
ip dhcp snooping trust {{ ip_dhcp_snoop...
In addition have a look at group method attribute, that way you won't need all these start indicators, i.e. instead of:
<group name="port_security">
switchport port-security {{ state | set("enable") | _start_ }}
switchport port-security maximum {{ maximum | _start_ }}
</group>
the functional equivalent would be
<group name="port_security" method="table">
switchport port-security {{ state | set("enable") }}
switchport port-security maximum {{ maximum }}
</group>
Another trick that you can use and already used - dynamic path forming, that would allow you to flatten your template, for instance this template result should be the same as yours one:
<group name="interfaces.{{ interface }}.other">
interface {{ interface }}
ip dhcp snooping trust {{ ip_dhcp_snooping | set("trust") }}
shutdown {{ status | set("disabled")}}
description {{ description }}
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.switchport">
interface {{ interface }}
switchport nonegotiate {{ nonegotiate | set("enable") }}
switchport trunk native vlan {{ native_vlan }}
switchport mode {{ mode | _start_ }}
switchport access vlan {{ access_vlan }}
switchport trunk allowed vlan {{ trunk_vlan }}
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.port_security">
interface {{ interface }}
switchport port-security {{ state | set("enable") }}
switchport port-security maximum {{ maximum }}
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.stp">
interface {{ interface }}
spanning-tree portfast {{ portfast | set("enable") }}
spanning-tree portfast trunk {{ portfast_on_trunk | set("yes") }}
spanning-tree bpduguard enable {{ bpduguard | set("yes") }}
spanning-tree bpdufilter enable {{ bpdufilter | set("yes") }}
spanning-tree guard root {{ guard_root | set("yes") }}
spanning-tree guard loop {{ guard_loop | set("yes") }}
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.storm-control">
interface {{ interface }}
storm-control action {{ action }}
<group name='broadcast'>
storm-control broadcast level {{ units }} {{ value }}
</group>
<group name='multicast'>
storm-control multicast level {{ units }} {{ value }}
</group>
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.neighbor_discovery">
interface {{ interface }}
no lldp transmit {{ lldp_transmit | set("no") }}
no lldp receive {{ lldp_receive | set("no") }}
no cdp enable {{ cdp | set("disabled") }}
! {{ _end_ }}
</group>
<group name="interfaces.{{ interface }}.undef">
interface {{ interface }}
{{ undefined_conf | _line_ | joinmatches(', ') }}
! {{ _end_ }}
</group>
Also, for description suggest to use ORPHRASE regex pattern, that way it would match description strings like "my long description" in addition to "short_description"
from ttp.
Related Issues (20)
- Hello everyone, how do I parse import_RT and export_RT in the following configuration file using TTP. HOT 1
- Question about parsing non hierarchical data HOT 4
- Config generation from TTP template HOT 1
- Group functions filter out tail match results HOT 2
- Incorrect behavior if text notstartswith '\n' and template with '_end_' indicates
- resuball functions will execution many times HOT 3
- Cannot parse identical keys in different groups HOT 2
- Record multiple variables from a single group? HOT 1
- matching irrelevant group HOT 1
- Using of group.to_int leads to errors HOT 3
- TTP KeyError while running macro HOT 1
- Handling a variable that conditionally appears in output to be parsed? HOT 2
- Add new method to TTP to emit template content HOT 1
- How to correlate/enforce previously matched attribute? HOT 2
- Incorrect "default" behavior in nested groups HOT 6
- Incorrect macro behavior in nested groups HOT 2
- Request: linenumber match function
- The asterisks at the end of the key_name are removed
- \1 in key_value used in group name path_string
- Not closing group match properly when matching lines appear in multiple places in config HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ttp.