Skip to content

Commit

Permalink
bump to version 0.3.1, added ttp://mist/N2G/cli_ip_data/arista_eos.tx…
Browse files Browse the repository at this point in the history
…t template
  • Loading branch information
dmulyalin committed Jul 9, 2022
1 parent db26ac4 commit b3c96cd
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ttp_templates"
version = "0.3.0"
version = "0.3.1"
description = "Template Text Parser Templates collections"
license = "MIT"
include = [
Expand Down
93 changes: 93 additions & 0 deletions test/mock_data/test_N2G_cli_ip_data_arista_eos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
ceos1#show run
! Command: show running-config
! device: ceos1 (cEOSLab, EOS-4.26.0F-21792469.4260F (engineering build))
!
transceiver qsfp default-mode 4x10G
!
service routing protocols model ribd
!
agent Bfd shutdown
agent PowerManager shutdown
agent LedPolicy shutdown
agent Thermostat shutdown
agent PowerFuse shutdown
agent StandbyCpld shutdown
agent LicenseManager shutdown
!
no logging console
logging host 1.1.1.1 514
logging host 1.2.3.4 514
logging host 1.2.3.5 514
logging host 1.2.3.6 514
logging host 2.2.2.2 514
logging host 4.3.2.1 514
logging host 5.5.5.5 514
logging host 7.7.7.7 514
logging host 9.9.9.9 514
!
logging level AAA informational
!
hostname ceos1
!
ntp server 1.1.1.1
ntp server 1.1.1.2
ntp server 1.1.1.10
ntp server 1.1.1.11
ntp server 2.2.2.2
ntp server 2.2.2.3
ntp server 3.3.3.3
ntp server 3.3.3.4
ntp server 4.3.2.1
ntp server 6.6.6.6
ntp server 7.7.7.7
ntp server 7.7.7.8
!
snmp-server location "North West Hall DC1"
snmp-server local-interface Ethernet1
snmp-server host 1.2.3.4 version 2c test
snmp-server host 1.2.3.5 version 2c test
!
spanning-tree mode mstp
!
no aaa root
!
username nornir privilege 15 secret sha512 $6$EkriX8oB5g3Midq4$ErOpqzIWT7FxiW1IkSNQKS8gEqsn9HsbRVm8.Zw47y3Xm9a.GywP9zPF/avyTBBS8c5/ZSMMj/6BHL64KcW2I1
!
interface Ethernet1
description Configured by NETCONF
mtu 9200
no switchport
ip address 10.0.1.4/24
!
interface Loopback1
ip address 1.1.1.1/24
!
interface Loopback2
description Lopback2 for Customer 27123
ip address 2.2.2.2/24
!
interface Loopback3
description Customer #56924 service
ip address 1.2.3.4/24
!
interface Loopback1000
!
no ip routing
!
management api http-commands
protocol http
no shutdown
!
management api gnmi
transport grpc default
!
management api netconf
transport ssh def
!
end
ceos1# show ip arp vrf all

VRF: default
Address Age (sec) Hardware Addr Interface
10.0.1.3 0:00:16 0242.0a00.0103 Ethernet1
ceos1#
50 changes: 49 additions & 1 deletion test/test_n2g_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
from ttp import ttp
from ttp_templates.ttp_vars import all_vars

# Custom TTP functions to use in templates:
def add_network(data):
if "netmask" in data:
ip_obj, _ = _ttp_["match"]["to_ip"]("{}/{}".format(data["ip"], data["netmask"]))
else:
ip_obj, _ = _ttp_["match"]["to_ip"](data["ip"])
data["network"] = str(ip_obj.network)
data["netmask"] = str(ip_obj.network.prefixlen)
return data, None

def test_N2G_ospf_lsdb_Cisco_IOSXR():
with open("./mock_data/cisco_xr_show_ip_ospf_database_router_external_summary_router-1.txt", "r") as f:
data1 = f.read()
Expand Down Expand Up @@ -510,4 +520,42 @@ def test_N2G_cli_l2_data_juniper():
'Networks, '
'Inc.'}}}}]

# test_N2G_cli_l2_data_juniper()
# test_N2G_cli_l2_data_juniper()


def test_N2G_cli_ip_data_arista_eos():
with open("./mock_data/test_N2G_cli_ip_data_arista_eos.txt", "r") as f:
data = f.read()
template = get_template(path="misc/N2G/cli_ip_data/arista_eos.txt")
# print(template)
parser = ttp(vars={"IfsNormalize": all_vars["short_interface_names"], "physical_ports": all_vars["physical_ports"]})
parser.add_function(add_network, scope="group", name="add_network", add_ttp=True)
parser.add_template(template=template)
parser.add_input(data, template_name="arista_eos")
parser.parse()
res = parser.result()
pprint.pprint(res)
assert res == [{'ceos1': {'interfaces': {'Eth1': {'arp': [{'age': '0:00:16',
'ip': '10.0.1.3',
'mac': '02:42:0a:00:01:03'}],
'ip_addresses': [{'ip': '10.0.1.4',
'netmask': '24',
'network': '10.0.1.0/24'}],
'port_description': 'Configured by '
'NETCONF'},
'Lo1': {'ip_addresses': [{'ip': '1.1.1.1',
'netmask': '24',
'network': '1.1.1.0/24'}]},
'Lo1000': {},
'Lo2': {'ip_addresses': [{'ip': '2.2.2.2',
'netmask': '24',
'network': '2.2.2.0/24'}],
'port_description': 'Lopback2 for Customer '
'27123'},
'Lo3': {'ip_addresses': [{'ip': '1.2.3.4',
'netmask': '24',
'network': '1.2.3.0/24'}],
'port_description': 'Customer #56924 '
'service'}}}}]

# test_N2G_cli_ip_data_arista_eos()
38 changes: 38 additions & 0 deletions ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template name="arista_eos" results="per_template">

<doc>
Template to parse Arista EOS interfaces configuration and ARP cache.
</doc>

<input load="python">
commands = [
"show running-config",
"show ip arp vrf all",
]
method = "send_command"
platform = ["arista_eos"]
</input>

<!-- Extract Device Hostname -->
<group name="nill" void="">
hostname {{ local_hostname | record("local_hostname") }}
</group>

<!-- Interfaces configuration group -->
<group name="{{ local_hostname }}.interfaces.{{ interface }}">
interface {{ interface | resuball("IfsNormalize") }}
description {{ port_description | re(".+") }}
vrf {{ vrf }}
<group name="ip_addresses*" chain="add_network()" method="table">
ip address {{ ip | IP }}/{{ netmask }}
ip address {{ ip | IP }}/{{ netmask }} secondary
</group>
! {{ _end_ }}
</group>

<!-- ARP cache group -->
<group name="{{ local_hostname }}.interfaces.{{ interface }}.arp*" method="table">
{{ ip | IP }} {{ age }} {{ mac | MAC | mac_eui }} {{ interface | resuball("IfsNormalize") }}
</group>

</template>

0 comments on commit b3c96cd

Please sign in to comment.