User Tools

Site Tools


Sidebar

NetYCE Documentation



guides:reference:templates:parsing_templates

Config Parsing templates

These templates parse a config from a node, and extract variables from that config, to be used in Scenarios.

Config Parsing Template Syntax

A config consists out of a number of blocks of lines, which can differ vastly in shape, syntax and size. Each block can be captured in a context in a parsing template. A context contains code lines and variables. These variables can be requested in a scenario through the parse_run and parse_nccm scenario commands. The parse_run command parses the config that is retrieved directly from the active node. The parse_nccm will parse against the node's config saved in the NCCM (note that if there is no config present in the NCCM, the error flag will be set).

For more information, see: commands_details

Note: both parse_run and parse_nccm can only pull one variable out of a config each time. If you need multiple variables from a config, you will need to call the function multiple times.

While you may require multiple parse_run commands in your scenario, the actual configuration is only retrieved once.

Scenario command

The config parsing function is called from the scenario like this:

<var> := parse_run -n <node> -t template -c "template context" -v tpl_variable

or:

<var> := parse_nccm -n <node> -t template -c "template context" -v tpl_variable

parse_run runs config parsing on the active config of the node. parse_nccm compares to the config known in the nccm. If no config can be found in the NCCM, it will parse not parse anything and set the <error> variable.

Like all commands, parameters can be either scenario variables, or plain text. Do note the quotes around the -c context parameter. This is to allow contexts containing spaces and non-alphanumeric characters. Omitting quotes with strings that lack spaces will work, however this won't work if there are spaces in your variable.

Basic Syntax

A basic parsing template syntax is:

[interface]
interface <if_name>

[interface] is the context (-c).
<if_name> is the variable (-v).

When the config parser parses a config, it looks out for blocks whose first line starts with this header. It only looks at the first line of this block, and headers can be made more specific. For example, the above header matches with all blocks that start with interface. However, the following template will only match the block headed by “interface Ethernet0/1”.

[interface Ethernet0/1]
interface <if_name>

Below the header follows a number of pattern lines. This can be any number. The config parser will match all lines of its block with all lines of its pattern. It requires an exact match. (NOTE: if a pattern matches a line, but at the end of the line there are a number of extra words that are not in the pattern, that means no match!). The syntax for special words is as follows:

<string> A variable; replace with positional word
<string:end> Replace positional words until (but not including) 'end'
<string:> Replace positional words until end of line for '<string>'
|*| Ignore all following words

In a scenario, parse_run and parse_nccm can be used to retrieve the positional words of these variables. If a variable matches multiple times in a config, a list is returned containing all these values.

Headers can also be consecutive, for example

[interface Ethernet0/1]
[interface Ethernet 0/1]
interface <if_name>

What this means is that this block matches for both “interface Ethernet0/1” and “interface Ethernet 0/1”.

In general words will be parsed as separated by spaces. However the following is also possible:

snmp-server chassis-id <hostname>.<dns_domain> 

route-target export <vrf_as>:<vrf_id>

General

If you do not want to specify a specific header, use general. This will be used on all blocks that can't be matched to a context. For example

[general]
version <version>, Release <release>
sysname <sysname>
clock <clock:>

Hierarchy

Blocks can contain sub blocks, which look different depending on vendor. To define a sub context in a template to match this block, you need to indent it. For example

[interfaces]
 [ge-5/0/0]
  description <if_description:>

This also means that to get the variable if_description, you need to submit 2 contexts (-c) with the parse_run and parse_nccm scenario commands: 'interfaces' and 'ge-5/0/0', in that order. It is also possible to go down more levels. For that, the same rules apply.

Wildcards

Consider the following parsing template:

[interface <>]
interface <if_name>

If you specify the context as “interface Ethernet0/1”, it will treat this block as:

[interface Ethernet0/1]
interface <if_name>

This way you can have customizable parsing templates. This also works in sub contexts. You can also specify a wildcard like this:

[<>]
interface <if_name>

In this case the header will match any context that is given. This wildcard can now also be used in a pattern:

[interface <>]
vlan ports <> pvid <vlan_port>

With the context “interface Ethernet0/1” the config parser will treat this block as:

[interface Ethernet0/1]
vlan ports Ethernet0/1 pvid <vlan_port>

In configs where headers are more generic and you want to use a wildcard that does not appear in a header:

[interface]
interface <>

If you specify the context and subcontext as “interface” and “Ethernet0/1”, it will treat this block as:

[interface]
interface Ethernet0/1

Note that with complex hierarchies, this will only work if the wildcard is specified as the last sub-context to be sent along with the parse_run and parse_nccm commands.

Indentation

Some vendors have indented blocks, others do not. For the ones that do, the patterns need to be specified with the correct indentation. For example

[interface]
interface <if_name>
 description <if_description:>

“interface <if_name>” is the header and the first line of this block, but it can also be parsed, so it will also have its own pattern in this context. This line is not indented in the config, while the pattern “ description <if_description:>” is. If this is the case in your config, this syntax is required.

Indentation is always in steps of a number of spaces. It doesn't matter whether these steps are 1, 2 or 4 spaces, as long as within one block or context, the step size is consistent.

Vendor Specific Syntax

Avaya_SW

Avaya SW configs contain port and vlan ranges. Since these ranges can take the form of “1/1-25,2/1-25,3/ALL,4/ALL,5/ALL,6/ALL”, the config parser before parsing expands all these lines for each port, and collects them together in one block. Any line containing a port, port range, vlan or vlan range needs to be accessed this way, and not in the way you would expect from its config.

Every port will be found under the “Interface Ethernet 1/1” context (where 1/1 is the port in question). Every vlan will be found under the “Vlan 1234” context (where 1234 is the vlan in question). For example:

[Interface Ethernet 1/11]
vlan ports 1/11 pvid <port_vlan>
name port 1/11 <port_name>
[Vlan 1234]
vlan create 1234 type port <vlan_create>
vlan name 1234 <vlan_name>

Indentation is not needed for patterns, only for headers in sub contexts. For example:

[OSPF]
 [router ospf]
router-id <router_ospf>

Avaya block headers are of the form:

! *** IP Manager ***
!

Closed by another '!'. Headers and contexts in parsing templates will ignore all special characters and and trim all leading and trailing spaces, so you can just use “[IP Manager]” or even “[IP]” as a context.

CI6 & CI8

Ciena blocks consist out of a header, followed by a non-hierarchical set of lines, so indentations for patterns is not needed, and there also is no hierarchy present for contexts.

CI6 en CI8 block headers are of the form:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! SYSLOG CONFIG:
!

Closed by another '!'. Headers and contexts in parsing templates will ignore all special characters and and trim all leading and trailing spaces, so you can just use “[SYSLOG CONFIG]” or even “[SYSLOG]” as a context.

Ciena configs rely heavily on port names and aliases, so it is advisable to use a lot of wildcards and multiple scenario calls to parse_run and parse_nccm to get all the correct data on all ports. NetYCE provides a number of sample parsing templates in order to help you get started.

On top of that, CI6 configs also have vlan ranges that go like:

vlan create vlan 9-12,24-25

Lines like these will be expanded and converted in the config parser to:

vlan create vlan 9
vlan create vlan 10
vlan create vlan 11
vlan create vlan 12
vlan create vlan 24
vlan create vlan 25

Cisco_IOS & Cisco_Nexus & Cisco_XR

Cisco configs have many different types of blocks, indented and not indented, so indentation is necessary in its parsing templates. Generally, lines that all start with the same keywords are considered in one context, even if these lines are prepended by “no” (for example the line: “no mmi auto-configure”.

Banners, blocks ending with a delimiter can be simply defined as:

[banner motd]
banner motd <motd>

And the variable <motd> will contain the entire multi line banner.

On top of that, Cisco IOS configs also have vlan ranges that go like:

switchport trunk allowed vlan 775-777,3322

Lines like these will be expanded and converted in the config parser to:

switchport trunk allowed vlan 775
switchport trunk allowed vlan 776
switchport trunk allowed vlan 777
switchport trunk allowed vlan 3322

HP_C5 & HP_C7

HP_C5 has two types of blocks: hierarchical blocks that are properly indented, and blocks that follow lyne-by-line that are always one space indented. In parsing templates, indentation is needed for the first type, but not for the second. For example:

[clock]
clock <clock:>

[vlan]
vlan <vlan>
 name <vlan_name>

An exception to this is the header statement. This is treated as just one line and can be retrieved as:

[header]
header legal <header_legal>

On top of that, HP C7 configs also have vlan ranges that go like:

port trunk permit vlan 500 540 to 545 570

Lines like these will be expanded and converted in the config parser to:

port trunk permit vlan 500
port trunk permit vlan 540
port trunk permit vlan 541
port trunk permit vlan 542
port trunk permit vlan 543
port trunk permit vlan 544
port trunk permit vlan 545
port trunk permit vlan 570

Huawei_CE & Huawei_S

Cisco configs have many different types of blocks, indented and not indented, so indentation is necessary in its parsing templates. Generally, lines that all start with the same keywords are considered in one context, even if these lines are prepended by “no” (for example the line: “no mmi auto-configure”.

On top of that, Huawei configs also have vlan ranges that go like:

port trunk allow-pass vlan 4 1115 1200 1450 to 1453 2905 3993 to 3994

Lines like these will be expanded and converted in the config parser to:

port trunk allow-pass vlan 4 
port trunk allow-pass vlan 1115
port trunk allow-pass vlan 1200
port trunk allow-pass vlan 1450
port trunk allow-pass vlan 1451
port trunk allow-pass vlan 1452
port trunk allow-pass vlan 1453
port trunk allow-pass vlan 2905
port trunk allow-pass vlan 3993
port trunk allow-pass vlan 3994

Junos

Junos configs are very hierarchical. Indentation for patterns is not necessary, For headers it is. Any comments in the config between '/*' and '*/' will be ignored.

NOTE: every line in a juniper config that ends with a ';': this semicolon is not needed in its pattern

guides/reference/templates/parsing_templates.txt · Last modified: 2020/06/18 13:49 by pgels