Skip to content

Commit

Permalink
Support get_mac_address_table and code coverage added (#15)
Browse files Browse the repository at this point in the history
* Support get_mac_address_table and code coverage added

* Bux fix to support all(mgmt/portchannel/vlan) interfaces part of get_interfaces and get_interfaces_ip API
  • Loading branch information
javeedf authored and skg-net committed Sep 5, 2018
1 parent fc4a91e commit 0eb54aa
Show file tree
Hide file tree
Showing 13 changed files with 68,305 additions and 1,554 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/napalm-automation-community/napalm-dellos10.svg?branch=master)](https://travis-ci.org/napalm-automation-community/napalm-dellos10)
[![PyPI](https://img.shields.io/pypi/v/napalm-dellos10.svg)](https://pypi.python.org/pypi/napalm-dellos10)
[![Supported python versions](https://img.shields.io/pypi/pyversions/napalm-dellos10.svg)](https://pypi.python.org/pypi/napalm-dellos10/)
[![Coverage Status](https://coveralls.io/repos/github/napalm-automation-community/napalm-dellos10/badge.svg?branch=master)](https://coveralls.io/github/napalm-automation-community/napalm-dellos10)
[![Coverage Status](https://coveralls.io/repos/github/javeedf/napalm-dellos10/badge.svg?branch=master)](https://coveralls.io/github/javeedf/napalm-dellos10?branch=master)
# napalm-dellos10

NAPALM driver for Dell EMC Networking OS10 Operating System.
Expand Down
157 changes: 90 additions & 67 deletions napalm_dellos10/dellos10.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DellOS10Driver(NetworkDriver):

UNKNOWN = u"N/A"
UNKNOWN_INT = int(-1)
UNKNOWN_FLOAT = float(-1)
UNKNOWN_BOOL = bool("False")

PROCEED_TO_REBOOT_MSG = "Proceed with upgrade and reboot"
Expand Down Expand Up @@ -758,37 +759,68 @@ def get_interfaces(self):
'speed': 100}}
"""
# default values.
output = self._send_command('show interface status | display-xml')
interfaces_xml_data = self.convert_xml_data(output)

cmd = 'show interface | display-xml'
interfaces_output = self._send_command(cmd)
interfaces_output_list = self._build_xml_list(interfaces_output)
interfaces_dict = {}

for interface in interfaces_xml_data.findall(
'./data/interfaces/interface'):
intf = dict()
name = self.parse_item(interface, 'name')
intf['last_flapped'] = -1.0
intf['description'] = self.parse_item(interface, 'description')
admin_status = self.parse_item(interface, 'enabled')
intf['is_enabled'] = True if admin_status == "true" else False
for interfaces_output in interfaces_output_list:
if_xml_data = self.convert_xml_data(interfaces_output)

intf['mac_address'] = self.UNKNOWN
interface_state_xpath = "./bulk/data/interface"
for interface in if_xml_data.findall(interface_state_xpath):
intf = dict()
name = self.parse_item(interface, 'name')
last_flapped = self.parse_item(interface, 'last-change-time')
last_flapped = float(last_flapped) if last_flapped else -1.0
intf['last_flapped'] = last_flapped

interfaces_dict[name] = intf
intf['description'] = self.parse_item(interface, 'description')

for interface in interfaces_xml_data.findall(
'./data/interfaces-state/interface'):
name = self.parse_item(interface, 'name')
intf = interfaces_dict[name]
oper_status = self.parse_item(interface, 'oper-status')
intf['is_up'] = False if oper_status == "down" else True
speed_val = self.parse_item(interface, 'speed')
intf['speed'] = self.convert_int(speed_val)
admin_status = self.parse_item(interface, 'admin-status')
intf['is_enabled'] = True if admin_status == "up" else False

interfaces_dict[name] = intf
intf['mac_address'] = self.parse_item(interface,
'phys-address')

oper_status = self.parse_item(interface, 'oper-status')
intf['is_up'] = False if oper_status == "down" else True

speed_val = self.parse_item(interface, 'speed')
intf['speed'] = self.convert_int(speed_val)

interfaces_dict[name] = intf

return interfaces_dict

def get_mac_address_table(self):
cmd = 'show mac address-table | display-xml'
lldp_neighbors_output = self._send_command(cmd)

routes_xml_data = self.convert_xml_data(lldp_neighbors_output)
base_xpath = "./bulk/data/fwd-table"
ret_mac_dict = []
mac_xml_list = routes_xml_data.findall(base_xpath)
for mac_xml in mac_xml_list:
mac_addr = self.parse_item(mac_xml, 'mac-addr')
# vlan id comes with "vlan123"
vlan_id_str = self.parse_item(mac_xml, 'vlan')
entry_type = self.parse_item(mac_xml, 'entry-type')
if_name = self.parse_item(mac_xml, 'if-name')
vlan_id = int(vlan_id_str[4:].strip())
mac_dict = {
"mac": mac_addr,
"interface": if_name,
"static": True if "static" == entry_type else False,
"active": True,
"vlan": vlan_id,
"moves": self.UNKNOWN_INT,
"last_move": self.UNKNOWN_FLOAT
}
ret_mac_dict.append(mac_dict)

return ret_mac_dict

def get_route_to(self, destination=u'', protocol=u''):
"""To get routes.
Expand Down Expand Up @@ -884,53 +916,44 @@ def get_interfaces_ip(self):
u'10.65.0.1': { 'prefix_length': 24}}},
u'Vlan200': {'ipv4': {u'10.63.176.57': { 'prefix_length': 29}}}}
"""
output = self._send_command('show ip interface brief | display-xml')
interfaces_xml_data = self.convert_xml_data(output)

interfaces_dict = {}
interface_xpath = './data/interfaces/interface'
ipv4_xpath = 'ipv4/address/primary-addr'
interface_state_xpath = './data/interfaces-state/interface'
for interface in interfaces_xml_data.findall(interface_xpath):
name = self.parse_item(interface, 'name')

ipv4_address_with_prefix = self.parse_item(interface, ipv4_xpath)
if not ipv4_address_with_prefix:
continue

ip_split_list = ipv4_address_with_prefix.split("/")
ipv4 = ip_split_list[0]
ipv4_prefix = self.convert_int(ip_split_list[1])

interfaces_dict[name] = {
"ipv4": {ipv4: {'prefix_length': ipv4_prefix}}}

ipv6_res = self._send_command(
'show ipv6 interface brief | display-xml')
ipv6_output_xml_data = self.convert_xml_data(ipv6_res)

for ipv6_entry in ipv6_output_xml_data.findall(interface_state_xpath):
name = self.parse_item(ipv6_entry, 'name')
ipv6_dict = {}

for ipv6_entry1 in ipv6_entry.iter('global-addr'):
ipv6_address_with_prefix = ipv6_entry1.text
if not ipv6_address_with_prefix:
continue

if "/" in ipv6_address_with_prefix:
ipv6_split_list = ipv6_address_with_prefix.split("/")
ipv6 = ipv6_split_list[0]
ipv6_prefix = self.convert_int(ip_split_list[1])
cmd = 'show interface | display-xml'
ipv4_xpath = 'ipv4-info/addr'
ipv6_xpath = 'ipv6/global-addr'
interfaces_output = self._send_command(cmd)
interfaces_output_list = self._build_xml_list(interfaces_output)
ret_interfaces_dict = {}
print("in ip")

ipv6_dict[ipv6] = {'prefix_length': ipv6_prefix}
if ipv6_dict:
ipv6_str_dict = {"ipv6": ipv6_dict}
if interfaces_dict.get(name):
ipv6_str_dict.update(interfaces_dict[name])
interfaces_dict[name] = ipv6_str_dict
for interfaces_output in interfaces_output_list:
if_xml_data = self.convert_xml_data(interfaces_output)

return interfaces_dict
interface_state_xpath = "./bulk/data/interface"
for interface in if_xml_data.findall(interface_state_xpath):
name = self.parse_item(interface, 'name')
interfaces_dict = {}
ipv4_address_with_prefix = self.parse_item(interface,
ipv4_xpath)
if ipv4_address_with_prefix:
ip_split_list = ipv4_address_with_prefix.split("/")
ipv4 = ip_split_list[0]
ipv4_prefix = self.convert_int(ip_split_list[1])
interfaces_dict.update(
{"ipv4": {ipv4: {'prefix_length': ipv4_prefix}}})

ipv6_address_with_prefix = self.parse_item(interface,
ipv6_xpath)
if ipv6_address_with_prefix:
if "/" in ipv6_address_with_prefix:
ipv6_split_list = ipv6_address_with_prefix.split("/")
ipv6 = ipv6_split_list[0]
ipv6_prefix = self.convert_int(ip_split_list[1])
interfaces_dict.update(
{"ipv6": {ipv6: {'prefix_length': ipv6_prefix}}})

if interfaces_dict:
ret_interfaces_dict[name] = interfaces_dict

return ret_interfaces_dict

def get_bgp_config(self, group=u'', neighbor=u''):
"""To get BGP configuration.
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
],
url="https://github.com/skg-net/napalm-dellos10",
url="https://github.com/napalm-automation-community/napalm-dellos10",
include_package_data=True,
install_requires=reqs,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply>
<bulk>
<data>
<fwd-table>
<mac-addr>11:22:33:44:55:55</mac-addr>
<vlan>vlan25</vlan>
<entry-type>dynamic</entry-type>
<if-name>port-channel11</if-name>
</fwd-table>
<fwd-table>
<mac-addr>11:22:33:44:55:56</mac-addr>
<vlan>vlan24</vlan>
<entry-type>dynamic</entry-type>
<if-name>port-channel12</if-name>
</fwd-table>
<fwd-table>
<mac-addr>11:22:33:44:55:57</mac-addr>
<vlan>vlan23</vlan>
<entry-type>dynamic</entry-type>
<if-name>port-channel13</if-name>
</fwd-table>
<last-keys>
<entry-type>static</entry-type>
<mac-addr>11:22:33:44:55:59</mac-addr>
<vlan>vlan123</vlan>
</last-keys>
</data>
</bulk>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"ethernet1/1/8": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/9": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/6": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/7": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/4": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/5": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/2": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/3": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/1": {"is_enabled": true, "description": "This is test deswcription to validate the length", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/18": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/19": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/10": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/11": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/12": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/13": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/14": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/15": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/16": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/17": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/30": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/31": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/32": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/29": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/28": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/25": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/24": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/27": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/26": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/21": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/20": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/23": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}, "ethernet1/1/22": {"is_enabled": true, "description": "", "last_flapped": -1.0, "is_up": false, "mac_address": "N/A", "speed": 0}
}
{"mgmt1/1/1": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": true, "mac_address": "00:50:56:af:6b:7b", "speed": 1000000000}, "ethernet1/1/8": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:98", "speed": 0}, "ethernet1/1/9": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:9c", "speed": 0}, "ethernet1/1/6": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:90", "speed": 0}, "ethernet1/1/7": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:94", "speed": 0}, "ethernet1/1/4": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:88", "speed": 0}, "ethernet1/1/5": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:8c", "speed": 0}, "ethernet1/1/2": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:80", "speed": 0}, "ethernet1/1/3": {"is_enabled": true, "description": "", "last_flapped": 76.0, "is_up": false, "mac_address": "00:50:56:af:6b:84", "speed": 0}, "ethernet1/1/1": {"is_enabled": true, "description": "", "last_flapped": 103.0, "is_up": true, "mac_address": "00:50:56:af:6b:7c", "speed": 40000000000}, "vlan1": {"is_enabled": true, "description": "", "last_flapped": 11826.0, "is_up": false, "mac_address": "00:50:56:af:6b:e5", "speed": 0}, "null0": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": true, "mac_address": "", "speed": -1}, "ethernet1/1/18": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:b4", "speed": 0}, "ethernet1/1/19": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:b8", "speed": 0}, "ethernet1/1/10": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:a0", "speed": 0}, "ethernet1/1/11": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:a4", "speed": 0}, "ethernet1/1/12": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:a8", "speed": 0}, "ethernet1/1/13": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:ac", "speed": 0}, "ethernet1/1/14": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:ad", "speed": 0}, "ethernet1/1/15": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:ae", "speed": 0}, "ethernet1/1/16": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:af", "speed": 0}, "ethernet1/1/17": {"is_enabled": true, "description": "", "last_flapped": 77.0, "is_up": false, "mac_address": "00:50:56:af:6b:b0", "speed": 0}, "ethernet1/1/30": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:e1", "speed": 0}, "ethernet1/1/31": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:e2", "speed": 0}, "ethernet1/1/32": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:e3", "speed": 0}, "ethernet1/1/29": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:e0", "speed": 0}, "ethernet1/1/28": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:dc", "speed": 0}, "ethernet1/1/25": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:d0", "speed": 0}, "ethernet1/1/24": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:cc", "speed": 0}, "ethernet1/1/27": {"is_enabled": true, "description": "", "last_flapped": 79.0, "is_up": false, "mac_address": "00:50:56:af:6b:d8", "speed": 0}, "ethernet1/1/26": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:d4", "speed": 0}, "ethernet1/1/21": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:c0", "speed": 0}, "ethernet1/1/20": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:bc", "speed": 0}, "ethernet1/1/23": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:c8", "speed": 0}, "ethernet1/1/22": {"is_enabled": true, "description": "", "last_flapped": 78.0, "is_up": false, "mac_address": "00:50:56:af:6b:c4", "speed": 0}}
Loading

0 comments on commit 0eb54aa

Please sign in to comment.