summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-03 18:55:33 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-03 18:55:33 -0600
commit8dc6ad089193ad285812579d324fdb20f3d67493 (patch)
tree2fa558e0bd31833edd5917a41b254fd71be239c0
parentb3ca4b49ef72724a6fc1eb13453cb7aee9960756 (diff)
downloadnetconfapk-8dc6ad089193ad285812579d324fdb20f3d67493.tar.gz
netconfapk-8dc6ad089193ad285812579d324fdb20f3d67493.tar.bz2
netconfapk-8dc6ad089193ad285812579d324fdb20f3d67493.tar.xz
netconfapk-8dc6ad089193ad285812579d324fdb20f3d67493.zip
ietf-interfaces: Add ability to edit description
-rw-r--r--ncserver/module/interfaces.py73
1 files changed, 63 insertions, 10 deletions
diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py
index 7a02708..ec3861c 100644
--- a/ncserver/module/interfaces.py
+++ b/ncserver/module/interfaces.py
@@ -15,10 +15,10 @@ import pathlib
import subprocess
from lxml import etree
-from netconf import util
+from netconf import error, util
from ncserver.base.modman import MODMAN
-from ncserver.base.util import _, yang_dt_for_timestamp
+from ncserver.base.util import _, node_operation, yang_dt_for_timestamp
QName = etree.QName # pylint: disable=I1101
@@ -103,12 +103,18 @@ def _add_iface_contents(container, ifaces):
ifname.name, type_num)
+def _get_nmsa():
+ """Retrieve our NMSA module handle."""
+ nmsa_ns = "http://netconf.adelielinux.org/ns/netmgmt"
+ nmsa = MODMAN._module_for_ns(nmsa_ns) # pylint: disable=W0212
+
+ return nmsa
+
+
def running(node):
"""Retrieve the service configuration for this device."""
ifaces = util.subelm(node, 'if:interfaces')
-
- nmsa_ns = "http://netconf.adelielinux.org/ns/netmgmt"
- nmsa = MODMAN._module_for_ns(nmsa_ns) # pylint: disable=W0212
+ nmsa = _get_nmsa()
if nmsa is None:
# We can't get any parameters if an NMSA module isn't loaded.
@@ -122,9 +128,6 @@ def running(node):
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))
@@ -172,8 +175,7 @@ def operational(node):
ifaces = util.subelm(node, 'if:interfaces')
_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) # pylint: disable=W0212
+ nmsa = _get_nmsa()
for iface in ifaces.iterchildren():
name = iface.find('{'+M_NS+'}name').text
@@ -225,5 +227,56 @@ def operational(node):
_add_stats_to(iface, name)
+def _edit_description(session, rpc, node, def_op, iface: str):
+ """Edit the description for an interface."""
+ operation = node_operation(node, def_op)
+ nmsa = _get_nmsa()
+ already = nmsa.get_param(iface, 'description') is not None
+
+ if operation == 'create' and already:
+ raise error.DataExistsAppError(rpc)
+
+ if operation == 'delete' and not already:
+ raise error.DataMissingAppError(rpc)
+
+ if operation in ('delete', 'remove'):
+ nmsa.unset_param(iface, 'description')
+ return
+
+ if operation not in ('create', 'merge', 'replace'):
+ raise error.OperationNotSupportedAppError(rpc)
+
+ nmsa.set_param(iface, 'description', node.text)
+
+
+def _edit_enabled(session, rpc, node, def_op, iface: str):
+ """Edit the enabled property of an interface."""
+
+
def edit(session, rpc, node, def_op):
"""Edit the interface configuration for this device."""
+ methods = {'description': _edit_description, 'enabled': _edit_enabled}
+
+ nmsa = _get_nmsa()
+ # We can't edit if we don't have an NMSA module loaded.
+ # This guarantees that none of our child functions need to test for nmsa.
+ if nmsa is None:
+ raise error.OperationNotSupportedAppError(rpc)
+
+ for interface in node:
+ if QName(interface.tag).localname != 'interface':
+ raise error.UnknownElementAppError(rpc, interface)
+
+ iface_name = interface.find('{'+M_NS+'}name').text
+ # One never knows if some admin or utility will set an operation on
+ # the interface node itself. This is legal, so we handle it here:
+ operation = node_operation(node, def_op)
+
+ for candidate in interface:
+ name = QName(candidate.tag).localname
+ if name in methods:
+ methods[name](session, rpc, candidate, operation, iface_name)
+ elif name == 'name':
+ continue
+ else:
+ raise error.UnknownElementAppError(rpc, candidate)