Skip to content

Commit

Permalink
Merge pull request #15 from napalm-automation-community/get_interfaces
Browse files Browse the repository at this point in the history
get_interfaces added
  • Loading branch information
gcotone authored Dec 20, 2021
2 parents 60e8320 + dbd9e90 commit 7a705e9
Show file tree
Hide file tree
Showing 7 changed files with 697 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Driver implementation for Aruba OS Switch. Tested in AOS > WC.16.09.0004, some m
* get_facts() ✅
* get_firewall_policies() ❌*
* get_interfaces_counters() ❌***
* get_interfaces()
* get_interfaces()
* get_interfaces_ip() ✅
* get_ipv6_neighbors_table() ❌*
* get_lldp_neighbors() ✅
Expand Down
64 changes: 60 additions & 4 deletions napalm_arubaoss/ArubaOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_facts,
get_arp_table,
get_config,
get_interfaces,
get_interfaces_ip,
get_lldp_neighbors,
get_lldp_neighbors_detail,
Expand Down Expand Up @@ -260,11 +261,66 @@ def get_firewall_policies(self):

def get_interfaces(self):
"""
Get interfaces - NOT IMPLEMENTED.
Return a dictionary of dictionaries. The keys for the first dictionary will be the \
interfaces in the devices. The inner dictionary will contain the following data for \
each interface.
* is_up (True/False)
* is_enabled (True/False)
* description (string)
* last_flapped (float in seconds) - NOT IMPLEMENTED (always -1.0)
* speed (int in Mbit)
* MTU (in Bytes) - NOT IMPLEMENTED (always -1)
* mac_address (string)
Example::
{
u'Management1':
{
'is_up': False,
'is_enabled': False,
'description': '',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:61',
},
u'Ethernet1':
{
'is_up': True,
'is_enabled': True,
'description': 'foo',
'last_flapped': 1429978575.1554043,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:62',
},
u'Ethernet2':
{
'is_up': True,
'is_enabled': True,
'description': 'bla',
'last_flapped': 1429978575.1555667,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:63',
},
u'Ethernet3':
{
'is_up': False,
'is_enabled': True,
'description': 'bar',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:64',
}
}
"""
ret = get_interfaces(self)

:return:
"""
return super(ArubaOSS, self).get_interfaces()
return ret

def get_interfaces_counters(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions napalm_arubaoss/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from napalm_arubaoss.helper.get_arp_table import get_arp_table
from napalm_arubaoss.helper.get_config import get_config
from napalm_arubaoss.helper.get_facts import get_facts
from napalm_arubaoss.helper.get_interfaces import get_interfaces
from napalm_arubaoss.helper.get_interfaces_ip import get_interfaces_ip
from napalm_arubaoss.helper.get_lldp_neighbors import get_lldp_neighbors
from napalm_arubaoss.helper.get_lldp_neighbors_detail import get_lldp_neighbors_detail
Expand Down Expand Up @@ -43,6 +44,7 @@
"get_facts",
"get_arp_table",
"get_config",
"get_interfaces",
"get_interfaces_ip",
"get_lldp_neighbors",
"get_lldp_neighbors_detail",
Expand Down
74 changes: 74 additions & 0 deletions napalm_arubaoss/helper/get_interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Get the interfaces of the device."""

import logging

logger = logging.getLogger("arubaoss.helper.get_interfaces")


def get_interfaces(self):
"""Get IP interface IP addresses."""
url_ports = self.connection.config["api_url"] + "ports"
url_port_stats = self.connection.config["api_url"] + "port-statistics"

interface_template = {
'is_up': False,
'is_enabled': False,
'description': '',
'last_flapped': -1.0,
'speed': 1000,
'mtu': -1,
'mac_address': 'FA:16:3E:57:33:61',
}
output = {}

resp_ports = self.connection.get(url_ports)
resp_port_stats = self.connection.get(url_port_stats)

if not resp_ports.status_code == 200:
logger.error("didn't get status code 200 from %s", url_ports)
return output

if not resp_port_stats.status_code == 200:
logger.error("didn't get status code 200 from %s", url_port_stats)
return output

resp_ports_json = resp_ports.json()
for interface in resp_ports_json.get("port_element", []):
# show interfaces 1 | include MAC[[:space:]]Address
i_id = interface.get("id")
description = interface.get("name")
is_up = interface.get("is_port_up")
is_enabled = interface.get("is_port_enabled")

if i_id not in output.keys():
output[i_id] = interface_template.copy()

output[i_id]["description"] = description
output[i_id]["is_up"] = is_up
output[i_id]["is_enabled"] = is_enabled

resp_port_stats_json = resp_port_stats.json()
for interface_stats in resp_port_stats_json.get("port_statistics_element", []):
i_id = interface_stats.get("id")
speed = interface_stats.get("port_speed_mbps")

if i_id not in output.keys():
output[i_id] = interface_template.copy()

output[i_id]["speed"] = speed

for interface_id, interface_values in output.items():
resp = self.connection.run_cmd(
f"show interfaces {interface_id} | include MAC[[:space:]]Address"
)

resp = resp.replace(" ", "")
resp = resp.split(":")
mac_raw = resp[1]
mac_raw = mac_raw.replace("-", "")
mac = ':'.join(mac_raw[i:i+2] for i in range(0, 12, 2))
mac = mac.upper()

output[interface_id]["mac_address"] = mac

return output
16 changes: 16 additions & 0 deletions test/unit/mocked_data/test_get_interfaces/normal/cli_mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"show interfaces 1 | include MAC[[:space:]]Address": " MAC Address : 000000-00aebf ",
"show interfaces 2 | include MAC[[:space:]]Address": " MAC Address : 000000-00aebe ",
"show interfaces 3 | include MAC[[:space:]]Address": " MAC Address : 000000-00aebd ",
"show interfaces 4 | include MAC[[:space:]]Address": " MAC Address : 000000-00aebc ",
"show interfaces 5 | include MAC[[:space:]]Address": " MAC Address : 000000-00aebb ",
"show interfaces 6 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeba ",
"show interfaces 7 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb9 ",
"show interfaces 8 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb8 ",
"show interfaces 9 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb7 ",
"show interfaces 10 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb6 ",
"show interfaces 11 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb5 ",
"show interfaces 12 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb4 ",
"show interfaces 13 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb3 ",
"show interfaces 14 | include MAC[[:space:]]Address": " MAC Address : 000000-00aeb2 "
}
128 changes: 128 additions & 0 deletions test/unit/mocked_data/test_get_interfaces/normal/expected_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"1": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BF"
},
"2": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BE"
},
"3": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BD"
},
"4": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BC"
},
"5": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BB"
},
"6": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:BA"
},
"7": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B9"
},
"8": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B8"
},
"9": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B7"
},
"10": {
"is_up": false,
"is_enabled": true,
"description": "test-new",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B6"
},
"11": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B5"
},
"12": {
"is_up": false,
"is_enabled": true,
"description": "blah",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B4"
},
"13": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B3"
},
"14": {
"is_up": false,
"is_enabled": true,
"description": "",
"last_flapped": -1.0,
"speed": 1000,
"mtu": -1,
"mac_address": "00:00:00:00:AE:B2"
}
}
Loading

0 comments on commit 7a705e9

Please sign in to comment.