Skip to content

Commit

Permalink
add parser for cdp and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
willtome committed Oct 29, 2018
1 parent ee8cac7 commit 0d8bef6
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
39 changes: 39 additions & 0 deletions parser_templates/cli/show_cdp_entry_all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: match cdp sections
pattern_match:
regex: "^----------------------------------------"
match_all: yes
match_greedy: yes
register: context

- name: match cpd values
pattern_group:
- name: match name
pattern_match:
regex: "Device ID:(|\\s)(.+)\\("
content: "{{ item }}"
register: device_id

- name: match interface
pattern_match:
regex: "Interface: (.+), Port ID \\(outgoing port\\): (.+)"
content: "{{ item }}"
register: interface

loop: "{{ context }}"
register: values

- name: build cdp template
json_template:
template:
- key: "{{ item.device_id.matches.1 }}"
object:
- key: local_port
value: "{{ item.interface.matches.0 }}"
- key: remote_port
value: "{{ item.interface.matches.1}}"
loop: "{{ values }}"
register: neighbors
export: yes
export_as: dict
extend: cisco_nxos
84 changes: 84 additions & 0 deletions parser_templates/cli/show_interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
- name: match interface sections
pattern_match:
regex: "^\\S+ is (up|down)"
match_all: yes
match_greedy: yes
register: context

- name: match interface values
pattern_group:
- name: match name
pattern_match:
regex: "^(.+) is (\\w+)"
content: "{{ item }}"
register: name

- name: match admin state
pattern_match:
regex: "admin state is (\\S+)"
content: "{{ item }}"
register: admin_state

- name: match mac address
pattern_match:
regex: "Hardware: Ethernet, address: ([\\d|\\w]{4}.[\\d|\\w]{4}.[\\d|\\w]{4})"
content: "{{ item }}"
register: mac_addr

- name: match description value
pattern_match:
regex: "Description: (.*)"
content: "{{ item }}"
register: description

- name: match mtu value
pattern_match:
regex: "MTU (\\d+)"
content: "{{ item }}"
register: mtu

- name: match ipv4 address
pattern_match:
regex: "Internet Address is (.+)"
content: "{{ item }}"
register: ipv4addr

- name: match port mode
pattern_match:
regex: "Port mode is (.+)"
content: "{{ item }}"
register: port_mode

loop: "{{ context }}"
register: values

- name: build interface template
json_template:
template:
- key: "{{ item.name.matches.0 }}"
object:
- key: oper_status
value: "{{ item.name.matches.1 }}"
- key: admin_status
value: "{{ item.admin_state.matches.0}}"
- key: mac_address
value: "{{ item.mac_addr.matches.0 }}"
- key: ipv4
object:
- key: address
value: "{{ item.ipv4addr.matches.0.split('/')[0] }}"
- key: masklen
value: "{{ item.ipv4addr.matches.0.split('/')[1] }}"
when: item.ipv4addr.matches
- key: description
value: "{{ item.description.matches.0 }}"
- key: mtu
value: "{{ item.mtu.matches.0 }}"
- key: port_mode
value: "{{ item.port_mode.matches.0}}"
loop: "{{ values }}"
register: interfaces
export: yes
export_as: dict
extend: cisco_nxos

0 comments on commit 0d8bef6

Please sign in to comment.