summaryrefslogtreecommitdiff
path: root/plugins/module_utils/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/module_utils/utils.py')
-rw-r--r--plugins/module_utils/utils.py40
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