diff options
author | Christian Breunig <christian@breunig.cc> | 2024-04-26 20:33:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 20:33:59 +0200 |
commit | f980f8b8010a9681c387d47c476254c89b0c4a25 (patch) | |
tree | 0aba005506ce4384722ae67f9202f2b0d497bd98 /src/conf_mode | |
parent | 854864f0dffe3d3371bb05eaaf6c470ba16598dd (diff) | |
parent | 8c5c3bc48f76a5bb0c819c6f549d7fbcacf964de (diff) | |
download | vyos-1x-f980f8b8010a9681c387d47c476254c89b0c4a25.tar.gz vyos-1x-f980f8b8010a9681c387d47c476254c89b0c4a25.zip |
Merge pull request #3365 from vyos/mergify/bp/sagitta/pr-3316
qos: T4248: Allow to remove the only rule from the qos class (backport #3316)
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-x | src/conf_mode/qos.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/conf_mode/qos.py b/src/conf_mode/qos.py index 3dfb4bab8..ccfc8f6b8 100755 --- a/src/conf_mode/qos.py +++ b/src/conf_mode/qos.py @@ -70,6 +70,22 @@ def get_shaper(qos, interface_config, direction): return (map_vyops_tc[shaper_type], shaper_config) + +def _clean_conf_dict(conf): + """ + Delete empty nodes from config e.g. + match ADDRESS30 { + ip { + source {} + } + } + """ + if isinstance(conf, dict): + return {node: _clean_conf_dict(val) for node, val in conf.items() if val != {} and _clean_conf_dict(val) != {}} + else: + return conf + + def get_config(config=None): if config: conf = config @@ -120,6 +136,13 @@ def get_config(config=None): if 'queue_limit' not in qos['policy'][policy][p_name]['precedence'][precedence]: qos['policy'][policy][p_name]['precedence'][precedence]['queue_limit'] = \ str(int(4 * max_thr)) + # cleanup empty match config + if 'class' in p_config: + for cls, cls_config in p_config['class'].items(): + if 'match' in cls_config: + cls_config['match'] = _clean_conf_dict(cls_config['match']) + if cls_config['match'] == {}: + del cls_config['match'] return qos |