diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-12-11 07:09:58 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-12-11 07:09:58 -0600 |
commit | a2194aea6a6ff073c94db0c7d7cdc7472c7d4446 (patch) | |
tree | 30992896ab1b080bc2273b7301a175bd537beff8 | |
parent | cb0dee93926f7658560f84496225b1efd80b5035 (diff) | |
download | netconfapk-a2194aea6a6ff073c94db0c7d7cdc7472c7d4446.tar.gz netconfapk-a2194aea6a6ff073c94db0c7d7cdc7472c7d4446.tar.bz2 netconfapk-a2194aea6a6ff073c94db0c7d7cdc7472c7d4446.tar.xz netconfapk-a2194aea6a6ff073c94db0c7d7cdc7472c7d4446.zip |
ietf-ip: Report live addresses in the operational state
-rw-r--r-- | ncserver/module/ip.py | 36 |
1 files 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): |