Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds parser for reload reason. #87

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions parser_templates/cli/show_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,44 @@
regex: "^System image file is (\\S+)"
register: image

- name: match restart conditions
pattern_match:
regex: "^System restarted at (?P<time>\\d+:\\d+:\\d+) (?P<tz>\\S+)"
register: restart_conditions

- name: match reload reason
pattern_match:
regex: "^Last reload reason: (\\S+)"
register: reload_reason

- name: match uptime
pattern_match:
regex: "uptime is (.+)"
register: uptime

- name: match uptime years
pattern_match:
regex: "uptime is (\\d+) years,"
regex: "uptime is (\\d+) year"
register: uptime_years

- name: match uptime weeks
pattern_match:
regex: "(\\d+) weeks,"
regex: "(\\d+) week"
register: uptime_weeks

- name: match uptime days
pattern_match:
regex: "(\\d+) days,"
regex: "(\\d+) day"
register: uptime_days

- name: match uptime hours
pattern_match:
regex: "(\\d+) hours,"
regex: "(\\d+) hour"
register: uptime_hours

- name: match uptime minutes
pattern_match:
regex: "(\\d+) minutes"
regex: "(\\d+) minute"
register: uptime_minutes

- name: match configuration register
Expand All @@ -71,20 +81,26 @@
value: "{{ image.matches.0 }}"
- key: model
value: "{{ model.matches.0 }}"
- key: restart_time
value: "{{ restart_conditions.time }}"
- key: restart_tz
value: "{{ restart_conditions.tz }}"
- key: reload_reason
value: "{{ reload_reason.matches.0 | lower }}"
- key: uptime
value: "{{ uptime.matches.0 }}"
- key: uptime_split
object:
- key: years
value: "{{ uptime_years.matches.0 | default(0) }}"
value: "{{ uptime_years.matches.0 | default(0) | int }}"
- key: weeks
value: "{{ uptime_weeks.matches.0 | default(0) }}"
value: "{{ uptime_weeks.matches.0 | default(0) | int }}"
- key: days
value: "{{ uptime_days.matches.0 | default(0) }}"
value: "{{ uptime_days.matches.0 | default(0) | int }}"
- key: hours
value: "{{ uptime_hours.matches.0 | default(0) }}"
value: "{{ uptime_hours.matches.0 | default(0) | int }}"
- key: minutes
value: "{{ uptime_minutes.matches.0 | default(0) }}"
value: "{{ uptime_minutes.matches.0 | default(0) | int }}"
- key: configuration_register
value: "{{ confreg.matches.0 }}"
register: system
Expand Down
4 changes: 2 additions & 2 deletions tests/parser_templates/cli/show_interfaces/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
- interfaces['GigabitEthernet0/0/1']['admin-status'] == 'enabled'
- interfaces['Tunnel0']['admin-status'] == 'enabled'
- interfaces['Tunnel0']['oper-status'] == 'down'
- interfaces['GigabitEthernet0']['counters']['in-broadcast-pkts'] == '4891144'
- interfaces['GigabitEthernet0']['counters']['in-broadcast-pkts'] == 4891144
- interfaces['GigabitEthernet0']['counters']['in-multicast-pkts'] == None
- interfaces['Virtual-Access1']['mtu'] == '1500'
- interfaces['Virtual-Access1']['mtu'] == 1500
- interfaces['Tunnel2']['description'] == 'tunnel for gloabl routing for SJC'
- interfaces['GigabitEthernet0/0/5']['type'] == '6XGE-BUILT-IN'
- interfaces['Tunnel0']['type'] == 'Tunnel'
Expand Down
9 changes: 9 additions & 0 deletions tests/parser_templates/cli/show_version/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- system.uptime_split.minutes | int == 27
- system.version == '15.5(1)S'
- system.model is not none
- system.reload_reason == 'reload'
- system.restart_time == '09:58:28'
- system.restart_tz == 'UTC'

### IOS-XE 16.6.4

Expand All @@ -37,6 +40,9 @@
- system.uptime_split.minutes | int == 23
- system.version == '16.6.4'
- system.model is not none
- system.reload_reason == 'poweron'
- system.restart_time == '08:29:02'
- system.restart_tz == 'UTC'

### IOS 15.1(4)M4
- name: 15.1(4)M4 - parse `show version`
Expand All @@ -55,6 +61,9 @@
- system.uptime_split.minutes | int == 53
- system.version == '15.1(4)M4'
- system.model is not none
- system.reload_reason == 'reload'
- system.restart_time == '18:49:38'
- system.restart_tz == 'UTC'

### Done

Expand Down
2 changes: 2 additions & 0 deletions tests/test_config_manager.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ansible-playbook

---
# Main Entrypoint
- import_playbook: config_manager/test.yml
2 changes: 2 additions & 0 deletions tests/test_parser_templates.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ansible-playbook

---
- hosts: localhost
gather_facts: false
Expand Down