Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Fix #127 get_interfaces_ip fails when multiple ipv6 #135

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 15 additions & 27 deletions napalm_nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from requests.exceptions import ConnectionError

# import third party lib
from netaddr import IPAddress
from netaddr import IPAddress, IPNetwork
from netaddr.core import AddrFormatError

from pynxos.device import Device as NXOSDevice
Expand Down Expand Up @@ -706,34 +706,22 @@ def get_interfaces_ip(self):

for interface in ipv6_interf_table_vrf:
interface_name = py23_compat.text_type(interface.get('intf-name', ''))
address = napalm_base.helpers.ip(interface.get('addr', '').split('/')[0])
prefix = interface.get('prefix', '').split('/')[-1]
if prefix:
prefix = int(interface.get('prefix', '').split('/')[-1])
else:
prefix = 128
if interface_name not in interfaces_ip.keys():
interfaces_ip[interface_name] = {}
if 'ipv6' not in interfaces_ip[interface_name].keys():
interfaces_ip[interface_name]['ipv6'] = {}
if address not in interfaces_ip[interface_name].get('ipv6'):
interfaces_ip[interface_name]['ipv6'][address] = {}
interfaces_ip[interface_name]['ipv6'][address].update({
'prefix_length': prefix
})
secondary_addresses = interface.get('TABLE_sec_addr', {}).get('ROW_sec_addr', [])
if type(secondary_addresses) is dict:
secondary_addresses = [secondary_addresses]
for secondary_address in secondary_addresses:
sec_prefix = secondary_address.get('sec-prefix', '').split('/')
secondary_address_ip = napalm_base.helpers.ip(sec_prefix[0])
secondary_address_prefix = int(sec_prefix[-1])
addresses = interface.get('addr', [])
if type(addresses) is not list:
addresses = [addresses]

for address in addresses:
network = IPNetwork(address)
host = napalm_base.helpers.ip(network.ip)
prefix = network.prefixlen
if interface_name not in interfaces_ip.keys():
interfaces_ip[interface_name] = {}
if 'ipv6' not in interfaces_ip[interface_name].keys():
interfaces_ip[interface_name]['ipv6'] = {}
if secondary_address_ip not in interfaces_ip[interface_name].get('ipv6'):
interfaces_ip[interface_name]['ipv6'][secondary_address_ip] = {}
interfaces_ip[interface_name]['ipv6'][secondary_address_ip].update({
'prefix_length': secondary_address_prefix
if host not in interfaces_ip[interface_name].get('ipv6'):
interfaces_ip[interface_name]['ipv6'][host] = {}
interfaces_ip[interface_name]['ipv6'][host].update({
'prefix_length': prefix
})
return interfaces_ip

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Ethernet1/1": {
"ipv6": {
"2001:db8:800:200c::2": {
"prefix_length": 64
},
"2001:db8:800:200d::2": {
"prefix_length": 64
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"TABLE_vrf": {
"ROW_vrf": {
"vrf-name-out": "default"
}
},
"TABLE_intf": {
"ROW_intf": {
"intf-name": "Ethernet1/1",
"proto-state": "up",
"link-state": "up",
"admin-state": "up",
"addr": [
"2001:db8:800:200c::2/64",
"2001:db8:800:200d::2/64"
],
"prefix": "2001:db8:800:200c::/64",
"linklocal-addr": "fe80::2ec2:60ff:fe7d:5725",
"linklocal-configured": "FALSE",
"mrouting-enabled": "disabled",
"mgroup-locally-joined": "TRUE",
"TABLE_maddr": {
"ROW_maddr": [
{
"m-addr": "ff02::1:ff00:2"
},
{
"m-addr": "ff02::2"
},
{
"m-addr": "ff02::1"
},
{
"m-addr": "ff02::1:ff00:2"
},
{
"m-addr": "ff02::1:ff7d:5725"
},
{
"m-addr": "ff02::1:ff00:0"
}
]
},
"mtu": "1500",
"urpf-mode": "none",
"ipv6-lstype": "none",
"stats-last-reset": "never",
"upkt-fwd": "0",
"upkt-orig": "64",
"upkt-consumed": "66",
"ubyte-fwd": "0",
"ubyte-orig": "5760",
"ubyte-consumed": "4720",
"mpkt-fwd": "0",
"mpkt-orig": "114",
"mpkt-consumed": "929",
"mbyte-fwd": "0",
"mbyte-orig": "13532",
"mbyte-consumed": "93536"
}

}
}