From a2194aea6a6ff073c94db0c7d7cdc7472c7d4446 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 11 Dec 2020 07:09:58 -0600 Subject: ietf-ip: Report live addresses in the operational state --- ncserver/module/ip.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ncserver/module/ip.py b/ncserver/module/ip.py index 8329c81..a7f645c 100644 --- a/ncserver/module/ip.py +++ b/ncserver/module/ip.py @@ -10,6 +10,7 @@ with this source distribution for more information. SPDX-License-Identifier: NCSA """ +import ipaddress import logging from lxml.etree import QName # pylint: disable=E0611 @@ -194,10 +195,41 @@ def operational(node): return for iface in ifaces.iterchildren(): + name = iface.find('{'+IF_NS+'}name').text + addrs = nmsa.live_addresses(name) + # IPv4 - _add_ipv4(iface, nmsa.curr_param) + ipv4 = _add_ipv4(iface, nmsa.curr_param) + for addr in addrs: + if not isinstance(addr, ipaddress.IPv4Interface): + continue + + addr_node = util.subelm(ipv4, 'ip:address') + addr_node.append(util.leaf_elm('ip:ip', str(addr.ip))) + addr_node.append(util.leaf_elm('ip:prefix-length', + addr.network.prefixlen)) + + origin = "other" + conf = "{a}/{p}".format(a=str(addr.ip), p=addr.network.prefixlen) + if conf in nmsa.list_addresses(name): + origin = "static" + addr_node.append(util.leaf_elm('ip:origin', origin)) # IPv6 - _add_ipv6(iface, nmsa.curr_param) + ipv6 = _add_ipv6(iface, nmsa.curr_param) + for addr in addrs: + if not isinstance(addr, ipaddress.IPv6Interface): + continue + + addr_node = util.subelm(ipv6, 'ip:address') + addr_node.append(util.leaf_elm('ip:ip', str(addr.ip))) + addr_node.append(util.leaf_elm('ip:prefix-length', + addr.network.prefixlen)) + + origin = "other" + conf = "{a}/{p}".format(a=str(addr.ip), p=addr.network.prefixlen) + if conf in nmsa.list_addresses(name): + origin = "static" + addr_node.append(util.leaf_elm('ip:origin', origin)) def _edit_param(iface: str, param: str, operation: str, rpc, node): -- cgit v1.2.3-60-g2f50