Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Implement get_lldp_neighbors_detail() getter and make adjustements to…
Browse files Browse the repository at this point in the history
… show_lldp_remote-device_detail textfsm template
  • Loading branch information
Gary T. Giesen committed Jun 10, 2020
1 parent d18545c commit 6413bcc
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 85 deletions.
246 changes: 165 additions & 81 deletions napalm_dellos6/dellos6.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,87 +476,6 @@ def get_lldp_neighbors(self):

return lldp

def get_environment(self):
"""
Returns a dictionary where:
* fans is a dictionary of dictionaries where the key is the location and the values:
* status (True/False) - True if it's ok, false if it's broken
* temperature is a dict of dictionaries where the key is the location and the values:
* temperature (float) - Temperature in celsius the sensor is reporting.
* is_alert (True/False) - True if the temperature is above the alert threshold
* is_critical (True/False) - True if the temp is above the critical threshold
* power is a dictionary of dictionaries where the key is the PSU id and the values:
* status (True/False) - True if it's ok, false if it's broken
* capacity (float) - Capacity in W that the power supply can support
* output (float) - Watts drawn by the system
* cpu is a dictionary of dictionaries where the key is the ID and the values
* %usage
* memory is a dictionary with:
* available_ram (int) - Total amount of RAM installed in the device
* used_ram (int) - RAM in use in the device
* cpu is using 1-minute average
* cpu hard-coded to cpu0 (i.e. only a single CPU)
"""

raw_show_sys = self._send_command("show system")
raw_show_proc_cpu = self._send_command("show process cpu")

show_sys_fans = textfsm_extractor(
self, "show_system-fans", raw_show_sys
)
show_sys_temps = textfsm_extractor(
self, "show_system-temps", raw_show_sys
)
show_sys_power = textfsm_extractor(
self, "show_system-power_supplies", raw_show_sys
)
show_proc_cpu = textfsm_extractor(
self, "show_process_cpu", raw_show_proc_cpu
)

environment = {}
environment.setdefault("fans", {})
environment.setdefault("temperature", {})
environment.setdefault("power", {})
environment.setdefault("cpu", {})
environment.setdefault("memory", {})

for fan in show_sys_fans:
environment["fans"].setdefault("unit " + fan["unit"], {})
environment["fans"]["unit " + fan["unit"]].setdefault(fan["description"], {})
if fan["status"] == "OK":
environment["fans"]["unit " + fan["unit"]][fan["description"]]["status"] = True
else:
environment["fans"]["unit " + fan["unit"]][fan["description"]]["status"] = False
for temp in show_sys_temps:
environment["temperature"].setdefault("unit " + temp["unit"], {})
environment["temperature"]["unit " + temp["unit"]].setdefault(temp["description"], {})
environment["temperature"]["unit " + temp["unit"]][temp["description"]] = {
"temperature": float(temp["temp"]),
"is_alert": False,
"is_critical": False,
}
for power in show_sys_power:
environment["power"].setdefault("unit " + power["unit"], {})
environment["power"]["unit " + power["unit"]].setdefault(power["description"], {})
environment["power"]["unit " + power["unit"]][power["description"]] = {
"status": False,
"capacity": -1.0,
"output": float(power["pwr_cur"]),
}
if power["status"] == "OK":
environment["power"]["unit " + power["unit"]][power["description"]]["status"] = True
environment["cpu"][0] = {}
environment["cpu"][0]["%usage"] = 0.0
environment["cpu"][0]["%usage"] = show_proc_cpu[0]['cpu_60']
environment["memory"] = {
"available_ram": int(show_proc_cpu[0]['mem_free']) * 1024,
"used_ram": int(show_proc_cpu[0]['mem_alloc']) * 1024,
}

return environment

def get_interfaces_counters(self):
"""
Returns a dictionary of dictionaries where the first key is an interface name and the
Expand Down Expand Up @@ -681,3 +600,168 @@ def get_interfaces_counters(self):
int_counters[int_list]['rx_broadcast_packets'] = int(int_count['in_bcast_pkts'])

return int_counters

def get_environment(self):
"""
Returns a dictionary where:
* fans is a dictionary of dictionaries where the key is the location and the values:
* status (True/False) - True if it's ok, false if it's broken
* temperature is a dict of dictionaries where the key is the location and the values:
* temperature (float) - Temperature in celsius the sensor is reporting.
* is_alert (True/False) - True if the temperature is above the alert threshold
* is_critical (True/False) - True if the temp is above the critical threshold
* power is a dictionary of dictionaries where the key is the PSU id and the values:
* status (True/False) - True if it's ok, false if it's broken
* capacity (float) - Capacity in W that the power supply can support
* output (float) - Watts drawn by the system
* cpu is a dictionary of dictionaries where the key is the ID and the values
* %usage
* memory is a dictionary with:
* available_ram (int) - Total amount of RAM installed in the device
* used_ram (int) - RAM in use in the device
* cpu is using 1-minute average
* cpu hard-coded to cpu0 (i.e. only a single CPU)
"""

raw_show_sys = self._send_command("show system")
raw_show_proc_cpu = self._send_command("show process cpu")

show_sys_fans = textfsm_extractor(
self, "show_system-fans", raw_show_sys
)
show_sys_temps = textfsm_extractor(
self, "show_system-temps", raw_show_sys
)
show_sys_power = textfsm_extractor(
self, "show_system-power_supplies", raw_show_sys
)
show_proc_cpu = textfsm_extractor(
self, "show_process_cpu", raw_show_proc_cpu
)

environment = {}
environment.setdefault("fans", {})
environment.setdefault("temperature", {})
environment.setdefault("power", {})
environment.setdefault("cpu", {})
environment.setdefault("memory", {})

for fan in show_sys_fans:
environment["fans"].setdefault("unit " + fan["unit"], {})
environment["fans"]["unit " + fan["unit"]].setdefault(fan["description"], {})
if fan["status"] == "OK":
environment["fans"]["unit " + fan["unit"]][fan["description"]]["status"] = True
else:
environment["fans"]["unit " + fan["unit"]][fan["description"]]["status"] = False
for temp in show_sys_temps:
environment["temperature"].setdefault("unit " + temp["unit"], {})
environment["temperature"]["unit " + temp["unit"]].setdefault(temp["description"], {})
environment["temperature"]["unit " + temp["unit"]][temp["description"]] = {
"temperature": float(temp["temp"]),
"is_alert": False,
"is_critical": False,
}
for power in show_sys_power:
environment["power"].setdefault("unit " + power["unit"], {})
environment["power"]["unit " + power["unit"]].setdefault(power["description"], {})
environment["power"]["unit " + power["unit"]][power["description"]] = {
"status": False,
"capacity": -1.0,
"output": float(power["pwr_cur"]),
}
if power["status"] == "OK":
environment["power"]["unit " + power["unit"]][power["description"]]["status"] = True
environment["cpu"][0] = {}
environment["cpu"][0]["%usage"] = 0.0
environment["cpu"][0]["%usage"] = show_proc_cpu[0]['cpu_60']
environment["memory"] = {
"available_ram": int(show_proc_cpu[0]['mem_free']) * 1024,
"used_ram": int(show_proc_cpu[0]['mem_alloc']) * 1024,
}

return environment

def get_lldp_neighbors_detail(self, interface=""):
"""
Returns a detailed view of the LLDP neighbors as a dictionary
containing lists of dictionaries for each interface.
Empty entries are returned as an empty string (e.g. '') or list where applicable.
Inner dictionaries contain fields:
* parent_interface (string)
* remote_port (string)
* remote_port_description (string)
* remote_chassis_id (string)
* remote_system_name (string)
* remote_system_description (string)
* remote_system_capab (list) with any of these values
* other
* repeater
* bridge
* wlan-access-point
* router
* telephone
* docsis-cable-device
* station
* remote_system_enabled_capab (list)
Example::
{
'TenGigE0/0/0/8': [
{
'parent_interface': u'Bundle-Ether8',
'remote_chassis_id': u'8c60.4f69.e96c',
'remote_system_name': u'switch',
'remote_port': u'Eth2/2/1',
'remote_port_description': u'Ethernet2/2/1',
'remote_system_description': u'''Cisco Nexus Operating System (NX-OS)
Software 7.1(0)N1(1a)
TAC support: http://www.cisco.com/tac
Copyright (c) 2002-2015, Cisco Systems, Inc. All rights reserved.''',
'remote_system_capab': ['bridge', 'repeater'],
'remote_system_enable_capab': ['bridge']
}
]
}
"""
raw_show_lldp_remote_device_all = self._send_command("show lldp remote-device all")

show_lldp_remote_device_all = textfsm_extractor(
self, "show_lldp_remote-device_all", raw_show_lldp_remote_device_all
)

lldp = {}
for lldp_entry in show_lldp_remote_device_all:
lldp[lldp_entry['interface']] = {}
raw_show_lldp_remote_device_detail = self._send_command("show lldp remote-device detail " + lldp_entry['interface'])
show_lldp_remote_device_detail = textfsm_extractor(
self, "show_lldp_remote-device_detail", raw_show_lldp_remote_device_detail
)
print(raw_show_lldp_remote_device_detail)
print(show_lldp_remote_device_detail)
parent_interface = ''
remote_chassis_id = lldp_entry['chassis_id']
remote_system_name = show_lldp_remote_device_detail[0]['host_name']
remote_port = show_lldp_remote_device_detail[0]['port_id']
remote_port_description = show_lldp_remote_device_detail[0]['port_desc']
remote_system_description = show_lldp_remote_device_detail[0]['sys_desc']
if show_lldp_remote_device_detail[0]['sys_cap_sup']:
remote_system_capab = show_lldp_remote_device_detail[0]['sys_cap_sup'].replace(" ", "").split(",")
else:
remote_system_capab = []
if show_lldp_remote_device_detail[0]['sys_cap_oper']:
remote_system_enable_capab = show_lldp_remote_device_detail[0]['sys_cap_oper'].replace(" ", "").split(",")
else:
remote_system_enable_capab = []

lldp[lldp_entry['interface']] = {
"parent_interface": parent_interface,
"remote_chassis_id": remote_chassis_id,
"remote_system_name": remote_system_name,
"remote_port": remote_port,
"remote_port_description": remote_port_description,
"remote_system_description": remote_system_description,
"remote_system_capab": remote_system_capab,
"remote_system_enable_capab": remote_system_enable_capab,
}

return lldp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Value CHASSIS_ID (\S+)
Value PORT_ID_SUBTYPE (\S+)
Value PORT_ID (\S+)
Value HOST_NAME (\S+)
Value SYS_DESC (.+)
Value PORT_DESC (.*)
Value SYS_CAP_SUP (.*)
Value SYS_CAP_OPER (.*)
Expand All @@ -17,9 +18,10 @@ Start
^Chassis ID\:\s+${CHASSIS_ID}
^Port ID Subtype\:\s+${PORT_ID_SUBTYPE}
^Port ID\:\s+${PORT_ID}
^System Name\:\s+${HOST_NAME}
^Port Description:\s+${PORT_DESC}
^System Capabilities Supported\:\s+${SYS_CAP_SUP}
^System Capabilities Enabled\:\s+${SYS_CAP_OPER} -> Record
^System Name\:\s*${HOST_NAME}
^System Description\:\s*${SYS_DESC}
^Port Description:\s*${PORT_DESC}
^System Capabilities Supported\:\s*${SYS_CAP_SUP}
^System Capabilities Enabled\:\s*${SYS_CAP_OPER} -> Record

EOF

0 comments on commit 6413bcc

Please sign in to comment.