summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-07 19:20:52 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-07 19:20:52 -0600
commitec8637540f403a607a18f3f77ee6c10c141e4291 (patch)
tree7c2a436cd972085f2eb1c0234a9464b6f7dc05c6
parent8dc6ad089193ad285812579d324fdb20f3d67493 (diff)
downloadnetconfapk-ec8637540f403a607a18f3f77ee6c10c141e4291.tar.gz
netconfapk-ec8637540f403a607a18f3f77ee6c10c141e4291.tar.bz2
netconfapk-ec8637540f403a607a18f3f77ee6c10c141e4291.tar.xz
netconfapk-ec8637540f403a607a18f3f77ee6c10c141e4291.zip
Module Manager: Support augmenting models
This is very early code, but seems to work.
-rw-r--r--ncserver/base/modman.py28
-rw-r--r--ncserver/util.py36
2 files changed, 64 insertions, 0 deletions
diff --git a/ncserver/base/modman.py b/ncserver/base/modman.py
index d8659a2..5033afa 100644
--- a/ncserver/base/modman.py
+++ b/ncserver/base/modman.py
@@ -146,6 +146,25 @@ class ModuleManager:
return None
+ def _augments_for_ns(self, namespace):
+ """Find modules that augment the specified namespace.
+
+ :param str namespace:
+ The namespace of the model whose augments are desired.
+
+ :returns:
+ An Iterable of modules that augment the namespace.
+ The Iterable may be empty.
+ """
+ augments = list()
+
+ for mod in self.modules.values():
+ if getattr(mod, 'M_AUGMENTS', None) is not None and \
+ namespace in mod.M_AUGMENTS:
+ augments.append(mod)
+
+ return augments
+
def load_module(self, name):
"""Load a module.
@@ -325,6 +344,15 @@ class ModuleManager:
raise error.OperationNotSupportedAppError(rpc)
self.logger.debug('Dispatching edit-config to %s', module.M_NAME)
module.edit(session, rpc, child, def_op)
+ for augment in self._augments_for_ns(namespace):
+ try:
+ self.logger.debug(
+ 'Augment: Dispatching edit-config for %s to %s',
+ namespace, augment.M_NAME
+ )
+ augment.edit(session, rpc, child, def_op)
+ except error.OperationNotSupportedAppError:
+ continue
MODMAN = ModuleManager()
diff --git a/ncserver/util.py b/ncserver/util.py
new file mode 100644
index 0000000..209d4d9
--- /dev/null
+++ b/ncserver/util.py
@@ -0,0 +1,36 @@
+"""
+NETCONF for APK Distributions server:
+ Higher-level utility functions.
+
+Copyright © 2020 Adélie Software in the Public Benefit, Inc.
+
+Released under the terms of the NCSA license. See the LICENSE file included
+with this source distribution for more information.
+
+SPDX-License-Identifier: NCSA
+"""
+
+
+from lxml.etree import QName
+from netconf import error
+
+from ncserver.base.modman import MODMAN
+
+
+def maybe_raise_on_invalid_node(xmlns, rpc, node):
+ """Determine if this node should cause the module in namespace to raise.
+
+ :param str xmlns:
+ The xmlns of the current module.
+
+ :param rpc:
+ The RPC causing this lookup to happen.
+
+ :param node:
+ The node in question.
+ """
+ nodens = QName(node).namespace
+ if nodens == xmlns:
+ raise error.UnknownElementAppError(rpc, node)
+ if nodens not in (mod.M_PREFIX for mod in MODMAN._augments_for_ns(xmlns)):
+ raise error.UnknownNamespaceAppError(rpc, node, None)