diff options
| author | Scott Moser <smoser@ubuntu.com> | 2014-09-10 21:17:40 -0400 | 
|---|---|---|
| committer | Scott Moser <smoser@ubuntu.com> | 2014-09-10 21:17:40 -0400 | 
| commit | 932c073db79e667623d27174c55e5b16ea439578 (patch) | |
| tree | 14469c0eff9bb76c038f4c7f58cc31e752e8a2eb /cloudinit/sources/helpers | |
| parent | 2755274f34ef11651a5ee57a31955f3e413cdfc4 (diff) | |
| download | vyos-cloud-init-932c073db79e667623d27174c55e5b16ea439578.tar.gz vyos-cloud-init-932c073db79e667623d27174c55e5b16ea439578.zip | |
Openstack: Vendor data cleanup
For now, this vendor data handling is just added to openstack.
However, in an effort to allow sanely handling of multi-part vendor-data
that is namespaced, we add openstack.convert_vendordata_json .
That basically takes whatever was loaded from vendordata and takes
the 'cloud-init' key if it is a dict.  This way the author can
namespace cloud-init, basically telling it to ignore everything else.
Diffstat (limited to 'cloudinit/sources/helpers')
| -rw-r--r-- | cloudinit/sources/helpers/openstack.py | 25 | 
1 files changed, 25 insertions, 0 deletions
| diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py index a7dd05df..9718b0be 100644 --- a/cloudinit/sources/helpers/openstack.py +++ b/cloudinit/sources/helpers/openstack.py @@ -459,3 +459,28 @@ class MetadataReader(BaseReader):          return ec2_utils.get_instance_metadata(ssl_details=self.ssl_details,                                                 timeout=self.timeout,                                                 retries=self.retries) + + +def convert_vendordata_json(data, recurse=True): +    """ data: a loaded json *object* (strings, arrays, dicts). +    return something suitable for cloudinit vendordata_raw. + +    if data is: +       None: return None +       string: return string +       list: return data +             the list is then processed in UserDataProcessor +       dict: return convert_vendordata_json(data.get('cloud-init')) +    """ +    if not data: +        return None +    if isinstance(data, (str, unicode, basestring)): +        return data +    if isinstance(data, list): +        return copy.deepcopy(data) +    if isinstance(data, dict): +        if recurse is True: +            return convert_vendordata_json(data.get('cloud-init'), +                                           recurse=False) +        raise ValueError("vendordata['cloud-init'] cannot be dict") +    raise ValueError("Unknown data type for vendordata: %s" % type(data)) | 
