diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-02-13 21:18:17 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-02-13 21:18:17 -0500 |
commit | 4ba72556193219f90c313f62d0d309761bb53c6b (patch) | |
tree | 2ad80e184d53a85a1fe5933ad106249bc522da35 /cloudinit/util.py | |
parent | 507aeed12312af7fc8a9fcfca6b845183a5a3c51 (diff) | |
parent | 053667688d7c2ad51e569c62e00dac1942e46f62 (diff) | |
download | vyos-cloud-init-4ba72556193219f90c313f62d0d309761bb53c6b.tar.gz vyos-cloud-init-4ba72556193219f90c313f62d0d309761bb53c6b.zip |
merge from trunk
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 08cdd8c8..87b0c853 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -32,6 +32,7 @@ import glob import grp import gzip import hashlib +import json import os import os.path import platform @@ -362,6 +363,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('.') |