Skip to content

Commit

Permalink
added template for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulyalin committed May 4, 2022
1 parent 67cd597 commit 7f0a7f0
Show file tree
Hide file tree
Showing 10 changed files with 723 additions and 21 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down Expand Up @@ -175,7 +175,6 @@ pprint.pprint(res)
```
</details>


## How templates collections structured

This repository contains three collections of templates corresponding to folder names:
Expand All @@ -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:

Expand Down
40 changes: 30 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

---

**Templates count: 50**
**Templates count: 52**

---

Expand All @@ -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/)

Expand Down Expand Up @@ -182,7 +182,6 @@ pprint.pprint(res)
```
</details>


## How templates collections structured

This repository contains three collections of templates corresponding to folder names:
Expand All @@ -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:

Expand Down
177 changes: 177 additions & 0 deletions docs/ttp_templates/misc.Netmiko.cisco.ios.cfg.nat.static.md
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
]
```



---

<details><summary>Template Content</summary>
```
<doc>
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")
'''
</doc>
<input>
commands = [
"show running-config | include source static"
]
</input>
<extend template="ttp://platform/cisco_ios_show_running_config_pipe_include_source_static.txt"/>
```
</details>
Loading

0 comments on commit 7f0a7f0

Please sign in to comment.