← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~chad.smith/cloud-init:feature/maintain-network-on-boot into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
> index 90d7457..302cd59 100644
> --- a/cloudinit/sources/__init__.py
> +++ b/cloudinit/sources/__init__.py
> @@ -102,6 +103,22 @@ class DataSource(object):
>      url_timeout = 10    # timeout for each metadata url read attempt
>      url_retries = 5     # number of times to retry url upon 404
>  
> +    # The datasource defines a list of supported EventTypes for
> +    # which network_configuration is regenerated.

updated comment here to reflect reality a bit more as it's really just a filter for the datasource to determine whether it will allow it's metadata to get updated or not.

> +    # A datasource which supports writing network config on each system boot
> +    # would set network_maintenance_events = [EventType.BOOT].
> +
> +    # Default: generate network config on new instance id (first boot).
> +    network_maintenance_events = [EventType.BOOT_NEW_INSTANCE]
> +
> +    # N-tuple listing default values for any metadata-related class
> +    # attributes cached on an instance by a get_data runs. These attribute
> +    # values are reset via clear_cached_data during any of the supported
> +    # network_maintenance_events.
> +    cached_attr_defaults = (
> +        ('userdata', None), ('metadata', {}), ('userdata_raw', None),
> +        ('vendordata', None), ('vendordata_raw', None))
> +
>      def __init__(self, sys_cfg, distro, paths, ud_proc=None):
>          self.sys_cfg = sys_cfg
>          self.distro = distro
> @@ -416,6 +439,34 @@ class DataSource(object):
>      def get_package_mirror_info(self):
>          return self.distro.get_package_mirror_info(data_source=self)
>  
> +    def update_metadata(self, source_event_types):
> +        """Refresh cached metadata if the datasource supports this event.
> +
> +        The datasource has a list of network_maintenance_events which
> +        trigger refreshing all cached metadata.
> +
> +        @param source_event_types: List of EventTypes  which may trigger a
> +            metadata update.
> +
> +        @return True if the datasource did successfully update cached metadata
> +            due to source_event_type.
> +        """
> +        supported_events = [
> +            evt for evt in source_event_types
> +            if evt in self.network_maintenance_events]

This branch is providing a mechanism that a datasource can limit updates to cached metadata to only certain events. Under unsupported events, it will no-op and return False indicating that no metadata-update occurred. It is then to responsibility of the callers of datasource.update_metadata to check whether or not it resulted in a delta and to consume any updated-metadata.  Since different datasources may have unique conditions permit/deny metadata updates presented by metadata values, it felt best to encapsulate that logic here within the datasource instead of putting that burder on other call-sites. 

I imagined that a branch following this one will:
   1, compare newly crawled metadata versus the cache for deltas
   2. only clear_cached_data and return True if deltas and event_type in self.network_maintenance_events

> +        if supported_events:
> +            LOG.debug(
> +                "Update datasource metadata due to maintenance events: '%s'",
> +                ','.join(supported_events))
> +            result = self.clear_cached_data()
> +            result = self.get_data()
> +            if result:
> +                return True
> +            else:
> +                LOG.warning(
> +                    'Update metadata encountered 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.


References