From 7952a8645124ef160c2759a2dae9e9cb32eac1a9 Mon Sep 17 00:00:00 2001 From: omnom62 Date: Mon, 2 Mar 2026 21:20:30 +1000 Subject: first commit --- plugins/module_utils/utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plugins/module_utils/utils.py (limited to 'plugins/module_utils/utils.py') diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py new file mode 100644 index 0000000..f256247 --- /dev/null +++ b/plugins/module_utils/utils.py @@ -0,0 +1,40 @@ +def normalize_to_list(value): + """ + Normalize VyOS REST return values to list. + + Handles: + dict -> keys + list -> same + str -> [value] + None -> [] + """ + if isinstance(value, dict): + return list(value.keys()) + + if isinstance(value, list): + return value + + if isinstance(value, str): + return [value] + + return [] + + +def normalize_to_dict(value): + """ + Normalize VyOS REST return values to dict. + + list -> {item: {}} + str -> {value: {}} + dict -> same + """ + if isinstance(value, dict): + return value + + if isinstance(value, list): + return {v: {} for v in value} + + if isinstance(value, str): + return {value: {}} + + return {} \ No newline at end of file -- cgit v1.2.3