diff options
| author | omnom62 <omnom62@outlook.com> | 2026-03-02 21:20:30 +1000 |
|---|---|---|
| committer | omnom62 <omnom62@outlook.com> | 2026-03-02 21:20:30 +1000 |
| commit | 7952a8645124ef160c2759a2dae9e9cb32eac1a9 (patch) | |
| tree | a01436ff4f4af14d7386715e9e7c613f05d5ac2c /plugins/module_utils/utils.py | |
| download | rest.vyos-7952a8645124ef160c2759a2dae9e9cb32eac1a9.tar.gz rest.vyos-7952a8645124ef160c2759a2dae9e9cb32eac1a9.zip | |
first commit
Diffstat (limited to 'plugins/module_utils/utils.py')
| -rw-r--r-- | plugins/module_utils/utils.py | 40 |
1 files changed, 40 insertions, 0 deletions
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 |
