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

Fix exception when trying to get environmental data from certain Nexus devices #1133

Merged
merged 5 commits into from
Mar 4, 2020
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
28 changes: 22 additions & 6 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,12 @@ def get_network_instances(self, name=""):
def get_environment(self):
def _process_pdus(power_data):
normalized = defaultdict(dict)
ps_info_table = power_data["TABLE_psinfo"]
# some nexus devices have keys postfixed with the shorthand device series name (ie n3k)
# ex. on a 9k, the key is TABLE_psinfo, but on a 3k it is TABLE_psinfo_n3k
ps_info_key = [
i for i in power_data.keys() if i.startswith("TABLE_psinfo")
][0]
ps_info_table = power_data[ps_info_key]
# Later version of nxos will have a list under TABLE_psinfo like
# TABLE_psinfo : [{'ROW_psinfo': {...
# and not have the psnum under the row
Expand All @@ -1383,17 +1388,28 @@ def _process_pdus(power_data):
count += 1
tmp_table.append(tmp)
ps_info_table = {"ROW_psinfo": tmp_table}
for psinfo in ps_info_table["ROW_psinfo"]:
# some nexus devices have keys postfixed with the shorthand device series name (ie n3k)
# ex. on a 9k the key is ROW_psinfo, but on a 3k it is ROW_psinfo_n3k
ps_info_row_key = [
i for i in ps_info_table.keys() if i.startswith("ROW_psinfo")
][0]
for psinfo in ps_info_table[ps_info_row_key]:
normalized[psinfo["psnum"]]["status"] = (
psinfo.get("ps_status", "ok") == "ok"
)
normalized[psinfo["psnum"]]["output"] = float(psinfo.get("watts", -1.0))
# Newer nxos versions provide the total capacity in the `tot_capa` key
if "tot_capa" in psinfo:
normalized[psinfo["psnum"]]["capacity"] = float(
psinfo["tot_capa"].split()[0]
)
# The capacity of the power supply can be determined by the model
# ie N2200-PAC-400W = 400 watts
ps_model = psinfo.get("psmodel", "-1")
normalized[psinfo["psnum"]]["capacity"] = float(
ps_model.split("-")[-1][:-1]
)
else:
ps_model = psinfo.get("psmodel", "-1")
normalized[psinfo["psnum"]]["capacity"] = float(
ps_model.split("-")[-1][:-1]
)
return json.loads(json.dumps(normalized))

def _process_fans(fan_data):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"cpu": {
"0": {
"%usage": 5.55
}
},
"fans": {
"Fan1(sys_fan1)": {
"status": true
},
"Fan2(sys_fan2)": {
"status": true
},
"Fan3(sys_fan3)": {
"status": true
},
"Fan4(sys_fan4)": {
"status": true
}
},
"memory": {
"available_ram": 426000,
"used_ram": 36000
},
"power": {
"1": {
"capacity": 500.0,
"output": 504.0,
"status": true
},
"2": {
"capacity": 500.0,
"output": 504.0,
"status": true
}
},
"temperature": {
"1-1 ASIC": {
"is_alert": false,
"is_critical": false,
"temperature": 55.0
},
"1-2 Front-Left (D1)": {
"is_alert": false,
"is_critical": false,
"temperature": 37.0
},
"1-3 Front-Right(D2)": {
"is_alert": false,
"is_critical": false,
"temperature": 32.0
},
"1-4 Back (D3)": {
"is_alert": false,
"is_critical": false,
"temperature": 25.0
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"powersup": {
"voltage_level": "12",
"TABLE_psinfo_n3k": {
"ROW_psinfo_n3k": [
{
"psnum": "1",
"psmodel": "NXA-PAC-500W",
"input_type": "AC",
"watts": "504.00",
"amps": "42.00",
"ps_status": "ok"
},
{
"psnum": "2",
"psmodel": "NXA-PAC-500W",
"input_type": "AC",
"watts": "504.00",
"amps": "42.00",
"ps_status": "ok"
}
]
},
"TABLE_mod_pow_info_n3k": {
"ROW_mod_pow_info_n3k": {
"modnum": "1",
"mod_model": "N3K-C3172TQ-XL",
"watts_requested": "348.00",
"amps_requested": "29.00",
"watts_alloced": "348.00",
"amps_alloced": "29.00",
"modstatus": "powered-up"
}
},
"power_summary_n3k": {
"ps_redun_mode": "Redundant",
"ps_redun_op_mode": "Redundant",
"tot_pow_capacity": "1008.00 W",
"reserve_sup": "348.00 W",
"pow_used_by_mods": "0.00 W",
"available_pow": "660.00 W"
}
},
"fandetails": {
"TABLE_faninfo": {
"ROW_faninfo": [
{
"fanname": "Fan1(sys_fan1)",
"fanmodel": "NXA-FAN-30CFM",
"fanhwver": "0.0",
"fandir": "front-to-back",
"fanstatus": "Ok",
"failfanlet": null
},
{
"fanname": "Fan2(sys_fan2)",
"fanmodel": "NXA-FAN-30CFM",
"fanhwver": "0.0",
"fandir": "front-to-back",
"fanstatus": "Ok",
"failfanlet": null
},
{
"fanname": "Fan3(sys_fan3)",
"fanmodel": "NXA-FAN-30CFM",
"fanhwver": "0.0",
"fandir": "front-to-back",
"fanstatus": "Ok",
"failfanlet": null
},
{
"fanname": "Fan4(sys_fan4)",
"fanmodel": "NXA-FAN-30CFM",
"fanhwver": "0.0",
"fandir": "front-to-back",
"fanstatus": "Ok",
"failfanlet": null
},
{
"fanname": "Fan_in_PS1",
"fanmodel": "NXA-PAC-500W",
"fanhwver": "--",
"fandir": "front-to-back",
"fanstatus": "Ok"
},
{
"fanname": "Fan_in_PS2",
"fanmodel": "NXA-PAC-500W",
"fanhwver": "--",
"fandir": "front-to-back",
"fanstatus": "Ok"
}
]
},
"TABLE_fan_zone_speed": {
"ROW_fan_zone_speed": {
"zone": "1",
"speed": "0x28"
}
},
"fan_filter_status": "NotSupported"
},
"TABLE_tempinfo": {
"ROW_tempinfo": [
{
"tempmod": "1",
"sensor": "ASIC",
"majthres": "110",
"minthres": "100",
"curtemp": "55",
"alarmstatus": "Ok"
},
{
"tempmod": "1",
"sensor": "Front-Left (D1)",
"majthres": "70",
"minthres": "60",
"curtemp": "37",
"alarmstatus": "Ok"
},
{
"tempmod": "1",
"sensor": "Front-Right(D2)",
"majthres": "70",
"minthres": "56",
"curtemp": "32",
"alarmstatus": "Ok"
},
{
"tempmod": "1",
"sensor": "Back (D3)",
"majthres": "70",
"minthres": "46",
"curtemp": "25",
"alarmstatus": "Ok"
}
]
}
}
Loading