From 937fa5aad2519f588c6d0feb8f08211f6b99872f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Feb 2022 18:22:19 -0800 Subject: [PATCH] split dhcp options --- jc/parsers/nmcli.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index d3c1ce80..1614299b 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -144,6 +144,17 @@ def _split_routes(value: str) -> Dict: return output_dict +def _split_options(value: str) -> Dict: + # ip_address = 192.168.71.180 + # requested_broadcast_address = 1 + output_dict = {} + k, v = value.split('=') + output_dict['name'] = k.strip() + output_dict['value'] = v.strip() + + return output_dict + + def _device_show_parse(data: str) -> List[Dict]: raw_output: List = [] item: Dict = {} @@ -166,6 +177,12 @@ def _device_show_parse(data: str) -> List[Dict]: item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + + if '_route_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_routes(item[key_n]) + # get final item if item: raw_output.append(item) @@ -189,6 +206,9 @@ def _connection_show_x_parse(data: str) -> List[Dict]: item[key_n] = _remove_text_from_value(value_n) item.update(text_kv) + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + if '_route_' in key_n and key_n[-1].isdigit(): item[key_n] = _split_routes(item[key_n])