summaryrefslogtreecommitdiff
path: root/python/vyos/xml/definition.py
diff options
context:
space:
mode:
authorMarcus Hoff <marcus.hoff@ring2.dk>2020-09-05 09:58:03 +0200
committerMarcus Hoff <marcus.hoff@ring2.dk>2020-09-05 09:58:03 +0200
commit46fb580fa0131f6815bbcfc95631654f6fe999a8 (patch)
tree73ae9fcaa97d5cfab7883bc6fbf3ea036677c2a3 /python/vyos/xml/definition.py
parent0377b8e40b0d3e424da11194e97659c5066c0a1d (diff)
parentb6b61bc9ecf1328e67a0c15934f8bf3966a6b66d (diff)
downloadvyos-1x-46fb580fa0131f6815bbcfc95631654f6fe999a8.tar.gz
vyos-1x-46fb580fa0131f6815bbcfc95631654f6fe999a8.zip
Merge remote-tracking branch 'upstream/current' into current
Diffstat (limited to 'python/vyos/xml/definition.py')
-rw-r--r--python/vyos/xml/definition.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/python/vyos/xml/definition.py b/python/vyos/xml/definition.py
index b0339b228..a25fc50c5 100644
--- a/python/vyos/xml/definition.py
+++ b/python/vyos/xml/definition.py
@@ -126,10 +126,12 @@ class XML(dict):
elif word:
if data_node != kw.plainNode or len(passed) == 1:
self.options = [_ for _ in self.tree if _.startswith(word)]
+ self.options.sort()
else:
self.options = []
else:
self.options = named_options
+ self.options.sort()
self.plain = not is_dataNode
@@ -143,6 +145,7 @@ class XML(dict):
self.word = ''
if self.tree.get(kw.node,'') not in (kw.tagNode, kw.leafNode):
self.options = [_ for _ in self.tree if not kw.found(_)]
+ self.options.sort()
def checks(self, cmd):
# as we move thought the named node twice
@@ -251,6 +254,9 @@ class XML(dict):
d = d.get(k, {})
if not flat:
+ # _flatten will make this conversion
+ d = self.multi_to_list(lpath, d)
+
r = {}
for k in d:
under = k.replace('-','_')
@@ -278,6 +284,23 @@ class XML(dict):
return _flatten(lpath, len(lpath), d)
+ def multi_to_list(self, lpath, conf):
+ r = {}
+ for k in conf:
+ # key mangling could also be done here
+ # it would prevent two parsing of the config tree
+ # under = k.replace('-','_')
+ under = k
+ fpath = lpath + [k]
+ if isinstance(conf[k],dict):
+ r[under] = self.multi_to_list(fpath, conf[k])
+ continue
+ value = conf[k]
+ if self.is_multi(fpath) and not isinstance(value, list):
+ value = [value]
+ r[under] = value
+ return r
+
# from functools import lru_cache
# @lru_cache(maxsize=100)
# XXX: need to use cachetool instead - for later
@@ -300,16 +323,28 @@ class XML(dict):
return tree
def _get(self, lpath, tag, with_tag=True):
- return self._tree(lpath + [tag], with_tag)
+ tree = self._tree(lpath, with_tag)
+ if tree is None:
+ return None
+ return tree.get(tag, None)
def is_multi(self, lpath, with_tag=True):
- return self._get(lpath, kw.multi, with_tag) is True
+ tree = self._get(lpath, kw.multi, with_tag)
+ if tree is None:
+ return None
+ return tree is True
def is_tag(self, lpath, with_tag=True):
- return self._get(lpath, kw.node, with_tag) == kw.tagNode
+ tree = self._get(lpath, kw.node, with_tag)
+ if tree is None:
+ return None
+ return tree == kw.tagNode
def is_leaf(self, lpath, with_tag=True):
- return self._get(lpath, kw.node, with_tag) == kw.leafNode
+ tree = self._get(lpath, kw.node, with_tag)
+ if tree is None:
+ return None
+ return tree == kw.leafNode
def exists(self, lpath, with_tag=True):
return self._get(lpath, kw.node, with_tag) is not None