- datasources can be laid down into /var/lib/cloudinit/datasources/
if entry is a directory, it must have __init__.py and is loaded as a module
if entry is a file, it must end in .py and it will be loaded
- datasource providers must define get_datasources.
get_datasources should return
a list of dictionaries
{'version': 2, 'priority': X, class: class}
- classes are loaded in priority order their search(mode='local') is called.
Short circuit on first found.
ultimately could declare in the return a list of "resources" (/dev/ttyS0)
that the datasource would need exclusive access to and then you could
call some in parallel.
- if there is a previously booted instance data (/var/lib/cloud/instance/obj.pkl)
then load it and call quick_check to see if it is still relevant
(on openstack that checks the dmi product id versus the stored instance-id)
- if did not reload from cache, then search(local) on each
if a True is found in search(local) then short circuit:
if class.dsmode == local:
then user data will be consumed and init_modules run
module is pickled to /var/lib/cloud/instance/obj.pkl
- if did not find in search(local) then search(network-probe)
this allows some datasources to go looking
- if not found in search(network-probe)
generate fallback networking
come back up after fallback networking and call search(network)
Version 2 Datasources
def __init__(self, sys_cfg, distro, paths)
sys_cfg : system config (loaded /etc/cloud.cfg.d)
distr: the current cloudinit.distro
paths: paths paths object for finding defined paths
def search(mode=('local', 'network-probe' or 'network'))
return True if this is the right datasource (you've found data)
raise UnNeccesaryDatasource if no more 'search' are necessary here
(definitively found this is *not* the right datasource)
return False if further searching should be done.
local-only: only search 'local' datasources
network-probe: you can muck with networking to further look
ie, you could bring up an ipv4 link local and try http://169.254.169.254/
network: network is configured, you can read data from network sources
@property
def dsmode()
return local or network
defines when the init_modules should be invoked
should be 'network' in almost any case unless the user
provided data or config indicates should be a local
Questions:
is statedir usefuL?
statedir: place to store state (/var/lib/cloud/instances/)
the intent of this is for a datasource that searches
locally can pick back up in network search.
for example NoCloud or ConfigDrive would find a disk
and thus know that it is the applicable datasource
but would not