diff options
author | Joshua Harlow <harlowja@gmail.com> | 2014-02-13 13:54:43 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-02-13 13:54:43 -0500 |
commit | 9be5a7aa77b9679c50583666dcfd3ee811a65522 (patch) | |
tree | f46e7a9ebbe07bdc7a8957944bc7f0ccdb289f10 /cloudinit/util.py | |
parent | 322e404dcbb891bbdecd1da50e6b4789781a71d5 (diff) | |
parent | b8f1c6f27345d1aa0ef550a72bd34c2d7bd4ed41 (diff) | |
download | vyos-cloud-init-9be5a7aa77b9679c50583666dcfd3ee811a65522.tar.gz vyos-cloud-init-9be5a7aa77b9679c50583666dcfd3ee811a65522.zip |
Add a openstack specific datasource
Openstack has a unique derivative datasource that is gaining usage.
Previously the config drive datasource provided part of this functionality
as well as the ec2 datasource, but since new functionality is being added
to openstack's special datasource it seems beneficial to combine the used
parts into a new datasource just made for handling openstack deployments
that use the openstack metadata service (possibly in combination with the
ec2 metadata service).
This patch factors out the common logic shared between the config drive
and the openstack metadata datasource and places that in a shared helper
file and then creates a new openstack datasource that readers from the
openstack metadata service and refactors the config drive datasource to
use this common logic.
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('.') |