Skip to content
Snippets Groups Projects
Commit 5ae87782 authored by Robert Latta's avatar Robert Latta
Browse files

Removed hardcoded index references from config parsing. RE DBOARD3-965

parent 78963212
No related branches found
No related tags found
No related merge requests found
......@@ -173,12 +173,14 @@ def get_interfaces_state(state_doc):
def get_ports_config(netconf_config):
def _port_info(e):
pi = {
'port-id': e.find('n:port-id', namespaces=NS).text,
'admin-state': e.find('n:admin-state', namespaces=NS).text,
'port-id': e.find('n:port-id', namespaces=NS).text
}
description = e.find('n:description', namespaces=NS)
admin_state = e.find('n:admin-state', namespaces=NS)
pi['admin-state'] = admin_state.text if admin_state is not None else 'enabled' # assume enabled if not present
description = e.find('n:description', namespaces=NS)
pi['description'] = description.text if description is not None else ''
breakout = e.find('./n:connector/n:breakout', namespaces=NS)
if breakout is not None:
breakout = breakout.text
......@@ -207,8 +209,7 @@ def get_ports_config(netconf_config):
def get_lags_config(netconf_config):
enabled_ports = {
p['port-id'] for p in get_ports_config(netconf_config)
if p['admin-state'] == 'enable'
p['port-id'] for p in get_ports_config(netconf_config) if p['admin-state'] == 'enable'
}
def _lag_info(e):
......@@ -216,14 +217,14 @@ def get_lags_config(netconf_config):
port_elements = e.findall('./n:port', namespaces=NS)
port_ids = (p.find('./n:port-id', namespaces=NS).text for p in port_elements)
admin_state = e.find('./n:admin-state', namespaces=NS).text
admin_state = e.find('./n:admin-state', namespaces=NS)
description_e = e.find('n:description', namespaces=NS)
ifc = {
'name': _name,
'description': (
description_e.text if description_e is not None else ''
),
'admin-state': admin_state,
'admin-state': admin_state.text if admin_state is not None else 'enabled', # assume enabled if not present
'ports': [p_id for p_id in port_ids if p_id in enabled_ports],
}
return ifc
......@@ -235,19 +236,6 @@ def get_lags_config(netconf_config):
def get_interfaces_config(netconf_config):
def _get_address_node_info(_e):
# HACKHACK: quick workaround for DBOARD3-965
# TODO: fix this properly
yield from _e.xpath('n:address', namespaces=NS)
yield from _e.xpath('n:primary', namespaces=NS)
def _get_ip_address(e):
for _address_elem in _get_address_node_info(e):
address = _address_elem[0].text
prefix_length = _address_elem[1].text
ip_string = f'{address}/{prefix_length}'
yield ip_string
interfaces = netconf_config.findall(
'n:configure/n:router/n:interface', namespaces=NS)
for interface in interfaces:
......@@ -263,10 +251,14 @@ def get_interfaces_config(netconf_config):
if admin_state is not None:
details["admin-state"] = admin_state.text
for element in interface.xpath('n:ipv4', namespaces=NS):
details["ipv4"].extend(_get_ip_address(element))
for element in interface.xpath('n:ipv4/n:primary | n:ipv4/n:secondary', namespaces=NS):
address = element.find('n:address', namespaces=NS).text
prefix_length = element.find('n:prefix-length', namespaces=NS).text
details["ipv4"].append(f'{address}/{prefix_length}')
for element in interface.xpath('n:ipv6', namespaces=NS):
details["ipv6"].extend(_get_ip_address(element))
for element in interface.xpath('n:ipv6/n:address', namespaces=NS):
address = element.find('n:ipv6-address', namespaces=NS).text
prefix_length = element.find('n:prefix-length', namespaces=NS).text
details["ipv6"].append(f'{address}/{prefix_length}')
yield details
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment