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

Added new functions compatible with pyaoscx v2 #26

Open
wants to merge 27 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
18ffc89
get_ntp_associations: fix typo
alagoutte Jan 3, 2021
89f5078
README(.md): remove get_route_to (not yet available)
alagoutte Dec 29, 2020
9e73aa4
get_lldp_neighbors: remove extra colon on port return value
alagoutte Dec 29, 2020
4019d7e
get_arp_table: missing import vrf and arp from pyaoscx
alagoutte Dec 29, 2020
6d8a5f8
get_arp_table: return IP(v4) Address (and not MAC Address) for ip fie…
alagoutte Dec 29, 2020
fd03d0b
get_arp_table: need to remove '/rest/v1/system/vrfs/' from vrf name
alagoutte Jan 3, 2021
d7f6988
get_arp_table: prepend vrf name when specify vrf for found on vrf list
alagoutte Jan 3, 2021
a789f59
get_facts: fix when there is not hostname define on the switch
alagoutte Jan 6, 2021
3430b72
get_environement fix KeyError: 'cpu' when use with VSF
alagoutte Jan 6, 2021
83102db
get_environment: fix KeyError 'memory' whe use with VSF
alagoutte Jan 7, 2021
d848dc9
get_environment: like for CPU, there is multiple value for memory whe…
alagoutte Jan 7, 2021
12560ca
get_config: fix KeyError url
alagoutte Jan 7, 2021
87f0483
Merge pull request #8 from alagoutte/fix-readme-get-route-to
alvinc13 Jan 15, 2021
68a5c3f
Merge pull request #13 from alagoutte/fix-5-get-config
alvinc13 Jan 15, 2021
673ffe8
Merge pull request #12 from alagoutte/fix-3-get-environment-vsf
alvinc13 Jan 15, 2021
2f6a3a6
Merge pull request #11 from alagoutte/fix-get-facts-no-hostname
alvinc13 Jan 15, 2021
668afd5
Merge pull request #10 from alagoutte/fix-7-extra-colon-port-lldp-nei…
alvinc13 Jan 15, 2021
925c8b7
Merge pull request #9 from alagoutte/fix-typo-ntp
alvinc13 Jan 15, 2021
143024e
get_facts: fix when use on Virtual CX (OVA)
alagoutte Jan 17, 2021
9fd87ce
get_interfaces_counters: remove debug print (interface name)
alagoutte Apr 26, 2021
f91ef19
get_interfaces_counters: set intf_counter array with all counters and…
alagoutte Apr 29, 2021
160a4f9
get_interfaces_counters: Add RX/TX Errors and Dropped fields
alagoutte May 1, 2021
4cc6285
get_interfaces_counters: remove no longer needed comment
alagoutte May 1, 2021
7d3cc87
get_interfaces_counters: only query interfaces statistics
alagoutte May 1, 2021
b9f92e8
Merge pull request #16 from alagoutte/fix-and-enhance-interfaces-coun…
alvinc13 May 5, 2021
88ddacf
Merge pull request #15 from alagoutte/fix-get-facts-virtualcx
alvinc13 May 5, 2021
206b00b
Merge pull request #14 from alagoutte/fix-get-arp-table
alvinc13 May 5, 2021
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ may have not been properly tested in older versions.
* get_lldp_neighbors_detail - Get LLDP Neighbor details from a device.
* get_mac_address_table - Get the MAC Address table from a device.
* get_ntp_servers - Gets NTP information from a network device.
* get_route_to - Shows an IP route on a device.
* get_snmp_information - Get the SNMP information of a device.
* is_alive - Check to see if the connection to the device is up.
* ping - Execute a ping command from the device.
Expand Down
146 changes: 103 additions & 43 deletions napalm_aoscx/aoscx.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Aruba AOS-CX lib
import pyaoscx
from pyaoscx import session, interface, system, common_ops, port, lldp, mac
from pyaoscx import session, interface, system, common_ops, port, lldp, mac, vrf, arp

class AOSCXDriver(NetworkDriver):
"""NAPALM driver for Aruba AOS-CX."""
Expand Down Expand Up @@ -114,18 +114,31 @@ def get_facts(self):
* interface_list - List of the interfaces of the device
"""
systeminfo = pyaoscx.system.get_system_info(**self.session_info)
productinfo = pyaoscx.system.get_product_info(**self.session_info)
if systeminfo['platform_name'] == 'X86-64': #it is Virtual CX (OVA)
#there is no product_info on Virtual CX (OVA)...
productinfo = dict(
product_info = dict (
serial_number = "N/A",
product_name = "VirtualCX (OVA)",
)
)
else:
productinfo = pyaoscx.system.get_product_info(**self.session_info)

uptime_seconds = (int(systeminfo['boot_time']))/1000
if 'hostname' not in systeminfo:
hostname = "ArubaCX"
else:
hostname = systeminfo['hostname']

fact_info = {
'uptime': uptime_seconds,
'vendor': 'Aruba',
'os_version': systeminfo['software_info']['build_id'],
'serial_number': productinfo['product_info']['serial_number'],
'model': productinfo['product_info']['product_name'],
'hostname': systeminfo['hostname'],
'fqdn':systeminfo['hostname'],
'hostname': hostname,
'fqdn': hostname,
'interface_list': pyaoscx.interface.get_all_interface_names(**self.session_info)
}
return fact_info
Expand Down Expand Up @@ -183,8 +196,7 @@ def get_interfaces_counters(self):
"""
Implementation of NAPALM method get_interfaces_counters. This gives statistic information
for all interfaces that are on the switch.
Note: Not currently implementing tx_errors, rx_errors, rx_discards, and tx_discards, and
those values will return -1.
Note: rx_discards, and tx_discards are equal to rx/tx dropped counters on Aruba CX
:return: Returns a dictionary of dictionaries where the first key is an interface name
and the inner dictionary contains the following keys:

Expand All @@ -204,32 +216,62 @@ def get_interfaces_counters(self):
interface_stats_dictionary = {}
interface_list = pyaoscx.interface.get_all_interface_names(**self.session_info)
for line in interface_list:
interface_details = pyaoscx.interface.get_interface(line, **self.session_info)
print(interface_details['name'])
interface_stats_dictionary.update(
{
line: {
'tx_errors': -1,
'rx_errors': -1,
'tx_discards': -1,
'rx_discards': -1,
'tx_octets': interface_details['statistics']['tx_bytes'],
'rx_octets': interface_details['statistics']['rx_bytes'],
'tx_unicast_packets':
interface_details['statistics']['if_hc_out_unicast_packets'],
'rx_unicast_packets':
interface_details['statistics']['if_hc_in_unicast_packets'],
'tx_multicast_packets':
interface_details['statistics']['if_out_multicast_packets'],
'rx_multicast_packets':
interface_details['statistics']['if_in_multicast_packets'],
'tx_broadcast_packets':
interface_details['statistics']['if_out_broadcast_packets'],
'rx_broadcast_packets':
interface_details['statistics']['if_in_broadcast_packets']
}
}
)
interface_details = pyaoscx.interface.get_interface(
line, selector="statistics", **self.session_info)
intf_counter = {
'tx_errors': 0,
'rx_errors': 0,
'tx_discards': 0,
'rx_discards': 0,
'tx_octets': 0,
'rx_octets': 0,
'tx_unicast_packets': 0,
'rx_unicast_packets': 0,
'tx_multicast_packets': 0,
'rx_multicast_packets': 0,
'tx_broadcast_packets': 0,
'rx_broadcast_packets': 0
}
if 'tx_bytes' in interface_details['statistics']:
intf_counter['tx_octets'] = interface_details['statistics']['tx_bytes']

if 'rx_bytes' in interface_details['statistics']:
intf_counter['rx_octets'] = interface_details['statistics']['rx_bytes']

if 'if_hc_out_unicast_packets' in interface_details['statistics']:
intf_counter['tx_unicast_packets'] = interface_details['statistics']['if_hc_out_unicast_packets']

if 'if_hc_in_unicast_packets' in interface_details['statistics']:
intf_counter['rx_unicast_packets'] = interface_details['statistics']['if_hc_in_unicast_packets']

if 'if_out_multicast_packets' in interface_details['statistics']:
intf_counter['tx_multicast_packets'] = interface_details['statistics']['if_out_multicast_packets']

if 'if_in_multicast_packets' in interface_details['statistics']:
intf_counter['rx_multicast_packets'] = interface_details['statistics']['if_in_multicast_packets']

if 'if_out_broadcast_packets' in interface_details['statistics']:
intf_counter['rx_bytes'] = interface_details['statistics']['if_out_broadcast_packets']

if 'if_in_broadcast_packets' in interface_details['statistics']:
intf_counter['rx_broadcast_packets'] = interface_details['statistics']['if_in_broadcast_packets']

if 'tx_errors' in interface_details['statistics']:
intf_counter['tx_errors'] = interface_details['statistics']['tx_errors']

if 'rx_errors' in interface_details['statistics']:
intf_counter['rx_errors'] = interface_details['statistics']['rx_errors']

if 'tx_dropped' in interface_details['statistics']:
intf_counter['tx_discards'] = interface_details['statistics']['tx_dropped']

if 'rx_dropped' in interface_details['statistics']:
intf_counter['rx_discards'] = interface_details['statistics']['rx_dropped']

interface_stats_dictionary.update({
line: intf_counter
})

return interface_stats_dictionary

def get_lldp_neighbors(self):
Expand All @@ -256,7 +298,7 @@ def get_lldp_neighbors(self):
lldp_brief_return[interface_name].append(
{
'hostname': interface_details['neighbor_info']['chassis_name'],
'port:': interface_details['port_id']
'port': interface_details['port_id']
}
)

Expand Down Expand Up @@ -382,16 +424,30 @@ def get_environment(self):
cpu_dict = {}
mem_dict = {}
for mm in resources_details:
if 'cpu' not in mm['resource_utilization']:
cpu = 'N/A'
else:
cpu = mm['resource_utilization']['cpu']

new_dict = {
mm['name']: {
'%usage': mm['resource_utilization']['cpu']
'%usage': cpu
}
}
cpu_dict.update(new_dict)
mem_dict = {
'available_ram': 'N/A',
'used_ram': mm['resource_utilization']['memory']

if 'memory' not in mm['resource_utilization']:
memory = 'N/A'
else:
memory = mm['resource_utilization']['memory']

new_dict = {
mm['name']: {
'available_ram': 'N/A',
'used_ram': memory
}
}
mem_dict.update(new_dict)

environment = {
'fans': fan_dict,
Expand Down Expand Up @@ -419,16 +475,20 @@ def get_arp_table(self, vrf=""):
"""
arp_entries = []
vrf_list = pyaoscx.vrf.get_all_vrfs(**self.session_info)
#prepend vrf
vrf = '/rest/v1/system/vrfs/' + vrf
if vrf in vrf_list:
vrf_list = [vrf]
for vrf_entry in vrf_list:
arp_list = pyaoscx.arp.get_arp_entries(vrf_entry, **self.session_info)
#remove '/rest/v1/system/vrfs' from vrf name...
myvrf = vrf_entry.replace('/rest/v1/system/vrfs/','')
arp_list = pyaoscx.arp.get_arp_entries(myvrf, **self.session_info)
for entry in arp_list:
arp_entries.append(
{
'interface': entry['Physical Port'],
'mac': entry['MAC Address'],
'ip': entry['MAC Address'],
'ip': entry['IPv4 Address'],
'age': 0.0
}
)
Expand Down Expand Up @@ -608,9 +668,9 @@ def get_config(self, retrieve="all", full=False):
"candidate": ""
}
if retrieve in ["running", "all"]:
config_dict['running'] = self._get_json_configuration("running-config")
config_dict['running'] = self._get_json_configuration("running-config", **self.session_info)
if retrieve in ["startup", "all"]:
config_dict['startup'] = self._get_json_configuration("startup-config")
config_dict['startup'] = self._get_json_configuration("startup-config", **self.session_info)
if retrieve in ["candidate", "all"]:
config_dict['candidate'] = self.candidate_config

Expand Down Expand Up @@ -866,11 +926,11 @@ def _get_ntp_associations(self, params={}, **kwargs):
associations_dict[server_name] = {}

if not common_ops._response_ok(response, "GET"):
logging.warning("FAIL: Getting dictionary of resource utilization info failed with status code %d: %s"
logging.warning("FAIL: Getting dictionary of NTP associations information failed with status code %d: %s"
% (response.status_code, response.text))
associations_dict = {}
else:
logging.info("SUCCESS: Getting dictionary of resource utilization information succeeded")
logging.info("SUCCESS: Getting dictionary of NTP associations information succeeded")
associations_dict = response.json()

return associations_dict
Expand Down