diff options
Diffstat (limited to 'ncserver/module/ip.py')
-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): |