cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #05022
Re: [Merge] ~chad.smith/cloud-init:feature/maintain-network-on-boot into cloud-init:master
so where would the logic of "apply if changed" be placed?
Diff comments:
> diff --git a/cloudinit/hotplug.py b/cloudinit/hotplug.py
> new file mode 100644
> index 0000000..c5ba1af
> --- /dev/null
> +++ b/cloudinit/hotplug.py
> @@ -0,0 +1,15 @@
> +# This file is part of cloud-init. See LICENSE file for license information.
> +"""Classes and functions related to hotplug and eventing."""
> +
> +# Maintenance events describing the source generating a maintenance request.
> +class MaintenanceEvent(object):
> + NONE = 0x0 # React to no maintenance events
> + BOOT = 0x1 # Any system boot or reboot event
> + DEVICE_ADD = 0x2 # Any new device added
> + DEVICE_REMOVE = 0x4 # Any device removed
i think these ADD/REMOVE are not relevant anymore.
right?
> + DEVICE_CHANGE = 0x8 # Any device metadata change
> + ANY = 0xF # Match any defined MaintenanceEvents
> +
> +MAINTENANCE_EVENT_STR = dict(
> + (attr, getattr(MaintenanceEvent, attr))
> + for attr in MaintenanceEvent.__dict__.keys() if attr.isupper())
> diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py
> index 24fd65f..cd6ab17 100644
> --- a/cloudinit/sources/DataSourceAltCloud.py
> +++ b/cloudinit/sources/DataSourceAltCloud.py
> @@ -114,7 +114,7 @@ class DataSourceAltCloud(sources.DataSource):
>
> return 'UNKNOWN'
>
> - def _get_data(self):
> + def _get_data(self, clear_cache=False):
ultimately i think we want *some* method on a datasource that actually just gets the data and doesnt modify the state of the datasource.
then, that thing doesnt have a 'clear_cache' it just gets called.
when i first read this without looking, i was thinking that _get_data() was that thing. but it appears some of our datasources modify their state there.
> '''
> Description:
> User Data is passed to the launching instance which
> diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
> index 90d7457..af876ad 100644
> --- a/cloudinit/sources/__init__.py
> +++ b/cloudinit/sources/__init__.py
> @@ -416,6 +440,32 @@ class DataSource(object):
> def get_package_mirror_info(self):
> return self.distro.get_package_mirror_info(data_source=self)
>
> + def maintain_metadata(self, maintenance_event):
> + """Refresh cached metadata if the datasource handles this event.
> +
> + The datasource defines a network_maintenance_mask attribute which
> + authorizes refreshing all cached metadata due to any number of
> + supported MaintenenanceEvent types.
> +
> + @param maintenance_event: The source MaintenanceEvent type
> + observed to which the datasource may react.
> +
> + @return True if the datasource has updated cached metadata due to the
> + the provided maintenance_event type. MaintenanceEvents will be
> + something like boot, configchange, device_add, device_remove etc.
> + """
> + if bool(maintenance_event & self.network_maintenance_mask):
> + LOG.debug(
> + "Re-crawling datasource metadata due to maintenance event: '%s'",
> + MAINTENANCE_EVENT_STR.get(maintenance_event, maintenance_event))
we probably should never hit the default value here... our maintenance event should always be in MAINTENANCE_EVENT_STR.
> + result = self.get_data(clear_cache=True)
> + if result:
> + return True
> + else:
> + LOG.warning(
> + 'Re-crawling metadata reported invalid datasource type')
> + return False
> +
> def check_instance_id(self, sys_cfg):
> # quickly (local check only) if self.instance_id is still
> return False
--
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/348000
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:feature/maintain-network-on-boot into cloud-init:master.
Follow ups
References