diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-09-11 14:32:22 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-09-11 14:32:22 -0500 |
commit | ca203f339f392ec7590cd3fcf5ac7847ea3c1f28 (patch) | |
tree | c895428faee4a6a121be448252f012f95c4713c1 | |
parent | 680c3616ae89eeda8cfab104b3b24d9dea89dd4e (diff) | |
download | netconfapk-ca203f339f392ec7590cd3fcf5ac7847ea3c1f28.tar.gz netconfapk-ca203f339f392ec7590cd3fcf5ac7847ea3c1f28.tar.bz2 netconfapk-ca203f339f392ec7590cd3fcf5ac7847ea3c1f28.tar.xz netconfapk-ca203f339f392ec7590cd3fcf5ac7847ea3c1f28.zip |
util: Add accessory functions for editing config
-rw-r--r-- | ncserver/base/util.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/ncserver/base/util.py b/ncserver/base/util.py index 3df076c..f69c65b 100644 --- a/ncserver/base/util.py +++ b/ncserver/base/util.py @@ -11,8 +11,35 @@ SPDX-License-Identifier: NCSA """ -def _(the_string): +from netconf import error + + +def _(the_string: str) -> str: """Translate a user-facing string. Currently not implemented, but allows us to implement translation later.""" return the_string + + +def ensure_leaf(rpc, node): + """Ensure that the node is a leaf (contains no child nodes).""" + if len(node) > 0: + raise error.UnknownElementAppError(rpc, node[0]) + + +def node_operation(node, def_op='merge') -> str: + """Determine the operation desired for an XML node. + + :param node: + The node. + + :param str def_op: + The default operation if none is specified. Defaults to 'merge'. + + :returns str: + The operation desired. + """ + + nc10 = '{urn:ietf:params:xml:ns:netconf:base:1.0}operation' + nc11 = '{urn:ietf:params:xml:ns:netconf:base:1.1}operation' + return node.attrib.get(nc11, node.attrib.get(nc10, def_op)) |