diff options
author | Christian Breunig <christian@breunig.cc> | 2023-02-13 17:38:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 17:38:16 +0100 |
commit | 5e56daaff4ec53a387abbd3ad879e916a2bfa373 (patch) | |
tree | 3a9a3d1823e01287c52a38cc67c0b7061bc901ce /python/vyos/util.py | |
parent | 9c481b00cae8ed1d121c809fb5edc24a937525e9 (diff) | |
parent | e7e81746e6ad01ce644cd7b584233464f91d9380 (diff) | |
download | vyos-1x-5e56daaff4ec53a387abbd3ad879e916a2bfa373.tar.gz vyos-1x-5e56daaff4ec53a387abbd3ad879e916a2bfa373.zip |
Merge pull request #1813 from sever-sever/T4971-eq
T4971: PPPoE server add named ip pool and attr Framed-Pool
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 5c6409341..32a5ae116 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -1,4 +1,4 @@ -# Copyright 2020-2022 VyOS maintainers and contributors <maintainers@vyos.io> +# Copyright 2020-2023 VyOS maintainers and contributors <maintainers@vyos.io> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -720,6 +720,26 @@ def dict_search(path, dict_object): c = c.get(p, {}) return c.get(parts[-1], None) +def dict_search_recursive(dict_object, key, path=[]): + """ Traverse a dictionary recurisvely and return the value of the key + we are looking for. + Thankfully copied from https://stackoverflow.com/a/19871956 + Modified to yield optional path to found keys + """ + if isinstance(dict_object, list): + for i in dict_object: + new_path = path + [i] + for x in dict_search_recursive(i, key, new_path): + yield x + elif isinstance(dict_object, dict): + if key in dict_object: + new_path = path + [key] + yield dict_object[key], new_path + for k, j in dict_object.items(): + new_path = path + [k] + for x in dict_search_recursive(j, key, new_path): + yield x + def convert_data(data): """Convert multiple types of data to types usable in CLI |