diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2022-07-09 10:13:42 +0000 |
---|---|---|
committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2022-07-09 10:13:42 +0000 |
commit | b2e6934152e94db21ca96525915db70bc6e9f172 (patch) | |
tree | 3dd7f520139d3585804cbb9aad74687287e8f476 /src/op_mode | |
parent | 2fcbd6315077d0a9d8c5d261e768282485d31ce6 (diff) | |
download | vyos-1x-b2e6934152e94db21ca96525915db70bc6e9f172.tar.gz vyos-1x-b2e6934152e94db21ca96525915db70bc6e9f172.zip |
nat: T4499: Fix NAT not showing a single flow entry
We must change dictionary if we get only onle flow entry
I.e one NAT record
With single entry we get:
OrderedDict([('meta', xxx]))
We expect:
[OrderedDict([('meta', xxx]))]
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/show_nat_translations.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/op_mode/show_nat_translations.py b/src/op_mode/show_nat_translations.py index 25091e9fc..508845e23 100755 --- a/src/op_mode/show_nat_translations.py +++ b/src/op_mode/show_nat_translations.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2020 VyOS maintainers and contributors +# Copyright (C) 2020-2022 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -83,11 +83,23 @@ def pipe(): return xml +def xml_to_dict(xml): + """ + Convert XML to dictionary + Return: dictionary + """ + parse = xmltodict.parse(xml) + # If only one NAT entry we must change dict T4499 + if 'meta' in parse['conntrack']['flow']: + return dict(conntrack={'flow': [parse['conntrack']['flow']]}) + return parse + + def process(data, stats, protocol, pipe, verbose, flowtype=''): if not data: return - parsed = xmltodict.parse(data) + parsed = xml_to_dict(data) print(headers(verbose, pipe)) |