← 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

 


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()

ahh good point. Originally since Ec2, _get_data already did a time wrapper around crawl_metadata inside _get_data. So, I didn't want the double wrapped timer, but there is a path potentially where we would also need to perform sendboxed dhcp before crawl_metadata, so it'd be nice to see timestamps around that effort as well as the crawl_metadata so I'll put it back in. Also discovered a path where we didn't log_time of crawl_metadata if no-network sandbox was required so I added that too.

>  
>          # 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:

fixed.

> +          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. |                                   |

thanks

> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| 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.                         |

thanks again.

> ++----------------------+-----------------------------------------------+-----------------------------------+
> +| 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