← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~chad.smith/cloud-init:cleanup/metadata-cloud-platform into cloud-init:master

 

if manual_cache_clean is set, then we should be careful not to re-crawl anything on upgrade.  This is most likely a case when there was a "config disk" in the generic sense.  Ie, where a datasource provided a disk (cdrom or block device) and then later pulled it or user formatted it.

Diff comments:

> diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
> index 968ab3f..28f08e4 100644
> --- a/cloudinit/sources/DataSourceEc2.py
> +++ b/cloudinit/sources/DataSourceEc2.py
> @@ -306,13 +303,11 @@ class DataSourceEc2(sources.DataSource):
>          result = None
>          no_network_metadata_on_aws = bool(
>              'network' not in self.metadata and
> -            self.cloud_platform == Platforms.AWS)
> +            self.cloud_name == CloudNames.AWS)
>          if no_network_metadata_on_aws:
>              LOG.debug("Metadata 'network' not present:"
>                        " Refreshing stale metadata from prior to upgrade.")
> -            util.log_time(
> -                logfunc=LOG.debug, msg='Re-crawl of metadata service',
> -                func=self._crawl_metadata)
> +            self.get_data()

any reason you dropped the time on that?
probably not important, but curious.

>  
>          # Limit network configuration to only the primary/fallback nic
>          iface = self.fallback_interface
> @@ -340,28 +335,32 @@ class DataSourceEc2(sources.DataSource):
>                  return super(DataSourceEc2, self).fallback_interface
>          return self._fallback_interface
>  
> -    def _crawl_metadata(self):
> +    def crawl_metadata(self):
>          """Crawl metadata service when available.
>  
> -        @returns: True on success, False otherwise.
> +        @returns: Dictionary of craweled metadata content containing the keys:

craweled -> crawled

> +          meta-data, user-data and dynamic.
>          """
>          if not self.wait_for_metadata_service():
> -            return False
> +            return {}
>          api_version = self.get_metadata_api_version()
> +        crawled_metadata = {}
>          try:
> -            self.userdata_raw = ec2.get_instance_userdata(
> +            crawled_metadata['user-data'] = ec2.get_instance_userdata(
>                  api_version, self.metadata_address)
> -            self.metadata = ec2.get_instance_metadata(
> +            crawled_metadata['meta-data'] = ec2.get_instance_metadata(
>                  api_version, self.metadata_address)
> -            if self.cloud_platform == Platforms.AWS:
> -                self.identity = ec2.get_instance_identity(
> -                    api_version, self.metadata_address).get('document', {})
> +            if self.cloud_name == CloudNames.AWS:
> +                identity = ec2.get_instance_identity(
> +                    api_version, self.metadata_address)
> +                crawled_metadata['dynamic'] = {'instance-identity': identity}
>          except Exception:
>              util.logexc(
>                  LOG, "Failed reading from metadata address %s",
>                  self.metadata_address)
> -            return False
> -        return True
> +            return {}
> +        crawled_metadata['_metadata_api_version'] = api_version
> +        return crawled_metadata
>  
>  
>  class DataSourceEc2Local(DataSourceEc2):
> diff --git a/doc/rtd/topics/instancedata.rst b/doc/rtd/topics/instancedata.rst
> index 634e180..9c30bc1 100644
> --- a/doc/rtd/topics/instancedata.rst
> +++ b/doc/rtd/topics/instancedata.rst
> @@ -90,24 +90,39 @@ There are three basic top-level keys:
>  
>  The standardized keys present:
>  
> -+----------------------+-----------------------------------------------+---------------------------+
> -|  Key path            | Description                                   | Examples                  |
> -+======================+===============================================+===========================+
> -| v1.cloud_name        | The name of the cloud provided by metadata    | aws, openstack, azure,    |
> -|                      | key 'cloud-name' or the cloud-init datasource | configdrive, nocloud,     |
> -|                      | name which was discovered.                    | ovf, etc.                 |
> -+----------------------+-----------------------------------------------+---------------------------+
> -| v1.instance_id       | Unique instance_id allocated by the cloud     | i-<somehash>              |
> -+----------------------+-----------------------------------------------+---------------------------+
> -| v1.local_hostname    | The internal or local hostname of the system  | ip-10-41-41-70,           |
> -|                      |                                               | <user-provided-hostname>  |
> -+----------------------+-----------------------------------------------+---------------------------+
> -| v1.region            | The physical region/datacenter in which the   | us-east-2                 |
> -|                      | instance is deployed                          |                           |
> -+----------------------+-----------------------------------------------+---------------------------+
> -| v1.availability_zone | The physical availability zone in which the   | us-east-2b, nova, null    |
> -|                      | instance is deployed                          |                           |
> -+----------------------+-----------------------------------------------+---------------------------+
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +|  Key path            | Description                                   | Examples                          |
> ++======================+===============================================+===================================+
> +| v1._beta_keys        | List of standardized keys still in 'beta'.    | [subplatform]                     |
> +|                      | The format, intent or presence of these keys  |                                   |
> +|                      | can change considering them production-ready. |                                   |

odd english?

The format, intent or presense of these keys can change.
Do not consider them production-ready.

> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.cloud_name        | The name of the cloud provided by metadata    | aws, openstack, azure,            |
> +|                      | key 'cloud-name' or the cloud-init datasource | configdrive, nocloud,             |
> +|                      | name which was discovered.                    | ovf, etc.                         |

Where possible this will indicate the 'name' of the cloud this
system is running on.  This is specifically different than the 'platform'
below.  As an example, the name of Amazon Web Services is 'aws' while
the platform is 'ec2'.

If no specific name is determinable or provided in meta-data, then
this field may contain the same content as 'platform'.

> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.instance_id       | Unique instance_id allocated by the cloud     | i-<somehash>                      |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.local_hostname    | The internal or local hostname of the system  | ip-10-41-41-70,                   |
> +|                      |                                               | <user-provided-hostname>          |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.platform          | An attempt to identify the cloud platform     | ec2, openstack, lxd, gce          |
> +|                      | instance that the system is running on.       | nocloud, ovf                      |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.subplatform       | Additional platform details describing the    | metadata (http://168.254.169.254),|
> +|                      | specific source or type of metadata used.     | seed-dir (/path/to/seed-dir/),    |
> +|                      | The format of subplatform will be:            | config-disk (/dev/cd0),           |
> +|                      | <subplatform_type> (<url_file_or_dev_path>)   | configdrive (/dev/sr0)            |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.public_ssh_keys   | A list of  ssh keys provided to the instance  | ['ssh-rsa AA...', ...]            |
> +|                      | by the datasource metadata.                   |                                   |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.region            | The physical region/datacenter in which the   | us-east-2                         |
> +|                      | instance is deployed                          |                                   |
> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| v1.availability_zone | The physical availability zone in which the   | us-east-2b, nova, null            |
> +|                      | instance is deployed                          |                                   |
> ++----------------------+-----------------------------------------------+-----------------------------------+
>  
>  
>  Below is an example of ``/run/cloud-init/instance_data.json`` on an EC2


-- 
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/355999
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:cleanup/metadata-cloud-platform into cloud-init:master.


References