-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Environment - Tested with 2930M Standalone and Stac…
…ked, 2930F
- Loading branch information
Showing
16 changed files
with
340 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Get the environment variables of the switch/es""" | ||
|
||
import logging | ||
|
||
from napalm.base.helpers import textfsm_extractor | ||
|
||
logger = logging.getLogger("arubaoss.helper.get_environment") | ||
|
||
|
||
def get_environment(self): | ||
""" | ||
Get device's Environment table. | ||
:param self: object from class | ||
:return: | ||
""" | ||
|
||
out = { | ||
"fans": {}, | ||
"temperature": {}, | ||
"power": {}, | ||
"cpu": {}, | ||
"memory": {} | ||
} | ||
|
||
raw_system = self.connection.run_cmd("show system") | ||
system_list = textfsm_extractor(self, "show_system", raw_system) | ||
|
||
memtotal = 0 | ||
memfree = 0 | ||
|
||
for switch in system_list: | ||
member = switch.pop("member") | ||
if member == "": | ||
member = 0 | ||
else: | ||
member = "Member " + member | ||
|
||
out["cpu"][member] = { | ||
"%usage": float(switch.pop("cpu")) | ||
} | ||
|
||
memtotal += int(switch.pop("memtotal").replace(',', '')) | ||
memfree += int(switch.pop("memfree").replace(',', '')) | ||
|
||
out["memory"] = { | ||
"available_ram": int(memtotal), | ||
"used_ram": int(memfree) | ||
} | ||
|
||
raw_system_fans = self.connection.run_cmd("show system fans") | ||
system_fans_list = textfsm_extractor(self, "show_system_fans", raw_system_fans) | ||
for fan in system_fans_list: | ||
member = fan.pop("member") | ||
if member != "": | ||
member = "Member " + member + " " | ||
|
||
out["fans"][member + fan.pop('location') + " " + fan.pop('num')] = { | ||
"status": True if fan.pop('state') == "Fan OK" else False | ||
} | ||
|
||
raw_system_temperature = self.connection.run_cmd("show system temperature") | ||
system_temperature_list = textfsm_extractor(self, "show_system_temperature", raw_system_temperature) | ||
for temp in system_temperature_list: | ||
member = temp.pop("member") | ||
if member != "": | ||
member = "Member " + member + " " | ||
|
||
overtemp = True if temp.pop('overtemp') == "YES" else False | ||
|
||
out["temperature"][member + temp.pop('sensor')] = { | ||
"temperature": float(temp.pop('temperature')), | ||
"is_alert": overtemp, | ||
"is_critical": overtemp | ||
} | ||
|
||
raw_system_power = self.connection.run_cmd("show system power-supply") | ||
system_power_list = textfsm_extractor(self, "show_system_power-supply", raw_system_power) | ||
for power in system_power_list: | ||
member = power.pop("member") | ||
if member != "": | ||
member = "Member " + member + " " | ||
|
||
out["power"][member + power.pop('ps')] = { | ||
"status": True if power.pop('state') == "Powered" else False, | ||
"capacity": float(power.pop('max')), | ||
"output": float(power.pop('wattage')) | ||
} | ||
|
||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Value Filldown Member (\d) | ||
Value Required CPU (\d+) | ||
Value MemTotal (.{5,}) | ||
Value MemFree (.{5,}) | ||
|
||
Start | ||
^.*General System -> System | ||
|
||
System | ||
^\s+Member\s+:${Member} | ||
^.*Total\s+:\s${MemTotal} | ||
^.*CPU\sUtil\s\(%\)\s+:\s${CPU} -> Continue | ||
^.*Free\s+:\s${MemFree} -> Record |
12 changes: 12 additions & 0 deletions
12
napalm_arubaoss/utils/textfsm_templates/show_system_fans.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Value Filldown Member (\d) | ||
Value Required NUM (\S+) | ||
Value STATE (\S+\s+\S+) | ||
Value FAILURES (\d+) | ||
Value LOCATION (\S+) | ||
|
||
Start | ||
^.*Fan Information -> Fans | ||
|
||
Fans | ||
^Member\s+${Member} | ||
^${NUM}\s+\|\s+${STATE}\s+\|\s+${FAILURES}\s+\|\s+${LOCATION} -> Record |
15 changes: 15 additions & 0 deletions
15
napalm_arubaoss/utils/textfsm_templates/show_system_power-supply.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Value Member (\d) | ||
Value PS (\d) | ||
Value State (\S+) | ||
Value Wattage (\d+) | ||
Value Max (\d+) | ||
|
||
Start | ||
^.*Member\s+PS#\s+Model\s+Serial\s+State\s+AC\/DC\s+\+\sV\s+Wattage\s+Max -> Member | ||
^.*PS#\s+Model\s+Serial\s+State\s+AC\/DC\s+\+\sV\s+Wattage\s+Max -> Standalone | ||
|
||
Standalone | ||
^ ${PS}\s+\S+\s+\S+\s+${State}\s+\S\S\s\d+\S+\d+\S\s+${Wattage}\s+${Max} -> Record | ||
|
||
Member | ||
^ ${Member}\s+${PS}\s+\S+\s+\S+\s+${State}\s+\S\S\s\d+\S+\d+\S\s+${Wattage}\s+${Max} -> Record |
11 changes: 11 additions & 0 deletions
11
napalm_arubaoss/utils/textfsm_templates/show_system_temperature.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Value Filldown Member (\d) | ||
Value Required Sensor (\S+) | ||
Value Temperature (\d+) | ||
Value OverTemp (YES|NO) | ||
|
||
Start | ||
^.*Air -> Temperature | ||
|
||
Temperature | ||
^ Member ${Member} | ||
^ ${Sensor}\s+${Temperature}\S\s+\d+\S\s+\d+\S\s+\d+\S\s+${OverTemp} -> Record |
6 changes: 6 additions & 0 deletions
6
test/unit/mocked_data/test_get_environment/normal/cli_mapping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"show system": "\n Status and Counters - General System Information\n\n System Name : Name\n System Contact : Contact\n System Location : Location\n\n MAC Age Time (sec) : 300\n\n Time Zone : 0\n Daylight Time Rule : None\n\n Software revision : WC.16.11.0001 Base MAC Addr : 1a3b3c-4d5e6f\n ROM Version : WC.17.02.0007 Serial Number : NANANANANA\n\n Up Time : 68 days Memory - Total : 338,190,848\n CPU Util (%) : 0 Free : 177,716,208\n\n IP Mgmt - Pkts Rx : 260,263 Packet - Total : 6600\n Pkts Tx : 263,776 Buffers Free : 4347\n Lowest : 4216\n Missed : 0\n\n", | ||
"show system fans": "\nFan Information\n Num | State | Failures | Location\n-------+-------------+----------+----------\nFan-1 | Fan OK | 0 | Chassis\nFan-2 | Fan OK | 0 | Chassis\nFan-3 | Fan OK | 0 | Chassis\nFan-4 | Fan OK | 0 | PS 1\nFan-5 | Fan OK | 0 | PS 2\n\n0 / 5 Fans in Failure State\n0 / 5 Fans have been in Failure State\n\n", | ||
"show system temperature": "\n System Air Temperature\n Temp Current Max Min\n Sensor Temp Temp Temp Threshold OverTemp\n ------- -------- ----- ----- ---------- ---------\n Chassis 12C 17C 10C 50C NO\n\n", | ||
"show system power-supply": "\nPower Supply Status:\n\n PS# Model Serial State AC/DC + V Wattage Max\n ----- --------- ----------- --------------- ----------------- --------- ------\n 1 JL086A NANANANANA Powered AC 120V/240V 14 680\n 2 JL086A NANANANANA Powered AC 120V/240V 19 680\n\n\n 2 / 2 supply bays delivering power.\n Currently supplying 33 W / 1360 W total power.\n\n" | ||
} |
47 changes: 47 additions & 0 deletions
47
test/unit/mocked_data/test_get_environment/normal/expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"fans": { | ||
"Chassis Fan-1": { | ||
"status": true | ||
}, | ||
"Chassis Fan-2": { | ||
"status": true | ||
}, | ||
"Chassis Fan-3": { | ||
"status": true | ||
}, | ||
"PS Fan-4": { | ||
"status": true | ||
}, | ||
"PS Fan-5": { | ||
"status": true | ||
} | ||
}, | ||
"temperature": { | ||
"Chassis": { | ||
"temperature": 12, | ||
"is_alert": false, | ||
"is_critical": false | ||
} | ||
}, | ||
"power": { | ||
"1": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 14 | ||
}, | ||
"2": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 19 | ||
} | ||
}, | ||
"cpu": { | ||
"0": { | ||
"%usage": 0 | ||
} | ||
}, | ||
"memory": { | ||
"available_ram": 338190848, | ||
"used_ram": 177716208 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
test/unit/mocked_data/test_get_environment/stack/cli_mapping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"show system": "\n Status and Counters - General System Information\n\n System Name : Switch101\n System Contact : Contact\n System Location : Location\n MAC Age Time (sec) : 300\n Time Zone : 0\n Daylight Time Rule : None\n\n Software revision : WC.16.11.0014\n Base MAC Addr : 1a3b3c-4d5e6f\n\n Member :1\n\n ROM Version : WC.17.02.0007\n Up Time : 119 days\n CPU Util (%) : 2\n MAC Addr : 1a3b3c-4d5e6f\n Serial Number : NANANANANA\n Memory - Total : 333,533,696\n Free : 169,758,520\n\n\n\n Member :2\n\n ROM Version : WC.17.02.0007\n Up Time : 11 days\n CPU Util (%) : 0\n MAC Addr : 1a3b3c-4d5e6f\n Serial Number : NANANANANA\n Memory - Total : 333,533,696\n Free : 186,152,132\n", | ||
"show system fans": "\nFan Information\n\nMember 1\n\n Num | State | Failures | Location\n-------+-------------+----------+----------\nSys-1 | Fan OK | 0 | Chassis\nSys-2 | Fan OK | 0 | Chassis\nSys-3 | Fan OK | 0 | Chassis\nSys-4 | Fan OK | 0 | PS 1\nSys-5 | Fan OK | 0 | PS 2\n\n0 / 5 Fans in Failure State\n0 / 5 Fans have been in Failure State\n\nMember 2\n\n Num | State | Failures | Location\n-------+-------------+----------+----------\nSys-1 | Fan OK | 0 | Chassis\nSys-2 | Fan OK | 0 | Chassis\nSys-3 | Fan OK | 0 | Chassis\nSys-4 | Fan OK | 0 | PS 1\nSys-5 | Fan OK | 0 | PS 2\n\n0 / 5 Fans in Failure State\n0 / 5 Fans have been in Failure State\n", | ||
"show system temperature": "\n System Air Temperatures\n\n Member 1\n\n Temp Current Max Min\n Sensor Temp Temp Temp Threshold OverTemp\n ------- -------- ----- ----- ---------- ---------\n Chassis 26C 26C 19C 55C NO\n\n\n Member 2\n\n Temp Current Max Min\n Sensor Temp Temp Temp Threshold OverTemp\n ------- -------- ----- ----- ---------- ---------\n Chassis 27C 27C 20C 50C NO\n\n\n", | ||
"show system power-supply": "\nPower Supply Status:\n\n Member PS# Model Serial State AC/DC + V Wattage Max\n ------- ----- --------- ----------- --------------- ----------------- --------- ------\n 1 1 JL086A NANANANANA Powered AC 120V/240V 79 680\n 1 2 JL086A NANANANANA Powered AC 120V/240V 66 680\n 2 1 JL086A NANANANANA Powered AC 120V/240V 29 680\n 2 2 JL086A NANANANANA Powered AC 120V/240V 38 680" | ||
} |
80 changes: 80 additions & 0 deletions
80
test/unit/mocked_data/test_get_environment/stack/expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"fans": { | ||
"Member 1 Chassis Sys-1": { | ||
"status": true | ||
}, | ||
"Member 1 Chassis Sys-2": { | ||
"status": true | ||
}, | ||
"Member 1 Chassis Sys-3": { | ||
"status": true | ||
}, | ||
"Member 1 PS Sys-4": { | ||
"status": true | ||
}, | ||
"Member 1 PS Sys-5": { | ||
"status": true | ||
}, | ||
"Member 2 Chassis Sys-1": { | ||
"status": true | ||
}, | ||
"Member 2 Chassis Sys-2": { | ||
"status": true | ||
}, | ||
"Member 2 Chassis Sys-3": { | ||
"status": true | ||
}, | ||
"Member 2 PS Sys-4": { | ||
"status": true | ||
}, | ||
"Member 2 PS Sys-5": { | ||
"status": true | ||
} | ||
}, | ||
"temperature": { | ||
"Member 1 Chassis": { | ||
"temperature": 26, | ||
"is_alert": false, | ||
"is_critical": false | ||
}, | ||
"Member 2 Chassis": { | ||
"temperature": 27, | ||
"is_alert": false, | ||
"is_critical": false | ||
} | ||
}, | ||
"power": { | ||
"Member 1 1": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 79 | ||
}, | ||
"Member 1 2": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 66 | ||
}, | ||
"Member 2 1": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 29 | ||
}, | ||
"Member 2 2": { | ||
"status": true, | ||
"capacity": 680, | ||
"output": 38 | ||
} | ||
}, | ||
"cpu": { | ||
"Member 1": { | ||
"%usage": 2 | ||
}, | ||
"Member 2": { | ||
"%usage": 0 | ||
} | ||
}, | ||
"memory": { | ||
"available_ram": 667067392, | ||
"used_ram": 355910652 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Value Filldown Member (\d) | ||
Value Required CPU (\d+) | ||
Value MemTotal (.{5,}) | ||
Value MemFree (.{5,}) | ||
|
||
Start | ||
^.*General System -> System | ||
|
||
System | ||
^\s+Member\s+:${Member} | ||
^.*Total\s+:\s${MemTotal} | ||
^.*CPU\sUtil\s\(%\)\s+:\s${CPU} -> Continue | ||
^.*Free\s+:\s${MemFree} -> Record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Value Filldown Member (\d) | ||
Value Required NUM (\S+) | ||
Value STATE (\S+\s+\S+) | ||
Value FAILURES (\d+) | ||
Value LOCATION (\S+) | ||
|
||
Start | ||
^.*Fan Information -> Fans | ||
|
||
Fans | ||
^Member\s+${Member} | ||
^${NUM}\s+\|\s+${STATE}\s+\|\s+${FAILURES}\s+\|\s+${LOCATION} -> Record |
Oops, something went wrong.