summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-24 18:00:21 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-24 18:00:21 -0600
commitc7484b5f9babd57bb56043e88cd7b4ab726c7d61 (patch)
treedd7ab28985b3df64ee1448e8cd8a0b3c38506be6
parent4e78d68029311a5f541ebf71efda91f3449c66d6 (diff)
downloadnetconfapk-c7484b5f9babd57bb56043e88cd7b4ab726c7d61.tar.gz
netconfapk-c7484b5f9babd57bb56043e88cd7b4ab726c7d61.tar.bz2
netconfapk-c7484b5f9babd57bb56043e88cd7b4ab726c7d61.tar.xz
netconfapk-c7484b5f9babd57bb56043e88cd7b4ab726c7d61.zip
ietf-interfaces: Connect to NMS abstraction layer
-rw-r--r--ncserver/module/interfaces.py74
-rw-r--r--ncserver/module/nms_ifupdownng.py25
2 files changed, 68 insertions, 31 deletions
diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py
index b8f9ad1..16a90cd 100644
--- a/ncserver/module/interfaces.py
+++ b/ncserver/module/interfaces.py
@@ -18,6 +18,7 @@ from lxml import etree
from netconf import util
from ncserver.base.util import _, yang_dt_for_timestamp
+from ncserver.base.modman import MODMAN
QName = etree.QName # pylint: disable=I1101
@@ -62,10 +63,8 @@ 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."""
+def _add_iface_contents(container, ifaces):
+ """Retrieve the interfaces for this device."""
types = {
'1': 'ethernetCsmacd',
'3': 'rfc877x25',
@@ -85,26 +84,52 @@ def _add_running_contents(ifaces):
'804': 'ieee802154'
}
- for ifname in pathlib.Path('/sys/class/net').iterdir():
- iface = util.subelm(ifaces, 'if:interface')
+ for ifname in ifaces:
+ iface = util.subelm(container, '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():
- iana_xmlns = "urn:ietf:params:xml:ns:yang:iana-if-type"
- iface.append(util.leaf_elm('if:type', 'ianaift:'+types[type_num],
- nsmap={'ianaift': iana_xmlns}))
- else:
- LOGGER.warning(_('unknown Linux hwtype for %s: %s'),
- ifname.name, type_num)
+ type_path = ifname / "type"
+ if type_path.exists():
+ type_file = open(type_path, 'r')
+ type_num = type_file.read()
+ type_file.close()
+ type_num = type_num.strip()
+ if type_num in types.keys():
+ iana_xmlns = "urn:ietf:params:xml:ns:yang:iana-if-type"
+ iface.append(util.leaf_elm('if:type', 'ianaift:'+types[type_num],
+ nsmap={'ianaift': iana_xmlns}))
+ else:
+ LOGGER.warning(_('unknown Linux hwtype for %s: %s'),
+ ifname.name, type_num)
def running(node):
"""Retrieve the service configuration for this device."""
ifaces = util.subelm(node, 'if:interfaces')
- _add_running_contents(ifaces)
+
+ nmsa_ns = "http://netconf.adelielinux.org/ns/netmgmt"
+ nmsa = MODMAN._module_for_ns(nmsa_ns)
+
+ if nmsa is None:
+ # We can't get any parameters if an NMSA module isn't loaded.
+ return
+
+ _add_iface_contents(ifaces, [
+ pathlib.Path('/sys/class/net/{iface}'.format(iface=iface))
+ for iface in nmsa.interface_list()
+ ])
+
+ for iface in ifaces.iterchildren():
+ name = iface.find('{'+M_NS+'}name').text
+
+ if nmsa is None:
+ continue
+
+ desc = nmsa.get_param(name, 'description')
+ if desc is not None:
+ iface.append(util.leaf_elm('if:description', desc))
+ enabled = nmsa.get_param(name, 'enabled')
+ if enabled is not None:
+ iface.append(util.leaf_elm('if:enabled', str(enabled).lower()))
def _add_stats_to(iface, name: str):
@@ -144,12 +169,23 @@ def _add_stats_to(iface, name: str):
def operational(node):
"""Retrieve the service state for this device."""
ifaces = util.subelm(node, 'if:interfaces')
- _add_running_contents(ifaces)
+ _add_iface_contents(ifaces, pathlib.Path('/sys/class/net').iterdir())
+
+ nmsa_ns = "http://netconf.adelielinux.org/ns/netmgmt"
+ nmsa = MODMAN._module_for_ns(nmsa_ns)
for iface in ifaces.iterchildren():
name = iface.find('{'+M_NS+'}name').text
ifpath = pathlib.Path("/sys/class/net/" + name)
+ if nmsa is not None:
+ desc = nmsa.curr_param(name, 'description')
+ if desc is not None:
+ iface.append(util.leaf_elm('if:description', desc))
+ enabled = nmsa.curr_param(name, 'enabled')
+ if enabled is not None:
+ iface.append(util.leaf_elm('if:enabled', str(enabled).lower()))
+
# if-index
if (ifpath / "ifindex").exists():
index_file = open(ifpath / "ifindex", 'r')
diff --git a/ncserver/module/nms_ifupdownng.py b/ncserver/module/nms_ifupdownng.py
index ab6a4c3..252ab78 100644
--- a/ncserver/module/nms_ifupdownng.py
+++ b/ncserver/module/nms_ifupdownng.py
@@ -324,16 +324,6 @@ def live_ipv6en(iface: str, parameter: str):
return not live_sysctl_bool(iface, parameter)
-def live_enabled(iface: str, _):
- """Determine if the interface is enabled or not."""
- statepath = _iface_path(iface) / "operstate"
- if statepath.exists():
- with open(statepath, 'r') as state_file:
- return state_file.read().strip() == "up"
-
- return False
-
-
def live_ipv4_mtu(iface: str, _):
"""Determine the IPv4 MTU for the interface."""
mtupath = _iface_path(iface) / "mtu"
@@ -484,8 +474,7 @@ def unset_slaac(iface: str, parameter: str):
_PARAMETERS = {
# "name": (getter, live getter, setter, unsetter)
'description': (get_one_eni, get_one_eni, set_desc, unset_one_eni),
- 'enabled': (get_one_eni, live_enabled,
- set_auto, unset_one_eni),
+ 'enabled': (get_one_eni, get_one_eni, set_auto, unset_one_eni),
# XXX TODO: ipv4_enabled
'ipv4_forwarding': (get_sysctl_bool, live_sysctl_bool,
set_sysctl_bool, unset_sysctl),
@@ -695,6 +684,18 @@ def remove_address(iface: str, addr: str):
raise NotImplementedError
+def running(_):
+ pass
+
+
+def operational(_):
+ pass
+
+
+def edit(*params):
+ pass
+
+
# Load immediately when we're loaded so we can go straight to a transaction
# if desired.
_load_config()