summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 3ce54f28..9bafd5b3 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -31,6 +31,7 @@ import glob
import grp
import gzip
import hashlib
+import json
import os
import os.path
import platform
@@ -385,6 +386,15 @@ def multi_log(text, console=True, stderr=True,
log.log(log_level, text)
+def load_json(text, root_types=(dict,)):
+ decoded = json.loads(text)
+ if not isinstance(decoded, tuple(root_types)):
+ expected_types = ", ".join([str(t) for t in root_types])
+ raise TypeError("(%s) root types expected, got %s instead"
+ % (expected_types, type(decoded)))
+ return decoded
+
+
def is_ipv4(instr):
"""determine if input string is a ipv4 address. return boolean."""
toks = instr.split('.')