Skip to content

Commit

Permalink
Initial code to support additional endpoints on get_interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoAndre committed Oct 5, 2018
1 parent 7120f8b commit 6795725
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 25 deletions.
56 changes: 33 additions & 23 deletions napalm_asa/asa.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _delete_token(self):

return delete_result

def _send_request(self, endpoint, data=None):
def _send_request(self, endpoint, data=None, throw=True):
"""Send request method."""
if data is None:
response = self.device.get_resp(endpoint)
Expand All @@ -171,10 +171,10 @@ def _send_request(self, endpoint, data=None):
offset = fetched_items
params = {'offset': offset}
if data is None:
r = self.device.get_resp(endpoint=endpoint, params=params)
r = self.device.get_resp(endpoint=endpoint, params=params, throw=throw)
else:
r = self.device.get_resp(endpoint=endpoint, data=json.dumps(data),
params=params)
params=params, throw=throw)

fetched_items = fetched_items + len(r['items'])
response['items'] = response['items'] + r['items']
Expand Down Expand Up @@ -282,29 +282,39 @@ def get_facts(self):
def get_interfaces(self):
"""Get Interfaces."""
interfaces = OrderedDict()
response = self._send_request('/interfaces/physical')

if response['rangeInfo']['total'] > 0:

for int_info in response['items']:
interfaces[int_info['hardwareID']] = {
'is_up': False,
'is_enabled': not int_info['shutdown'],
'description': int_info['interfaceDesc'],
'last_flapped': -1.0,
'speed': 0,
'mac_address': u'',
}
endpoints = ('/interfaces/physical', '/interfaces/vlan')
# , '/interfaces/portchannel',
# '/interfaces/redundant', '/interfaces/bvi', '/api/interfaces/setup',
# '/interfaces/firepower/93xx/portchannel')

responses = []

for endpoint in endpoints:
responses.append(self._send_request(endpoint, throw=False))

#response = self._send_request('/interfaces/physical', throw=False)
for response in responses:
if response['rangeInfo']['total'] > 0:

for int_info in response['items']:
interfaces[int_info['hardwareID']] = {
'is_up': False,
'is_enabled': not int_info['shutdown'],
'description': int_info['interfaceDesc'],
'last_flapped': -1.0,
'speed': 0,
'mac_address': u'',
}

ifs = []
for if_name in interfaces:
ifs.append(if_name)
ifs = []
for if_name in interfaces:
ifs.append(if_name)

ifs_details = self._get_interfaces_details(ifs)
ifs_details = self._get_interfaces_details(ifs)

for if_name, details in ifs_details.items():
interfaces[if_name]['mac_address'] = details['mac_address']
interfaces[if_name]['is_up'] = details['is_up']
for if_name, details in ifs_details.items():
interfaces[if_name]['mac_address'] = details['mac_address']
interfaces[if_name]['is_up'] = details['is_up']

return interfaces

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"response": [
"Interface GigabitEthernet0/0 \"inside\", is up, line protocol is up\n Hardware is i82540EM rev03, BW 1000 Mbps, DLY 10 usec\n\tAuto-Duplex(Full-duplex), Auto-Speed(1000 Mbps)\n\tInput flow control is unsupported, output flow control is off\n\tMAC address 008d.e011.ef01, MTU 1500\n\tIP address 192.168.1.1, subnet mask 255.255.255.0\n\t0 packets input, 0 bytes, 0 no buffer\n\tReceived 0 broadcasts, 0 runts, 0 giants\n\t0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort\n\t0 pause input, 0 resume input\n\t0 L2 decode drops\n\t1 packets output, 60 bytes, 0 underruns\n\t0 pause output, 0 resume output\n\t0 output errors, 0 collisions, 1 interface resets\n\t0 late collisions, 0 deferred\n\t0 input reset drops, 0 output reset drops\n\tinput queue (blocks free curr/low): hardware (511/511)\n\toutput queue (blocks free curr/low): hardware (511/510)\n Traffic Statistics for \"inside\":\n\t0 packets input, 0 bytes\n\t1 packets output, 28 bytes\n\t0 packets dropped\n 1 minute input rate 0 pkts/sec, 0 bytes/sec\n 1 minute output rate 0 pkts/sec, 0 bytes/sec\n 1 minute drop rate, 0 pkts/sec\n 5 minute input rate 0 pkts/sec, 0 bytes/sec\n 5 minute output rate 0 pkts/sec, 0 bytes/sec\n 5 minute drop rate, 0 pkts/sec\n",
"Interface Management0/0 \"mgmt\", is up, line protocol is up\n Hardware is i82540EM rev03, BW 1000 Mbps, DLY 10 usec\n\tAuto-Duplex(Full-duplex), Auto-Speed(1000 Mbps)\n\tInput flow control is unsupported, output flow control is off\n\tMAC address 008d.e011.ef00, MTU 1500\n\tIP address 172.16.62.100, subnet mask 255.255.255.0\n\t46152 packets input, 4131760 bytes, 0 no buffer\n\tReceived 73 broadcasts, 2 runts, 0 giants\n\t2 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort\n\t0 pause input, 0 resume input\n\t0 L2 decode drops\n\t26857 packets output, 29334260 bytes, 0 underruns\n\t0 pause output, 0 resume output\n\t0 output errors, 0 collisions, 1 interface resets\n\t0 late collisions, 0 deferred\n\t0 input reset drops, 0 output reset drops\n\tinput queue (blocks free curr/low): hardware (491/439)\n\toutput queue (blocks free curr/low): hardware (511/495)\n Traffic Statistics for \"mgmt\":\n\t1675 packets input, 122934 bytes\n\t1559 packets output, 1632138 bytes\n\t68 packets dropped\n 1 minute input rate 0 pkts/sec, 0 bytes/sec\n 1 minute output rate 0 pkts/sec, 0 bytes/sec\n 1 minute drop rate, 0 pkts/sec\n 5 minute input rate 0 pkts/sec, 0 bytes/sec\n 5 minute output rate 0 pkts/sec, 0 bytes/sec\n 5 minute drop rate, 0 pkts/sec\n\tManagement-only interface. Blocked 0 through-the-device packets\n\n",
"Interface GigabitEthernet0/1 \"outside\", is up, line protocol is up\n Hardware is i82540EM rev03, BW 1000 Mbps, DLY 10 usec\n\tAuto-Duplex(Full-duplex), Auto-Speed(1000 Mbps)\n\tInput flow control is unsupported, output flow control is off\n\tMAC address 008d.e011.ef02, MTU 1500\n\tIP address 192.168.2.1, subnet mask 255.255.255.0\n\t0 packets input, 0 bytes, 0 no buffer\n\tReceived 0 broadcasts, 0 runts, 0 giants\n\t0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort\n\t0 pause input, 0 resume input\n\t0 L2 decode drops\n\t1 packets output, 60 bytes, 0 underruns\n\t0 pause output, 0 resume output\n\t0 output errors, 0 collisions, 1 interface resets\n\t0 late collisions, 0 deferred\n\t0 input reset drops, 0 output reset drops\n\tinput queue (blocks free curr/low): hardware (511/511)\n\toutput queue (blocks free curr/low): hardware (511/510)\n Traffic Statistics for \"outside\":\n\t0 packets input, 0 bytes\n\t1 packets output, 28 bytes\n\t0 packets dropped\n 1 minute input rate 0 pkts/sec, 0 bytes/sec\n 1 minute output rate 0 pkts/sec, 0 bytes/sec\n 1 minute drop rate, 0 pkts/sec\n 5 minute input rate 0 pkts/sec, 0 bytes/sec\n 5 minute output rate 0 pkts/sec, 0 bytes/sec\n 5 minute drop rate, 0 pkts/sec\n"
"Interface GigabitEthernet0/1 \"outside\", is up, line protocol is up\n Hardware is i82540EM rev03, BW 1000 Mbps, DLY 10 usec\n\tAuto-Duplex(Full-duplex), Auto-Speed(1000 Mbps)\n\tInput flow control is unsupported, output flow control is off\n\tMAC address 008d.e011.ef02, MTU 1500\n\tIP address 192.168.2.1, subnet mask 255.255.255.0\n\t0 packets input, 0 bytes, 0 no buffer\n\tReceived 0 broadcasts, 0 runts, 0 giants\n\t0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort\n\t0 pause input, 0 resume input\n\t0 L2 decode drops\n\t1 packets output, 60 bytes, 0 underruns\n\t0 pause output, 0 resume output\n\t0 output errors, 0 collisions, 1 interface resets\n\t0 late collisions, 0 deferred\n\t0 input reset drops, 0 output reset drops\n\tinput queue (blocks free curr/low): hardware (511/511)\n\toutput queue (blocks free curr/low): hardware (511/510)\n Traffic Statistics for \"outside\":\n\t0 packets input, 0 bytes\n\t1 packets output, 28 bytes\n\t0 packets dropped\n 1 minute input rate 0 pkts/sec, 0 bytes/sec\n 1 minute output rate 0 pkts/sec, 0 bytes/sec\n 1 minute drop rate, 0 pkts/sec\n 5 minute input rate 0 pkts/sec, 0 bytes/sec\n 5 minute output rate 0 pkts/sec, 0 bytes/sec\n 5 minute drop rate, 0 pkts/sec\n",
"Interface Management0/0.2 \"submgmt\", is up, line protocol is up\n Hardware is i82540EM rev03, BW 1000 Mbps, DLY 10 usec\n\tVLAN identifier 2\n\tDescription: SubManagement\n\tMAC address 5e00.0000.0000, MTU 1500\n\tIP address 10.205.1.3, subnet mask 255.255.0.0\n Traffic Statistics for \"submgmt\":\n\t0 packets input, 0 bytes\n\t1 packets output, 28 bytes\n\t0 packets dropped\n\tManagement-only interface. Blocked 0 through-the-device packets\n\n"
]
}
56 changes: 56 additions & 0 deletions test/unit/asa/mock_data/_interfaces_vlan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"kind": "collection#VlanMgmtInterface",
"selfLink": "https://192.168.218.66/api/interfaces/vlan",
"rangeInfo": {
"offset": 0,
"limit": 1,
"total": 1
},
"items": [
{
"kind": "object#VlanMgmtInterface",
"selfLink": "https://192.168.218.66/api/interfaces/vlan/Management0_API_SLASH_0.2",
"hardwareID": "Management0/0.2",
"interfaceDesc": "SubManagement",
"forwardTrafficCX": false,
"forwardTrafficSFR": false,
"activeMacAddress": "",
"standByMacAddress": "",
"managementOnly": true,
"mtu": 1500,
"name": "submgmt",
"securityLevel": 0,
"shutdown": false,
"vlanID": 2,
"ipAddress": {
"kind": "StaticIP",
"ip": {
"kind": "IPv4Address",
"value": "10.205.1.3"
},
"netMask": {
"kind": "IPv4NetMask",
"value": "255.255.0.0"
}
},
"ipv6Info": {
"enabled": false,
"autoConfig": false,
"enforceEUI64": false,
"managedAddressConfig": false,
"nsInterval": 1000,
"dadAttempts": 1,
"nDiscoveryPrefixList": [],
"otherStatefulConfig": false,
"routerAdvertInterval": 200,
"routerAdvertIntervalUnit": "sec",
"routerAdvertLifetime": 1800,
"suppressRouterAdvert": false,
"reachableTime": 0,
"ipv6Addresses": [],
"kind": "object#Ipv6InterfaceInfo"
},
"objectId": "Management0_API_SLASH_0.2"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@
"is_up": true,
"mac_address": "008d.e011.ef00",
"speed": 0
}
},
"Management0/0.2": {
"is_up": true,
"is_enabled": true,
"description": "SubManagement",
"last_flapped": -1,
"speed": 0,
"mac_address": "5e00.0000.0000"
}
}

0 comments on commit 6795725

Please sign in to comment.