Skip to content

Commit

Permalink
Merge pull request #99 from dbarrosop/base_new_methods
Browse files Browse the repository at this point in the history
Base new methods
  • Loading branch information
dbarrosop committed Dec 2, 2015
2 parents 129a35e + d8bffd4 commit 2480c46
Show file tree
Hide file tree
Showing 48 changed files with 4,617 additions and 184 deletions.
192 changes: 108 additions & 84 deletions napalm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,87 +224,111 @@ def get_lldp_neighbors(self):
"""
raise NotImplementedError

# def get_bgp_neighbors(self):
# """
# Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf (global if no vrf).\
# The inner dictionary will containg the following data for each vrf:
# * local_as (int)
# * router_id
# * peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. The inner keys are:
# * is_up (True/False)
# * is_enabled (True/False)
# * remote_as (int)
# * description (string)
# * uptime (int in seconds)
# * received_prefixes (int)
# * accepted_prefixes (int)
# * sent_prefixes (int)
#
# For example:
#
# {
# u'default':
# {
# 'router_id': u'192.168.0.1',
# 'local_as': 65000,
# 'peers':
# {
# u'10.0.0.11':
# {
# 'is_up': True,
# 'is_enabled': True,
# 'uptime': 1429978587.950959,
# 'description': u'',
# 'received_prefixes': 2,
# 'sent_prefixes': 3,
# 'accepted_prefixes': 0,
# 'remote_as': 65001
# },
# u'1.1.1.1':
# {
# 'is_up': False,
# 'is_enabled': False,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 1
# }
# }
# },
# u'vrfA':
# {
# 'router_id': u'10.0.1.10',
# 'local_as': 65010,
# 'peers':
# {
# u'10.0.1.12':
# {
# 'is_up': False,
# 'is_enabled': True,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 65012
# },
# u'10.0.1.13':
# {
# 'is_up': False,
# 'is_enabled': True,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 65013
# }
# }
# }
# }
#
#
# """
# raise NotImplementedError
def get_bgp_neighbors(self):
"""
Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf (global if no vrf).
The inner dictionary will contain the following data for each vrf:
* router_id
* peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. The inner keys are:
* local_as (int)
* remote_as (int)
* remote_id - peer router id
* is_up (True/False)
* is_enabled (True/False)
* remote_as (int)
* description (string)
* uptime (int in seconds)
* address_family (dictionary) - A dictionary of address families available for the neighbor. So far it can
be 'ipv4' or 'ipv6'
* received_prefixes (int)
* accepted_prefixes (int)
* sent_prefixes (int)
"""
raise NotImplementedError

def get_environment(self):
"""
Returns a dictionary where:
* fans is a dictionary of dictionaries where the key is the location and the values:
* status (boolean) - True if it's ok, false if it's broken
* temperature is a dictionary of dictionaries where the key is the location and the values:
* temperature (float) - Temperature in celsius the sensor is reporting.
* is_alert (boolean) - True if the temperature is above the alert threshold
* is_critical (boolean) - True if the temperature is above the critical threshold
* power is a dictionary of dictionaries where the key is the PSU id and the values:
* status (boolean) - 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
"""
raise NotImplementedError

def get_interfaces_counters(self):
"""
Returns a dictionary of dictionaries where the first key is an interface name and the inner dictionary contains
the following keys:
* tx_errors (int)
* rx_errors (int)
* tx_discards (int)
* rx_discards (int)
* tx_octets (int)
* rx_octets (int)
* tx_unicast_packets (int)
* rx_unicast_packets (int)
* tx_multicast_packets (int)
* rx_multicast_packets (int)
* tx_broadcast_packets (int)
* rx_broadcast_packets (int)
Example:
{
u'Ethernet2': {
'tx_multicast_packets': 699,
'tx_discards': 0,
'tx_octets': 88577,
'tx_errors': 0,
'rx_octets': 0,
'tx_unicast_packets': 0,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 0,
'rx_discards': 0,
'rx_unicast_packets': 0
},
u'Management1': {
'tx_multicast_packets': 0,
'tx_discards': 0,
'tx_octets': 159159,
'tx_errors': 0,
'rx_octets': 167644,
'tx_unicast_packets': 1241,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 80,
'rx_discards': 0,
'rx_unicast_packets': 0
},
u'Ethernet1': {
'tx_multicast_packets': 293,
'tx_discards': 0,
'tx_octets': 38639,
'tx_errors': 0,
'rx_octets': 0,
'tx_unicast_packets': 0,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 0,
'rx_discards': 0,
'rx_unicast_packets': 0
}
}
"""
raise NotImplementedError
113 changes: 112 additions & 1 deletion napalm/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# the License.

import pyeapi
import re

from base import NetworkDriver

Expand Down Expand Up @@ -180,7 +181,7 @@ def get_interfaces(self):
interfaces[interface]['last_flapped'] = values.pop('lastStatusChangeTimestamp', None)

interfaces[interface]['speed'] = values['bandwidth']
interfaces[interface]['mac_address'] = values.pop('physicalAddress', None)
interfaces[interface]['mac_address'] = values.pop('physicalAddress', u'')

return interfaces

Expand All @@ -204,6 +205,40 @@ def get_lldp_neighbors(self):

return lldp

def get_interfaces_counters(self):
commands = list()

commands.append('show interfaces counters')
commands.append('show interfaces counters errors')

output = self.device.run_commands(commands)

interface_counters = dict()

for interface, counters in output[0]['interfaces'].iteritems():
interface_counters[interface] = dict()

interface_counters[interface]['tx_octets'] = counters['outOctets']
interface_counters[interface]['rx_octets'] = counters['inOctets']
interface_counters[interface]['tx_unicast_packets'] = counters['outUcastPkts']
interface_counters[interface]['rx_unicast_packets'] = counters['inUcastPkts']
interface_counters[interface]['tx_multicast_packets'] = counters['outMulticastPkts']
interface_counters[interface]['rx_multicast_packets'] = counters['inMulticastPkts']
interface_counters[interface]['tx_broadcast_packets'] = counters['outBroadcastPkts']
interface_counters[interface]['rx_broadcast_packets'] = counters['inBroadcastPkts']
interface_counters[interface]['tx_discards'] = counters['outDiscards']
interface_counters[interface]['rx_discards'] = counters['inDiscards']

# Errors come from a different command
errors = output[1]['interfaceErrorCounters'][interface]
interface_counters[interface]['tx_errors'] = errors['outErrors']
interface_counters[interface]['rx_errors'] = errors['inErrors']


return interface_counters



# def get_bgp_neighbors(self):
# bgp_neighbors = dict()
#
Expand Down Expand Up @@ -245,3 +280,79 @@ def get_lldp_neighbors(self):
# bgp_neighbors[vrf]['peers'][n]['description'] = n_data_full.pop('Description', '')
#
# return bgp_neighbors

def get_environment(self):
"""
Returns a dictionary where:
* fans is a dictionary of dictionaries where the key is the location and the values:
* status (boolean) - True if it's ok, false if it's broken
* temperature is a dictionary of dictionaries where the key is the location and the values:
* temperature (int) - Temperature in celsius the sensor is reporting.
* is_alert (boolean) - True if the temperature is above the alert threshold
* is_critical (boolean) - True if the temperature is above the critical threshold
* power is a dictionary of dictionaries where the key is the PSU id and the values:
* status (boolean) - True if it's ok, false if it's broken
* capacity (int) - Capacity in W that the power supply can support
* output (int) - Watts drawn by the system
* cpu is a dictionary of dictionaries where the key is the ID and the values
* %usage
* available_ram (int) - Total amount of RAM installed in the device
* used_ram (int) - RAM that is still free in the device
"""
command = list()
command.append('show environment cooling')
command.append('show environment temperature')
command.append('show environment power')
output = self.device.run_commands(command)

environment_counters = dict()
environment_counters['fans'] = dict()
environment_counters['temperature'] = dict()
environment_counters['power'] = dict()
environment_counters['cpu'] = dict()
environment_counters['available_ram'] = ''
environment_counters['used_ram'] = ''

fans_output = output[0]
temp_output = output[1]
power_output = output[2]
cpu_output = self.device.run_commands(['show processes top once'], encoding='text')[0]['output']

''' Get fans counters '''
for slot in fans_output['fanTraySlots']:
environment_counters['fans'][slot['label']] = dict()
environment_counters['fans'][slot['label']]['status'] = slot['status'] == 'ok'

''' Get temp counters '''
for slot in temp_output:
try:
for sensorsgroup in temp_output[slot]:
for sensor in sensorsgroup['tempSensors']:
environment_counters['temperature'][sensor['name']] = {
'temperature': sensor['currentTemperature'],
'is_alert': sensor['currentTemperature'] > sensor['overheatThreshold'],
'is_critical': sensor['currentTemperature'] > sensor['criticalThreshold']
}
except:
pass

''' Get power counters '''
for _, item in power_output.iteritems():
for id, ps in item.iteritems():
environment_counters['power'][id] = {
'status': ps['state'] == 'ok',
'capacity': ps['capacity'],
'output': ps['outputPower']
}

''' Get CPU counters '''
m = re.search('(\d+.\d+)\%', cpu_output.splitlines()[2])
environment_counters['cpu'][0] = float(m.group(1))
m = re.search('(\d+)k\W+total\W+(\d+)k\W+used\W+(\d+)k\W+free', cpu_output.splitlines()[3])

environment_counters['memory'] = {
'available_ram': int(m.group(1)),
'used_ram': int(m.group(2))
}

return environment_counters

0 comments on commit 2480c46

Please sign in to comment.