diff --git a/README.md b/README.md index 68c5c81..b12e283 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ This repository contains a collection of [TTP](https://github.com/dmulyalin/ttp) templates. -If you solved a problem using TTP and feel that your work can be -useful to other people, feel free to raise an issue or submit pull request to -include your template(s) in this repository. +If you solved a problem using TTP and feel that your work can be useful to other people, feel +free to raise an issue or submit pull request to include your template(s) in this repository. +Refer to [Contribute Guide](contribute.md) for details. Documentation: [https://dmulyalin.github.io/ttp_templates/](https://dmulyalin.github.io/ttp_templates/) @@ -175,7 +175,6 @@ pprint.pprint(res) ``` - ## How templates collections structured This repository contains three collections of templates corresponding to folder names: @@ -184,19 +183,40 @@ This repository contains three collections of templates corresponding to folder * `yang` collection - contains templates capable of producing YANG compatible structures out of text data * `misc` collection - miscellaneous templates for various use cases organized in folders -**Platform collection templates files naming rule** +### Platform collection templates files naming rule + +`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only. -`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only +Naming rules details: -**YANG collection templates files naming rule** +* All space symbols `' '` replaced with underscores. +* Pipe symbol `|` replaced with `pipe` in template name. For example, + template to parse Cisco IOS `show run | section interface` command output + must be named `cisco_ios_show_running_config_pipe_section_interface.txt` +* Dash symbols `-` replaced with underscores. For example, template to parse + Huawei `display current-configuration interface` command output must be + named `huawei_display_current_configuration_interface.txt` + +### YANG collection templates files naming rule `{{ YANG module name }}_{{ platform_name }}.txt` - lower case only -**Misc collection templates files naming rule** +Naming rules details: + +* All space symbols `' '` replaced with underscore. +* Dash symbol `-` **does not** replaced with underscore. For example, template + to produce output compatible with openconfig-lldp YANG model for Cisco IOS + must be named `openconfig-lldp_cisco_xr.txt` + +### Misc collection templates files naming rule `{{ usecase folder }}/{{ template name }}.txt` - upper or lower case -## Additional Template resources +Naming rules details: + +* Nothing replaced with anything, provided template name used as is. + +## Additional Templates Resources List of resources with TTP templates: diff --git a/docs/index.md b/docs/index.md index 2b1a947..65bf3de 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ --- -**Templates count: 50** +**Templates count: 52** --- @@ -12,9 +12,9 @@ This repository contains a collection of [TTP](https://github.com/dmulyalin/ttp) templates. -If you solved a problem using TTP and feel that your work can be -useful to other people, feel free to raise an issue or submit pull request to -include your template(s) in this repository. +If you solved a problem using TTP and feel that your work can be useful to other people, feel +free to raise an issue or submit pull request to include your template(s) in this repository. +Refer to [Contribute Guide](contribute.md) for details. Documentation: [https://dmulyalin.github.io/ttp_templates/](https://dmulyalin.github.io/ttp_templates/) @@ -182,7 +182,6 @@ pprint.pprint(res) ``` - ## How templates collections structured This repository contains three collections of templates corresponding to folder names: @@ -191,19 +190,40 @@ This repository contains three collections of templates corresponding to folder * `yang` collection - contains templates capable of producing YANG compatible structures out of text data * `misc` collection - miscellaneous templates for various use cases organized in folders -**Platform collection templates files naming rule** +### Platform collection templates files naming rule + +`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only. -`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only +Naming rules details: -**YANG collection templates files naming rule** +* All space symbols `' '` replaced with underscores. +* Pipe symbol `|` replaced with `pipe` in template name. For example, + template to parse Cisco IOS `show run | section interface` command output + must be named `cisco_ios_show_running_config_pipe_section_interface.txt` +* Dash symbols `-` replaced with underscores. For example, template to parse + Huawei `display current-configuration interface` command output must be + named `huawei_display_current_configuration_interface.txt` + +### YANG collection templates files naming rule `{{ YANG module name }}_{{ platform_name }}.txt` - lower case only -**Misc collection templates files naming rule** +Naming rules details: + +* All space symbols `' '` replaced with underscore. +* Dash symbol `-` **does not** replaced with underscore. For example, template + to produce output compatible with openconfig-lldp YANG model for Cisco IOS + must be named `openconfig-lldp_cisco_xr.txt` + +### Misc collection templates files naming rule `{{ usecase folder }}/{{ template name }}.txt` - upper or lower case -## Additional Template resources +Naming rules details: + +* Nothing replaced with anything, provided template name used as is. + +## Additional Templates Resources List of resources with TTP templates: diff --git a/docs/ttp_templates/misc.Netmiko.cisco.ios.cfg.nat.static.md b/docs/ttp_templates/misc.Netmiko.cisco.ios.cfg.nat.static.md new file mode 100644 index 0000000..a309f7b --- /dev/null +++ b/docs/ttp_templates/misc.Netmiko.cisco.ios.cfg.nat.static.md @@ -0,0 +1,177 @@ +Reference path: +``` +ttp://misc/Netmiko/cisco.ios.cfg.nat.static.txt +``` + +--- + + + +Template to parse Cisco IOS `show run | include source static` command output +Using Netmiko run_ttp method. + +Extends template: `ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt` + +Code to invoke this template Netmiko `run_ttp` method: + +``` +from netmiko import ConnectHandler + +net_connect = ConnectHandler( + device_type="cisco_ios", + host="1.2.3.4", + username="admin", + password="admin", +) + +res = net_connect.run_ttp("ttp://misc/netmiko/cisco.ios.cfg.nat.static.txt") +``` + + +GitHub Issue: https://github.com/dmulyalin/ttp_templates/issues/1 + +Author: Denis Mulyalin in cooperation with abhi1693 + +Template to parse Cisco IOS `show run | include source static` command output. + +Template's YANG model (not tested): + +``` +module nat { + + yang-version 1.1; + namespace "ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt"; + prefix nat; + revision "2022-May-04" { description "Initial Revision"; } + description "Template to parse Cisco IOS static NAT configuration"; + + list static { + key inside_ip; + leaf inside_ip { + type string; + } + leaf location { + type string; + } + leaf global_ip { + type string; + } + leaf interface { + type string; + } + leaf inside_port { + type uint32; + } + leaf global_port { + type uint32; + } + leaf vrf { + type string; + } + } +} +``` + +Sample data: + +``` +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 +``` + +Expected output: + +``` +[ + { + "nat": { + "static": [ + { + "global_ip": "3.3.3.3", + "inside_ip": "10.10.10.10", + "location": "inside" + }, + { + "global_ip": "3.3.4.4", + "global_port": 443, + "inside_ip": "192.168.1.10", + "inside_port": 443, + "location": "inside", + "protocol": "tcp", + "vrf": "VRF1000" + }, + { + "global_ip": "3.3.4.5", + "inside_ip": "192.168.2.10", + "location": "inside", + "vrf": "VRF1002" + }, + { + "global_ip": "3.3.5.6", + "global_port": 13389, + "inside_ip": "192.168.3.10", + "inside_port": 3389, + "location": "inside", + "protocol": "tcp" + }, + { + "global_ip": "6.6.6.6", + "inside_ip": "20.20.20.20", + "location": "inside" + }, + { + "global_port": 1443, + "inside_ip": "30.30.30.30", + "inside_port": 443, + "interface": "TenGigabitEthernet0/0/0", + "location": "inside", + "protocol": "tcp" + } + ] + } + } +] +``` + + + +--- + +
Template Content +``` + +Template to parse Cisco IOS 'show run | include source static' command output +Using Netmiko run_ttp method. + +Extends template: 'ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt' + +Code to invoke this template Netmiko 'run_ttp' method: + +''' +from netmiko import ConnectHandler + +net_connect = ConnectHandler( + device_type="cisco_ios", + host="1.2.3.4", + username="admin", + password="admin", +) + +res = net_connect.run_ttp("ttp://misc/netmiko/cisco.ios.cfg.nat.static.txt") +''' + + + + +commands = [ + "show running-config | include source static" +] + + + +``` +
\ No newline at end of file diff --git a/docs/ttp_templates/platform.cisco_ios_show_running_config_pipe_include_source_static.md b/docs/ttp_templates/platform.cisco_ios_show_running_config_pipe_include_source_static.md new file mode 100644 index 0000000..590288c --- /dev/null +++ b/docs/ttp_templates/platform.cisco_ios_show_running_config_pipe_include_source_static.md @@ -0,0 +1,245 @@ +Reference path: +``` +ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt +``` + +--- + + + +GitHub Issue: https://github.com/dmulyalin/ttp_templates/issues/1 + +Author: Denis Mulyalin in cooperation with abhi1693 + +Template to parse Cisco IOS `show run | include source static` command output. + +Template's YANG model (not tested): + +``` +module nat { + + yang-version 1.1; + namespace "ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt"; + prefix nat; + revision "2022-May-04" { description "Initial Revision"; } + description "Template to parse Cisco IOS static NAT configuration"; + + list static { + key inside_ip; + leaf inside_ip { + type string; + } + leaf location { + type string; + } + leaf global_ip { + type string; + } + leaf interface { + type string; + } + leaf inside_port { + type uint32; + } + leaf global_port { + type uint32; + } + leaf vrf { + type string; + } + } +} +``` + +Sample data: + +``` +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 +``` + +Expected output: + +``` +[ + { + "nat": { + "static": [ + { + "global_ip": "3.3.3.3", + "inside_ip": "10.10.10.10", + "location": "inside" + }, + { + "global_ip": "3.3.4.4", + "global_port": 443, + "inside_ip": "192.168.1.10", + "inside_port": 443, + "location": "inside", + "protocol": "tcp", + "vrf": "VRF1000" + }, + { + "global_ip": "3.3.4.5", + "inside_ip": "192.168.2.10", + "location": "inside", + "vrf": "VRF1002" + }, + { + "global_ip": "3.3.5.6", + "global_port": 13389, + "inside_ip": "192.168.3.10", + "inside_port": 3389, + "location": "inside", + "protocol": "tcp" + }, + { + "global_ip": "6.6.6.6", + "inside_ip": "20.20.20.20", + "location": "inside" + }, + { + "global_port": 1443, + "inside_ip": "30.30.30.30", + "inside_port": 443, + "interface": "TenGigabitEthernet0/0/0", + "location": "inside", + "protocol": "tcp" + } + ] + } + } +] +``` + + + +--- + +
Template Content +``` + +GitHub Issue: https://github.com/dmulyalin/ttp_templates/issues/1 + +Author: Denis Mulyalin in cooperation with abhi1693 + +Template to parse Cisco IOS 'show run | include source static' command output. + +Template's YANG model (not tested): + +''' +module nat { + + yang-version 1.1; + namespace "ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt"; + prefix nat; + revision "2022-May-04" { description "Initial Revision"; } + description "Template to parse Cisco IOS static NAT configuration"; + + list static { + key inside_ip; + leaf inside_ip { + type string; + } + leaf location { + type string; + } + leaf global_ip { + type string; + } + leaf interface { + type string; + } + leaf inside_port { + type uint32; + } + leaf global_port { + type uint32; + } + leaf vrf { + type string; + } + } +} +''' + +Sample data: + +''' +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 +''' + +Expected output: + +''' +[ + { + "nat": { + "static": [ + { + "global_ip": "3.3.3.3", + "inside_ip": "10.10.10.10", + "location": "inside" + }, + { + "global_ip": "3.3.4.4", + "global_port": 443, + "inside_ip": "192.168.1.10", + "inside_port": 443, + "location": "inside", + "protocol": "tcp", + "vrf": "VRF1000" + }, + { + "global_ip": "3.3.4.5", + "inside_ip": "192.168.2.10", + "location": "inside", + "vrf": "VRF1002" + }, + { + "global_ip": "3.3.5.6", + "global_port": 13389, + "inside_ip": "192.168.3.10", + "inside_port": 3389, + "location": "inside", + "protocol": "tcp" + }, + { + "global_ip": "6.6.6.6", + "inside_ip": "20.20.20.20", + "location": "inside" + }, + { + "global_port": 1443, + "inside_ip": "30.30.30.30", + "inside_port": 443, + "interface": "TenGigabitEthernet0/0/0", + "location": "inside", + "protocol": "tcp" + } + ] + } + } +] +''' + + + +ip nat {{ location }} source static {{ inside_ip | IP }} {{ global_ip | IP }} extendable +ip nat {{ location }} source static {{ inside_ip | IP }} interface {{ interface }} +ip nat {{ location }} source static {{ inside_ip | IP }} {{ global_ip | IP }} vrf {{ vrf }} extendable +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} interface {{ interface }} {{ global_port | INT | to_int }} +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} {{ global_ip | IP }} {{ global_port | INT | to_int }} extendable +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} {{ global_ip | IP }} {{ global_port | INT | to_int }} vrf {{ vrf }} extendable + +``` +
\ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 656d4a2..c97d755 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -41,6 +41,7 @@ nav: - cisco.ios.cfg.bgp: ttp_templates/misc.Netmiko.cisco.ios.cfg.bgp.md - cisco.ios.cfg.interface: ttp_templates/misc.Netmiko.cisco.ios.cfg.interface.md - cisco.ios.cfg.ip: ttp_templates/misc.Netmiko.cisco.ios.cfg.ip.md + - cisco.ios.cfg.nat.static: ttp_templates/misc.Netmiko.cisco.ios.cfg.nat.static.md - cisco.iosxr.arp: ttp_templates/misc.Netmiko.cisco.iosxr.arp.md - cisco.iosxr.cfg.interface: ttp_templates/misc.Netmiko.cisco.iosxr.cfg.interface.md - cisco.iosxr.cfg.ip: ttp_templates/misc.Netmiko.cisco.iosxr.cfg.ip.md @@ -58,6 +59,7 @@ nav: - cisco_ios_show_ip_ospf_database_router: ttp_templates/platform.cisco_ios_show_ip_ospf_database_router.md - cisco_ios_show_ip_ospf_database_summary: ttp_templates/platform.cisco_ios_show_ip_ospf_database_summary.md - cisco_ios_show_running_configuration_pipe_section_bgp: ttp_templates/platform.cisco_ios_show_running_configuration_pipe_section_bgp.md + - cisco_ios_show_running_config_pipe_include_source_static: ttp_templates/platform.cisco_ios_show_running_config_pipe_include_source_static.md - cisco_ios_show_running_config_pipe_section_interface: ttp_templates/platform.cisco_ios_show_running_config_pipe_section_interface.md - cisco_xr_show_arp_vrf_all: ttp_templates/platform.cisco_xr_show_arp_vrf_all.md - cisco_xr_show_isis_database_verbose: ttp_templates/platform.cisco_xr_show_isis_database_verbose.md diff --git a/test/test_misc_netmiko_templates.py b/test/test_misc_netmiko_templates.py index bb98202..a73bd31 100644 --- a/test/test_misc_netmiko_templates.py +++ b/test/test_misc_netmiko_templates.py @@ -101,6 +101,14 @@ def mock_output_cisco_ios(command_string, *args, **kwargs): neighbor 2.2.2.2 activate exit-address-family ! + """, + "show running-config | include source static": """ +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 """ } return outputs[command_string] @@ -697,4 +705,37 @@ def test_cisco_ios_cfg_bgp(): 'next_hop_self': True, 'pfl_out': 'VoIP-prefixes'}}}}}}]] -# test_cisco_ios_cfg_bgp() \ No newline at end of file +# test_cisco_ios_cfg_bgp() + +def test_cisco_ios_cfg_nat_static(): + res = connection_cisco_ios.run_ttp("ttp://misc/netmiko/cisco.ios.cfg.nat.static.txt") + pprint.pprint(res, width=150) + assert res == [[{'nat': {'static': [{'global_ip': '3.3.3.3', + 'inside_ip': '10.10.10.10', + 'location': 'inside'}, + {'global_ip': '3.3.4.4', + 'global_port': 443, + 'inside_ip': '192.168.1.10', + 'inside_port': 443, + 'location': 'inside', + 'protocol': 'tcp', + 'vrf': 'VRF1000'}, + {'global_ip': '3.3.4.5', + 'inside_ip': '192.168.2.10', + 'location': 'inside', + 'vrf': 'VRF1002'}, + {'global_ip': '3.3.5.6', + 'global_port': 13389, + 'inside_ip': '192.168.3.10', + 'inside_port': 3389, + 'location': 'inside', + 'protocol': 'tcp'}, + {'global_ip': '6.6.6.6', + 'inside_ip': '20.20.20.20', + 'location': 'inside'}, + {'global_port': 1443, + 'inside_ip': '30.30.30.30', + 'inside_port': 443, + 'interface': 'TenGigabitEthernet0/0/0', + 'location': 'inside', + 'protocol': 'tcp'}]}}]] \ No newline at end of file diff --git a/test/test_platform_cisco_ios.py b/test/test_platform_cisco_ios.py index 0d19b52..119fd48 100644 --- a/test/test_platform_cisco_ios.py +++ b/test/test_platform_cisco_ios.py @@ -341,3 +341,51 @@ def test_cisco_ios_show_ip_ospf_database_summary(): # test_cisco_ios_show_ip_ospf_database_summary() + +def test_cisco_ios_cisco_ios_show_running_config_pipe_include_source_static(): + data = """ +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 + """ + template = get_template( + platform="cisco_ios", command="show running-config | include source static" + ) + # print(template) + parser = ttp(data=data, template=template) + parser.parse() + res = parser.result() + pprint.pprint(res) + assert res == [[{'nat': {'static': [{'global_ip': '3.3.3.3', + 'inside_ip': '10.10.10.10', + 'location': 'inside'}, + {'global_ip': '3.3.4.4', + 'global_port': 443, + 'inside_ip': '192.168.1.10', + 'inside_port': 443, + 'location': 'inside', + 'protocol': 'tcp', + 'vrf': 'VRF1000'}, + {'global_ip': '3.3.4.5', + 'inside_ip': '192.168.2.10', + 'location': 'inside', + 'vrf': 'VRF1002'}, + {'global_ip': '3.3.5.6', + 'global_port': 13389, + 'inside_ip': '192.168.3.10', + 'inside_port': 3389, + 'location': 'inside', + 'protocol': 'tcp'}, + {'global_ip': '6.6.6.6', + 'inside_ip': '20.20.20.20', + 'location': 'inside'}, + {'global_port': 1443, + 'inside_ip': '30.30.30.30', + 'inside_port': 443, + 'interface': 'TenGigabitEthernet0/0/0', + 'location': 'inside', + 'protocol': 'tcp'}]}}]] + diff --git a/ttp_templates/misc/Netmiko/cisco.ios.cfg.nat.static.txt b/ttp_templates/misc/Netmiko/cisco.ios.cfg.nat.static.txt new file mode 100644 index 0000000..ac4006a --- /dev/null +++ b/ttp_templates/misc/Netmiko/cisco.ios.cfg.nat.static.txt @@ -0,0 +1,30 @@ + +Template to parse Cisco IOS `show run | include source static` command output +Using Netmiko run_ttp method. + +Extends template: `ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt` + +Code to invoke this template Netmiko `run_ttp` method: + +``` +from netmiko import ConnectHandler + +net_connect = ConnectHandler( + device_type="cisco_ios", + host="1.2.3.4", + username="admin", + password="admin", +) + +res = net_connect.run_ttp("ttp://misc/netmiko/cisco.ios.cfg.nat.static.txt") +``` + + + + +commands = [ + "show running-config | include source static" +] + + + \ No newline at end of file diff --git a/ttp_templates/platform/cisco_ios_show_running_config_pipe_include_source_static.txt b/ttp_templates/platform/cisco_ios_show_running_config_pipe_include_source_static.txt new file mode 100644 index 0000000..957679d --- /dev/null +++ b/ttp_templates/platform/cisco_ios_show_running_config_pipe_include_source_static.txt @@ -0,0 +1,119 @@ + +GitHub Issue: https://github.com/dmulyalin/ttp_templates/issues/1 + +Author: Denis Mulyalin in cooperation with abhi1693 + +Template to parse Cisco IOS `show run | include source static` command output. + +Template's YANG model (not tested): + +``` +module nat { + + yang-version 1.1; + namespace "ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt"; + prefix nat; + revision "2022-May-04" { description "Initial Revision"; } + description "Template to parse Cisco IOS static NAT configuration"; + + list static { + key inside_ip; + leaf inside_ip { + type string; + } + leaf location { + type string; + } + leaf global_ip { + type string; + } + leaf interface { + type string; + } + leaf inside_port { + type uint32; + } + leaf global_port { + type uint32; + } + leaf vrf { + type string; + } + } +} +``` + +Sample data: + +``` +ip nat inside source static 10.10.10.10 3.3.3.3 extendable +ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable +ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable +ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable +ip nat inside source static 20.20.20.20 6.6.6.6 extendable +ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443 +``` + +Expected output: + +``` +[ + { + "nat": { + "static": [ + { + "global_ip": "3.3.3.3", + "inside_ip": "10.10.10.10", + "location": "inside" + }, + { + "global_ip": "3.3.4.4", + "global_port": 443, + "inside_ip": "192.168.1.10", + "inside_port": 443, + "location": "inside", + "protocol": "tcp", + "vrf": "VRF1000" + }, + { + "global_ip": "3.3.4.5", + "inside_ip": "192.168.2.10", + "location": "inside", + "vrf": "VRF1002" + }, + { + "global_ip": "3.3.5.6", + "global_port": 13389, + "inside_ip": "192.168.3.10", + "inside_port": 3389, + "location": "inside", + "protocol": "tcp" + }, + { + "global_ip": "6.6.6.6", + "inside_ip": "20.20.20.20", + "location": "inside" + }, + { + "global_port": 1443, + "inside_ip": "30.30.30.30", + "inside_port": 443, + "interface": "TenGigabitEthernet0/0/0", + "location": "inside", + "protocol": "tcp" + } + ] + } + } +] +``` + + + +ip nat {{ location }} source static {{ inside_ip | IP }} {{ global_ip | IP }} extendable +ip nat {{ location }} source static {{ inside_ip | IP }} interface {{ interface }} +ip nat {{ location }} source static {{ inside_ip | IP }} {{ global_ip | IP }} vrf {{ vrf }} extendable +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} interface {{ interface }} {{ global_port | INT | to_int }} +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} {{ global_ip | IP }} {{ global_port | INT | to_int }} extendable +ip nat {{ location }} source static {{ protocol }} {{ inside_ip | IP }} {{ inside_port | INT | to_int }} {{ global_ip | IP }} {{ global_port | INT | to_int }} vrf {{ vrf }} extendable + \ No newline at end of file diff --git a/ttp_templates/ttp_templates.py b/ttp_templates/ttp_templates.py index 2091929..83da441 100644 --- a/ttp_templates/ttp_templates.py +++ b/ttp_templates/ttp_templates.py @@ -36,7 +36,7 @@ def get_template( platform = platform.lower() command = command.lower() command = command.replace("|", "pipe") - for symbol in [" "]: + for symbol in [" ", "-"]: platform = platform.replace(symbol, "_") command = command.replace(symbol, "_") path = "platform/{}_{}.txt".format(platform, command)