summaryrefslogtreecommitdiff
path: root/ncserver/module/interfaces.py
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-07 19:22:03 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-07 19:22:03 -0600
commitecbfce3b78b01501313234c9b669f0fcccf48559 (patch)
treeef382a319ee5f4eaf4a6f9aefe3645b11594ee78 /ncserver/module/interfaces.py
parent892323d81f22dedf2cd36d8e0819955c46b21f03 (diff)
downloadnetconfapk-ecbfce3b78b01501313234c9b669f0fcccf48559.tar.gz
netconfapk-ecbfce3b78b01501313234c9b669f0fcccf48559.tar.bz2
netconfapk-ecbfce3b78b01501313234c9b669f0fcccf48559.tar.xz
netconfapk-ecbfce3b78b01501313234c9b669f0fcccf48559.zip
ietf-interfaces,ip: Misc fixes
Diffstat (limited to 'ncserver/module/interfaces.py')
-rw-r--r--ncserver/module/interfaces.py43
1 files changed, 37 insertions, 6 deletions
diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py
index ec3861c..d6e0196 100644
--- a/ncserver/module/interfaces.py
+++ b/ncserver/module/interfaces.py
@@ -19,6 +19,7 @@ from netconf import error, util
from ncserver.base.modman import MODMAN
from ncserver.base.util import _, node_operation, yang_dt_for_timestamp
+from ncserver.util import maybe_raise_on_invalid_node
QName = etree.QName # pylint: disable=I1101
@@ -251,6 +252,17 @@ def _edit_description(session, rpc, node, def_op, iface: str):
def _edit_enabled(session, rpc, node, def_op, iface: str):
"""Edit the enabled property of an interface."""
+ operation = node_operation(node, def_op)
+ nmsa = _get_nmsa()
+
+ if operation == 'create':
+ raise error.DataExistsAppError(rpc)
+
+ if operation not in ('merge', 'replace'):
+ # You cannot delete the enabled node.
+ raise error.OperationNotSupportedAppError(rpc)
+
+ nmsa.set_param(iface, 'enabled', (node.text == 'true'))
def edit(session, rpc, node, def_op):
@@ -267,16 +279,35 @@ def edit(session, rpc, node, def_op):
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)
+ name_node = interface.find('{'+M_NS+'}name')
+ if name_node is None:
+ raise error.MissingElementAppError(rpc, interface)
+ iface = name_node.text
+
+ operation = node_operation(interface, def_op)
+ if operation in ('create', 'delete', 'remove'):
+ # We are operating on the "entire" interface here, not just a
+ # single element.
+ if operation == 'delete' and iface not in nmsa.interface_list():
+ raise error.DataMissingAppError(rpc)
+
+ if operation in ('delete', 'remove'):
+ nmsa.remove_interface(iface)
+ continue
+
+ enable_node = interface.find('{'+M_NS+'}enabled')
+ if enable_node is None:
+ nmsa.set_param(iface, 'enabled', True) # Default.
+ else:
+ nmsa.set_param(iface, 'enabled', enable_node.text == 'true')
+ # Don't let _edit_enabled raise an error due to 'create' op.
+ interface.remove(enable_node)
for candidate in interface:
name = QName(candidate.tag).localname
if name in methods:
- methods[name](session, rpc, candidate, operation, iface_name)
+ methods[name](session, rpc, candidate, operation, iface)
elif name == 'name':
continue
else:
- raise error.UnknownElementAppError(rpc, candidate)
+ maybe_raise_on_invalid_node(M_NS, rpc, candidate)