From b3c96cdf7073927bdf50e12ca624ba56e433039e Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 9 Jul 2022 18:26:56 +1000 Subject: [PATCH] bump to version 0.3.1, added ttp://mist/N2G/cli_ip_data/arista_eos.txt template --- pyproject.toml | 2 +- .../test_N2G_cli_ip_data_arista_eos.txt | 93 +++++++++++++++++++ test/test_n2g_templates.py | 50 +++++++++- .../misc/N2G/cli_ip_data/arista_eos.txt | 38 ++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 test/mock_data/test_N2G_cli_ip_data_arista_eos.txt create mode 100644 ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt diff --git a/pyproject.toml b/pyproject.toml index 90649c7..fa6dc0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/test/mock_data/test_N2G_cli_ip_data_arista_eos.txt b/test/mock_data/test_N2G_cli_ip_data_arista_eos.txt new file mode 100644 index 0000000..85ee0d3 --- /dev/null +++ b/test/mock_data/test_N2G_cli_ip_data_arista_eos.txt @@ -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# \ No newline at end of file diff --git a/test/test_n2g_templates.py b/test/test_n2g_templates.py index 960b19f..fb16fc5 100644 --- a/test/test_n2g_templates.py +++ b/test/test_n2g_templates.py @@ -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() @@ -510,4 +520,42 @@ def test_N2G_cli_l2_data_juniper(): 'Networks, ' 'Inc.'}}}}] -# test_N2G_cli_l2_data_juniper() \ No newline at end of file +# 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() \ No newline at end of file diff --git a/ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt b/ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt new file mode 100644 index 0000000..58e44f9 --- /dev/null +++ b/ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt @@ -0,0 +1,38 @@ + \ No newline at end of file