diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-06-12 13:00:38 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-06-12 15:35:38 -0500 |
| commit | 548dcd5b1471ed2877e53a9663869903a6d02f8f (patch) | |
| tree | d7cc53eb75e3b9d2ceb40d53b68fbe244bb9867e /python | |
| parent | 01d0cf6b49e7d71510652ff6b54db7d7f39f163a (diff) | |
| download | vyos-1x-548dcd5b1471ed2877e53a9663869903a6d02f8f.tar.gz vyos-1x-548dcd5b1471ed2877e53a9663869903a6d02f8f.zip | |
T8980: add convenience function to apply exlusion list to config tree
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/derivedtree.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/python/vyos/derivedtree.py b/python/vyos/derivedtree.py index dc46b8eb3..61e1a4d94 100644 --- a/python/vyos/derivedtree.py +++ b/python/vyos/derivedtree.py @@ -18,6 +18,7 @@ from vyos.referencetree import ReferenceTree from vyos.configtree import ConfigTree from vyos.configtree import ConfigTreeError from vyos.configtree import subtree_from_partial +from vyos.configtree import mask_exclusive class DerivedTreeError(Exception): @@ -29,7 +30,7 @@ def subtree_from_list_of_partial_paths( paths: list[list[str]], accumulator: ConfigTree = None, reference_tree: ReferenceTree = None, -): +) -> ConfigTree: """Return the union of subtrees of the ConfigTree argument matching each of the 'partial' paths. A partial path is one that may or may not contain intervening tag node values, in which case it will match for all @@ -61,3 +62,15 @@ def subtree_from_list_of_partial_paths( raise DerivedTreeError(f'Nonsensical paths: {errors}') return accumulator + + +def apply_exclusion_list( + config_tree: ConfigTree, exclusion_list: list[list[str]] +) -> ConfigTree: + mask_ex = subtree_from_list_of_partial_paths(config_tree, exclusion_list) + try: + masked = mask_exclusive(config_tree, mask_ex) + except ConfigTreeError as e: + raise DerivedTreeError(str(e)) from e + + return masked |
