diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-10-29 20:14:48 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-10-29 20:14:48 -0500 |
commit | 7750a92341adee5cac7ef1c51f2b687ae212f5d5 (patch) | |
tree | f69c5de2af0ba63cfbde360f68f7d244e7a45378 /ncserver | |
parent | 02493e74f7d9499dd090f63ca1ccfe397b23758a (diff) | |
download | netconfapk-7750a92341adee5cac7ef1c51f2b687ae212f5d5.tar.gz netconfapk-7750a92341adee5cac7ef1c51f2b687ae212f5d5.tar.bz2 netconfapk-7750a92341adee5cac7ef1c51f2b687ae212f5d5.tar.xz netconfapk-7750a92341adee5cac7ef1c51f2b687ae212f5d5.zip |
ietf-interfaces: Add more operational nodes
Diffstat (limited to 'ncserver')
-rw-r--r-- | ncserver/module/interfaces.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py index 7e48b2e..b244bfc 100644 --- a/ncserver/module/interfaces.py +++ b/ncserver/module/interfaces.py @@ -123,6 +123,43 @@ def operational(node): for iface in ifaces.iterchildren(): name = iface.find('{'+M_NS+'}name').text + ifpath = pathlib.Path("/sys/class/net/" + name) + + # if-index + if (ifpath / "ifindex").exists(): + index_file = open(ifpath / "ifindex", 'r') + iface.append(util.leaf_elm('if:if-index', + index_file.read().strip())) + index_file.close() + + # oper-status + status = "unknown" + if (ifpath / "operstate").exists(): + status_file = open(ifpath / "operstate", 'r') + status = status_file.read().strip() + status_file.close() + iface.append(util.leaf_elm('if:oper-status', status)) + + # speed + if status == "up" and (ifpath / "speed").exists(): + try: + with open(ifpath / "speed", 'r') as speed_file: + speed = int(speed_file.read().strip()) + speed *= 1000 + iface.append(util.leaf_elm('if:speed', speed)) + except IOError: + pass # if the interface does not have measurable speed, omit + except ValueError: + LOGGER.warning("%s has non-integral speed; kernel bug?", name) + + # phys-address + if (ifpath / "address").exists(): + addr_file = open(ifpath / "address", 'r') + iface.append(util.leaf_elm('if:phys-address', + addr_file.read().strip())) + addr_file.close() + + # statistics stats = util.subelm(iface, 'if:statistics') # XXX BAD vvv stats.append(util.leaf_elm('if:discontinuity-time', '2020-01-01T01:01:01.011Z')) |