-
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.
Merge pull request #15 from napalm-automation-community/get_interfaces
get_interfaces added
- Loading branch information
Showing
7 changed files
with
697 additions
and
5 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,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
16
test/unit/mocked_data/test_get_interfaces/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,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
128
test/unit/mocked_data/test_get_interfaces/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,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" | ||
} | ||
} |
Oops, something went wrong.