Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------
* C9400
* Modified/Revised ShowEnvironmentAll:
* Changed schema to include "switch" for every switch in the stack.
* Updated regex pattern to accomodate for "Switch:1" and "Switch: 1" outputs and use those as keys to the power supply and fantray parsing.
54 changes: 41 additions & 13 deletions sdk_generator/outputs/github_parser.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/genie/libs/parser/iosxe/cat9k/c9400/rv1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from genie import abstract
abstract.declare_token(revision='1')
269 changes: 269 additions & 0 deletions src/genie/libs/parser/iosxe/cat9k/c9400/rv1/show_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
# Python
import re

# Metaparser
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Any, Optional, Or

class ShowEnvironmentAllSchema(MetaParser):
"""Schema for show environment all
show environment all | include {include} """

schema = {
Optional('critical_alarms'): int,
Optional('major_alarms'): int,
Optional('minor_alarms'): int,
'sensor_list': {
Any(): {
'slot': {
Any(): {
'sensor': {
Any(): {
'state': str,
'reading': str,
Optional('threshold'): {
'minor': int,
'major': int,
'critical': int,
'shutdown': int,
'unit': str,
}
}
}
}
}
}
},
'switch': {
Any(): {
'power_supply': {
'slot': {
Any(): {
'model_no': str,
'type': str,
'capacity': str,
'status': str,
'fan_1_state': str,
'fan_2_state': str,
}
},
'current_configuration_mode': str,
'current_operating_state': str,
'currently_active': int,
'currently_available': int,
},
'fantray': {
'status': str,
'power_consumed_by_fantray_watts': int,
'fantray_airflow_direction': str,
'fantray_beacon_led': str,
'fantray_status_led': str,
'system': str,
},
},
},
}


class ShowEnvironmentAll(ShowEnvironmentAllSchema):
"""Parser for show environment all
show environment all | include {include}"""

cli_command = [
'show environment all', 'show environment all | include {include}'
]

def cli(self, include='', output=None):
if not output:
if include:
cmd = self.cli_command[1].format(include=include)
else:
cmd = self.cli_command[0]
output = self.device.execute(cmd)

# initial return dictionary
ret_dict = {}

# Number of Critical alarms: 0
p1 = re.compile(
r'^Number +of +Critical +alarms: +(?P<critic_alarms>\d+)$')

# Number of Major alarms: 0
p2 = re.compile(r'^Number +of +Major +alarms: +(?P<maj_alarms>\d+)$')

# Number of Minor alarms: 0
p3 = re.compile(r'^Number +of +Minor +alarms: +(?P<min_alarms>\d+)$')

# Sensor List: Environmental Monitoring
p4 = re.compile(r'Sensor\s+List:\s+(?P<sensor_list>.+)')

# Sensor Location State Reading Threshold(Minor,Major,Critical,Shutdown)
# Temp: Coretemp Chassis1-R0 Normal 46 Celsius (107,117,123,125)(Celsius)
# Temp: UADP Chassis1-R0 Normal 54 Celsius (107,117,123,125)(Celsius)
# V1: VX1 Chassis1-R0 Normal 871 mV na
# V1: VX2 Chassis1-R0 Normal 1498 mV na
# V1: VX3 Chassis1-R0 Normal 1055 mV na
# V1: VX4 Chassis1-R0 Normal 852 mV na
# V1: VX5 Chassis1-R0 Normal 1507 mV na
# V1: VX6 Chassis1-R0 Normal 1301 mV na
# V1: VX7 Chassis1-R0 Normal 1005 mV na
p5 = re.compile(
r'(?P<sensor_name>\S+(:\s+\S+)?)\s+(?P<slot>\S+[0-9])\s+(?P<state>\S+)\s+(?P<reading>\d+\s+\S+(\s+(AC|DC))?)\s+(\((?P<minor>\d+\s*),(?P<major>\d+\s*),(?P<critical>\d+\s*),(?P<shutdown>\d+\s*)\)\((?P<unit>\S+)\))?'
)

# Switch:1
p6 = re.compile(r'^Switch:(?P<switch>\d+)')

# Power Fan States
# Supply Model No Type Capacity Status 1 2
# ------ -------------------- ---- -------- ------------ -----------
# PS1 C9400-PWR-3200AC ac 3200 W active good good
# PS2 C9400-PWR-3200AC ac n.a. faulty good good
p7 = re.compile(
r'(?P<ps_slot>PS\S+)\s+(?P<model_no>\S+)\s+(?P<type>\S+)\s+(?P<capacity>\S+(\s+\S+)?)\s+(?P<status>\S+)\s+(?P<fan_1_state>\S+)\s+(?P<fan_2_state>\S+)$'
)

# PS Current Configuration Mode : Combined
# PS Current Operating State : Combined
# Power supplies currently active : 1
# Power supplies currently available : 1
p8 = re.compile(
r'(PS|Power supplies)\s+(?P<ps_key>.+)\s+:\s+(?P<ps_value>\S+)')

# Switch 1:
p9 = re.compile(r'^Switch +(?P<switch>\d+)')

# Fantray : good
# Power consumed by Fantray : 540 Watts
# Fantray airflow direction : side-to-side
# Fantray beacon LED: off
# Fantray status LED: green
# SYSTEM : GREEN
p10 = re.compile(
r'(?P<fantray_key>((.+)?Fantray(.+)?)|SYSTEM)(\s+)?:\s+(?P<fantray_value>(\S+)|(\d+\s+Watts))'
)

for line in output.splitlines():
line = line.strip()

# Number of Critical alarms: 0
m = p1.match(line)
if m:
group = m.groupdict()
ret_dict['critical_alarms'] = int(group['critic_alarms'])
continue

# Number of Major alarms: 0
m = p2.match(line)
if m:
group = m.groupdict()
ret_dict['major_alarms'] = int(group['maj_alarms'])
continue

# Number of Minor alarms: 0
m = p3.match(line)
if m:
group = m.groupdict()
ret_dict['minor_alarms'] = int(group['min_alarms'])
continue

# Sensor List: Environmental Monitoring
m = p4.match(line)
if m:
group = m.groupdict()
sensor_dict = ret_dict.setdefault('sensor_list',
{}).setdefault(
group['sensor_list'], {})
continue

# Sensor Location State Reading Threshold(Minor,Major,Critical,Shutdown)
# Temp: Coretemp R0 Normal 48 Celsius (107,117,123,125)(Celsius)
# Temp: UADP R0 Normal 56 Celsius (107,117,123,125)(Celsius)
# V1: VX1 R0 Normal 869 mV na
# Temp: inlet R0 Normal 32 Celsius (56 ,66 ,96 ,98 )(Celsius)
m = p5.match(line)
if m:
group = m.groupdict()
sensor_name = group.pop('sensor_name')
slot = group.pop('slot')
fin_dict = sensor_dict.setdefault('slot', {}).setdefault(slot, {}).\
setdefault('sensor', {}).setdefault(sensor_name, {})

fin_dict['state'] = group['state']
fin_dict['reading'] = group['reading']
if group['minor']:
fin_dict.setdefault('threshold', {})
for key in [
'minor', 'major', 'critical', 'shutdown', 'unit'
]:
fin_dict['threshold'][key] = int(
group[key]) if key != 'unit' else group[key]
continue

# Switch:1
m = p6.match(line)
if m:
group = m.groupdict()
switch = group['switch']
sw_dict = ret_dict.setdefault('switch', {}).setdefault(switch, {})

# Power Fan States
# Supply Model No Type Capacity Status 1 2
# ------ -------------------- ---- -------- ------------ -----------
# PS1 C9400-PWR-3200AC ac 3200 W active good good
# PS2 C9400-PWR-3200AC ac n.a. faulty good good
m = p7.match(line)
if m:
group = m.groupdict()
ps_slot = group.pop('ps_slot')
ps_dict = sw_dict.setdefault('power_supply', {})
ps_slot_dict = ps_dict.setdefault('slot',
{}).setdefault(ps_slot, {})
ps_slot_dict.update({k: v for k, v in group.items()})

# PS Current Configuration Mode : Combined
# PS Current Operating State : Combined
# Power supplies currently active : 1
# Power supplies currently available : 1
m = p8.match(line)
if m:
group = m.groupdict()
ps_key = group['ps_key'].strip().lower().replace(' ', '_')
if 'active' in ps_key or 'available' in ps_key:
ps_value = int(group['ps_value'])
else:
ps_value = group['ps_value']
ps_dict.setdefault(ps_key, ps_value)

# Switch 1:
m = p9.match(line)
if m:
group = m.groupdict()
switch = group['switch']
sw_dict = ret_dict.setdefault('switch', {}).setdefault(switch, {})

# Fantray : good
# Power consumed by Fantray : 540 Watts
# Fantray airflow direction : side-to-side
# Fantray beacon LED: off
# Fantray status LED: green
# SYSTEM : GREEN
m = p10.match(line)
if m:
group = m.groupdict()
fantray_key = group['fantray_key'].strip().lower().replace(
' ', '_')
if 'power_consumed' in fantray_key:
fantray_value = int(group['fantray_value'])
fantray_key += '_watts'
else:
fantray_value = group['fantray_value']
if 'fantray' == fantray_key:
sw_dict.setdefault('fantray',
{}).setdefault('status', fantray_value)
else:
sw_dict.setdefault('fantray',
{}).setdefault(fantray_key,
fantray_value)

return ret_dict
Loading
Loading