From 02493e74f7d9499dd090f63ca1ccfe397b23758a Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 29 Oct 2020 19:41:04 -0500 Subject: ietf-interfaces: Add type field --- ncserver/module/interfaces.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ncserver/module/interfaces.py') diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py index 497c63a..7e48b2e 100644 --- a/ncserver/module/interfaces.py +++ b/ncserver/module/interfaces.py @@ -51,6 +51,9 @@ M_REVISION = "2018-02-20" M_IMPORTS = { 'ietf-yang-types@2013-07-15': { 'ns': "urn:ietf:params:xml:ns:yang:ietf-yang-types", 'prefix': "yang" + }, + 'iana-if-type@2017-01-19': { + 'ns': "urn:ietf:params:xml:ns:yang:iana-if-type", 'prefix': "ianaift" } } """The imported YANG modules for this module.""" @@ -64,9 +67,38 @@ def _add_running_contents(ifaces): """Retrieve the interface configuration for this device. Allows returning the 'config true' data for both datastores.""" + types = { + '1': 'ethernetCsmacd', + '3': 'rfc877x25', + '7': 'arcnet', + '8': 'arap', + '19': 'atm', + '24': 'ieee1394', + '32': 'infiniband', + '256': 'slip', + '512': 'ppp', + '513': 'hdlc', + '516': 'lapb', + '768': 'tunnel', + '770': 'frameRelay', + '772': 'softwareLoopback', + '774': 'fddi', + '804': 'ieee802154' + } + for ifname in pathlib.Path('/sys/class/net').iterdir(): iface = util.subelm(ifaces, 'if:interface') iface.append(util.leaf_elm('if:name', ifname.name)) + type_file = open(ifname / "type", 'r') + type_num = type_file.read() + type_file.close() + type_num = type_num.strip() + if type_num in types.keys(): + iface.append(util.leaf_elm('if:type', 'ianaift:'+types[type_num], + nsmap={'ianaift': "urn:ietf:params:xml:ns:yang:iana-if-type"})) + else: + LOGGER.warning(_('unknown Linux hwtype for %s: %s'), + ifname.name, type_num) def running(node): -- cgit v1.2.3-60-g2f50