summaryrefslogtreecommitdiff
path: root/ncserver/base/modman.py
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-09-11 14:31:30 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-09-11 14:31:30 -0500
commitb3def43fe057d7b635ae1ed4e298997e4a27644f (patch)
tree8f7c02a01b49fc512498e1b91aa1e03d242a97d9 /ncserver/base/modman.py
parent16e322a9c71cde15d3112d8f3ffc174e656f50ef (diff)
downloadnetconfapk-b3def43fe057d7b635ae1ed4e298997e4a27644f.tar.gz
netconfapk-b3def43fe057d7b635ae1ed4e298997e4a27644f.tar.bz2
netconfapk-b3def43fe057d7b635ae1ed4e298997e4a27644f.tar.xz
netconfapk-b3def43fe057d7b635ae1ed4e298997e4a27644f.zip
Module Manager: Add support for writing
Diffstat (limited to 'ncserver/base/modman.py')
-rw-r--r--ncserver/base/modman.py46
1 files changed, 43 insertions, 3 deletions
diff --git a/ncserver/base/modman.py b/ncserver/base/modman.py
index cb9d47f..8c08fd4 100644
--- a/ncserver/base/modman.py
+++ b/ncserver/base/modman.py
@@ -13,7 +13,8 @@ SPDX-License-Identifier: NCSA
import hashlib
from logging import getLogger
-from netconf import nsmap_add, util
+from lxml import etree
+from netconf import error, nsmap_add, util
from taillight import Signal
from ncserver.base.util import _
@@ -24,6 +25,9 @@ MODULE_SET_CHANGE_SIGNAL = Signal(('base/ModuleManager', 'module_set_changed'))
yang-library-change notification should be fired, when this is supported."""
+QName = etree.QName # pylint: disable=I1101
+
+
def _import_compatible(existing, improps):
"""Determine if an imported module is compatible with the existing
module that has the same name/revision.
@@ -126,6 +130,21 @@ class ModuleManager:
nsmap_add(self.M_PREFIX, self.M_NS)
self.logger = getLogger('base/ModuleManager')
+ def _module_for_ns(self, namespace):
+ """Find a module that implements the specified namespace.
+
+ :param str namespace:
+ The namespace of the module to locate.
+
+ :returns:
+ The module that implements the namespace, or None.
+ """
+ for mod in self.modules.values():
+ if mod.M_NS == namespace:
+ return mod
+
+ return None
+
def load_module(self, name):
"""Load a module.
@@ -159,6 +178,12 @@ class ModuleManager:
mod.M_ABI_VERSION)
return None
+ if self._module_for_ns(mod.M_NS) is not None:
+ self.logger.error(
+ _("Module '%s' implements duplicate namespace %s."), name,
+ mod.M_NS
+ )
+
if getattr(mod, 'M_IMPORTS', None) is not None:
for imname, improps in mod.M_IMPORTS.items():
if imname in self.imports:
@@ -225,8 +250,9 @@ class ModuleManager:
:param node:
The XML node to append to.
"""
- lib = util.subelm(node, 'yanglib:yang-library',
- nsmap={'ds': "urn:ietf:params:xml:ns:yang:ietf-datastores"})
+ lib = util.subelm(node, 'yanglib:yang-library', nsmap={
+ 'ds': "urn:ietf:params:xml:ns:yang:ietf-datastores"
+ })
modset = util.subelm(lib, 'yanglib:module-set')
modset.append(util.leaf_elm('yanglib:name', 'netconfapk'))
for module in self.modules.values():
@@ -273,3 +299,17 @@ class ModuleManager:
"""Collect all available information for the <operational> datastore"""
for mod in self.modules.values():
mod.operational(node)
+
+ def collect_edit(self, rpc, node, def_op):
+ """Send off edit operations to the requested module(s)."""
+ for child in node:
+ namespace = QName(child.tag).namespace
+ module = self._module_for_ns(namespace)
+ if module is None:
+ raise error.UnknownNamespaceAppError(
+ rpc, child, error.RPCERR_TYPE_APPLICATION
+ )
+ if getattr(module, 'edit', None) is None:
+ raise error.OperationNotSupportedAppError(rpc)
+ self.logger.debug('Dispatching edit-config to %s', module.M_NAME)
+ module.edit(rpc, child, def_op)