summaryrefslogtreecommitdiff
path: root/ncserver/module/interfaces.py
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-10-29 18:50:03 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-10-29 18:50:03 -0500
commit4bf16df586bb7ee18b6e09616cbd8e7a66cc28f5 (patch)
treef4b5700b5d0148badda74fcdec256696f19e046e /ncserver/module/interfaces.py
parent6f33a3f4eb55b376ef929aa9a10d936377edb0ff (diff)
downloadnetconfapk-4bf16df586bb7ee18b6e09616cbd8e7a66cc28f5.tar.gz
netconfapk-4bf16df586bb7ee18b6e09616cbd8e7a66cc28f5.tar.bz2
netconfapk-4bf16df586bb7ee18b6e09616cbd8e7a66cc28f5.tar.xz
netconfapk-4bf16df586bb7ee18b6e09616cbd8e7a66cc28f5.zip
ietf-interfaces: Add statistics nodes
Diffstat (limited to 'ncserver/module/interfaces.py')
-rw-r--r--ncserver/module/interfaces.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py
index f8c4f45..497c63a 100644
--- a/ncserver/module/interfaces.py
+++ b/ncserver/module/interfaces.py
@@ -12,6 +12,7 @@ SPDX-License-Identifier: NCSA
import logging
import os
+import pathlib
import subprocess
from lxml import etree
@@ -55,11 +56,17 @@ M_IMPORTS = {
"""The imported YANG modules for this module."""
+M_FEATURES = ['pre-provisioning']
+"""The supported features declared in YANG for this module."""
+
+
def _add_running_contents(ifaces):
"""Retrieve the interface configuration for this device.
Allows returning the 'config true' data for both datastores."""
- # foo
+ for ifname in pathlib.Path('/sys/class/net').iterdir():
+ iface = util.subelm(ifaces, 'if:interface')
+ iface.append(util.leaf_elm('if:name', ifname.name))
def running(node):
@@ -73,6 +80,38 @@ def operational(node):
ifaces = util.subelm(node, 'if:interfaces')
_add_running_contents(ifaces)
+ counter_tags = {
+ 'rx.octets': 'if:in-octets',
+ 'rx.discard': 'if:in-discards',
+ 'rx.errors': 'if:in-errors',
+ 'tx.octets': 'if:out-octets',
+ 'tx.discard': 'if:out-discards',
+ 'tx.errors': 'if:out-errors'
+ }
+
+ for iface in ifaces.iterchildren():
+ name = iface.find('{'+M_NS+'}name').text
+ stats = util.subelm(iface, 'if:statistics')
+ # XXX BAD vvv
+ stats.append(util.leaf_elm('if:discontinuity-time', '2020-01-01T01:01:01.011Z'))
+ # XXX BAD ^^^
+
+ result = subprocess.run(['/sbin/ifupdown', 'ifctrstat', name],
+ stdout=subprocess.PIPE)
+ if result.returncode != 0:
+ LOGGER.error(_('ifctrstat failed for %s: %s'),
+ name, result.returncode)
+ continue
+
+ counters = result.stdout.decode('utf-8').split('\n')
+ counters.pop()
+ for counter, value in [data.split(': ') for data in counters]:
+ if counter not in counter_tags.keys():
+ LOGGER.warning(_('unhandled ifctrstat counter for %s: %s'),
+ name, counter)
+ continue
+ stats.append(util.leaf_elm(counter_tags[counter], value))
+
def edit(session, rpc, node, def_op):
"""Edit the interface configuration for this device."""