← 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

 

document beta_keys somwhere ?


Diff comments:

> diff --git a/cloudinit/sources/DataSourceAliYun.py b/cloudinit/sources/DataSourceAliYun.py
> index 858e082..16abd09 100644
> --- a/cloudinit/sources/DataSourceAliYun.py
> +++ b/cloudinit/sources/DataSourceAliYun.py
> @@ -18,25 +18,17 @@ class DataSourceAliYun(EC2.DataSourceEc2):
>      min_metadata_version = '2016-01-01'
>      extended_metadata_versions = []
>  
> -    def __init__(self, sys_cfg, distro, paths):
> -        super(DataSourceAliYun, self).__init__(sys_cfg, distro, paths)
> -        self.seed_dir = os.path.join(paths.seed_dir, "AliYun")
> -
>      def get_hostname(self, fqdn=False, resolve_ip=False, metadata_only=False):
>          return self.metadata.get('hostname', 'localhost.localdomain')
>  
>      def get_public_ssh_keys(self):
>          return parse_public_keys(self.metadata.get('public-keys', {}))
>  
> -    @property
> -    def cloud_platform(self):
> -        if self._cloud_platform is None:
> -            if _is_aliyun():
> -                self._cloud_platform = EC2.Platforms.ALIYUN
> -            else:
> -                self._cloud_platform = EC2.Platforms.NO_EC2_METADATA
> -
> -        return self._cloud_platform
> +    def _get_cloud_name(self):
> +        if _is_aliyun():

you dropped the caching of _cloud_platform. was that intended ?

> +            return EC2.CloudNames.ALIYUN
> +        else:
> +            return EC2.CloudNames.NO_EC2_METADATA
>  
>  
>  def _is_aliyun():
> diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py
> index 8cd312d..5270fda 100644
> --- a/cloudinit/sources/DataSourceAltCloud.py
> +++ b/cloudinit/sources/DataSourceAltCloud.py
> @@ -99,7 +101,14 @@ class DataSourceAltCloud(sources.DataSource):
>              'RHEV', 'VSPHERE' or 'UNKNOWN'
>  
>          '''
> -
> +        if os.path.exists(CLOUD_INFO_FILE):

these changes are hard... as can't test this anywhere.
I think at one poitn ovirt was using this, but I think it might be completely gone from current use (ie, we could/should drop).

not sure how to figure that out.

> +            try:
> +                cloud_type = util.load_file(CLOUD_INFO_FILE).strip().upper()
> +            except IOError:
> +                util.logexc(LOG, 'Unable to access cloud info file at %s.',
> +                            CLOUD_INFO_FILE)
> +                return 'UNKNOWN'
> +            return cloud_type
>          system_name = util.read_dmi_data("system-product-name")
>          if not system_name:
>              return 'UNKNOWN'
> diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
> index 783445e..39391d0 100644
> --- a/cloudinit/sources/DataSourceAzure.py
> +++ b/cloudinit/sources/DataSourceAzure.py
> @@ -351,6 +351,14 @@ class DataSourceAzure(sources.DataSource):
>          metadata['public-keys'] = key_value or pubkeys_from_crt_files(fp_files)
>          return metadata
>  
> +    def _get_subplatform(self):
> +        """Return the subplatform metadata source details."""
> +        if self.seed.startswith('/dev'):
> +            subplatform_type = 'config-disk'
> +        else:
> +            subplatform_type = 'seed-dir'

in reality this willi always say 'config-disk'  now.
right?

> +        return '%s (%s)' % (subplatform_type, self.seed)
> +
>      def crawl_metadata(self):
>          """Walk all instance metadata sources returning a dict on success.
>  
> diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
> index 968ab3f..618714b 100644
> --- a/cloudinit/sources/DataSourceEc2.py
> +++ b/cloudinit/sources/DataSourceEc2.py
> @@ -28,18 +28,16 @@ STRICT_ID_PATH = ("datasource", "Ec2", "strict_id")
>  STRICT_ID_DEFAULT = "warn"
>  
>  
> -class Platforms(object):
> -    # TODO Rename and move to cloudinit.cloud.CloudNames
> -    ALIYUN = "AliYun"
> -    AWS = "AWS"
> -    BRIGHTBOX = "Brightbox"
> -    SEEDED = "Seeded"

I'm wondering about 'aliyun' and 'brightbox' as platforms (and as cloudnames).

they're *not* ec2 api clones (just the metadata service portion). at least brightbox is not.

dont worry too much about this.

> +class CloudNames(object):
> +    ALIYUN = "aliyun"
> +    AWS = "aws"
> +    BRIGHTBOX = "brightbox"
>      # UNKNOWN indicates no positive id.  If strict_id is 'warn' or 'false',
>      # then an attempt at the Ec2 Metadata service will be made.
> -    UNKNOWN = "Unknown"
> +    UNKNOWN = "unknown"
>      # NO_EC2_METADATA indicates this platform does not have a Ec2 metadata
>      # service available. No attempt at the Ec2 Metadata service will be made.
> -    NO_EC2_METADATA = "No-EC2-Metadata"
> +    NO_EC2_METADATA = "no-ec2-metadata"
>  
>  
>  class DataSourceEc2(sources.DataSource):
> diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
> index 178ccb0..045291e 100644
> --- a/cloudinit/sources/DataSourceOVF.py
> +++ b/cloudinit/sources/DataSourceOVF.py
> @@ -275,6 +275,12 @@ class DataSourceOVF(sources.DataSource):
>          self.cfg = cfg
>          return True
>  
> +    def _get_subplatform(self):
> +        system_type = util.read_dmi_data("system-product-name").lower()
> +        if system_type == 'vmware':

more useful here is whether or not we used the vmware customization (self._vmware_cust_found).

on vmware we may or may not end up  using the vmware customization path.
on non-vmware we're almost certainly in the OVF disk path.

> +            return 'vmware (%s)' % self.seed
> +        return 'ovf (%s)' % self.seed
> +
>      def get_public_ssh_keys(self):
>          if 'public-keys' not in self.metadata:
>              return []
> diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py
> index 77ccd12..f8df36b 100644
> --- a/cloudinit/sources/DataSourceOpenNebula.py
> +++ b/cloudinit/sources/DataSourceOpenNebula.py
> @@ -95,6 +95,14 @@ class DataSourceOpenNebula(sources.DataSource):
>          self.userdata_raw = results.get('userdata')
>          return True
>  
> +    def _get_subplatform(self):
> +        """Return the subplatform metadata source details."""
> +        if self.seed_dir in self.seed:
> +            subplatform_type =  'seed-dir'

a separate mp should go through and riip out seed_dirs

> +        else:
> +            subplatform_type =  'config-disk'
> +        return '%s (%s)' % (subplatform_type, self.seed)
> +
>      @property
>      def network_config(self):
>          if self.network is not None:
> diff --git a/cloudinit/util.py b/cloudinit/util.py
> index 5068096..948cfe5 100644
> --- a/cloudinit/util.py
> +++ b/cloudinit/util.py
> @@ -2171,6 +2171,23 @@ def is_container():
>      return False
>  
>  
> +def is_lxd():
> +    """Check to see if we are running in a lxd container."""
> +    if os.path.exists('/dev/lxd/sock'):
> +        return True
> +    for container_file in ['/run/systemd/container', '/run/container_type']:
> +        if os.path.exists(container_file):

lxc is not lxd..
i'm fine to only consider lxd if /dev/lxd exists.

iti will exist everywhere.

where did you get these files ?

i think basically just make 'is_lxd' be:
  if os.path.exists("/dev/lxd/sock")

> +            if 'lxc' == load_file(container_file, decode=False):
> +                return True
> +    try:
> +        (virt_type, _err) = subp(['systemd-detect-virt'])
> +    except (IOError, OSError):
> +        return False
> +    if virt_type == 'lxc':
> +        return True
> +    return False
> +
> +
>  def get_proc_env(pid, encoding='utf-8', errors='replace'):
>      """
>      Return the environment in a dict that a given process id was started with.
> diff --git a/doc/rtd/topics/instancedata.rst b/doc/rtd/topics/instancedata.rst
> index 634e180..c1eed2e 100644
> --- a/doc/rtd/topics/instancedata.rst
> +++ b/doc/rtd/topics/instancedata.rst
> @@ -102,6 +102,12 @@ The standardized keys present:
>  | v1.local_hostname    | The internal or local hostname of the system  | ip-10-41-41-70,           |
>  |                      |                                               | <user-provided-hostname>  |
>  +----------------------+-----------------------------------------------+---------------------------+
> +| v1.platform_type     | The cloud platform or metadata api type       | ec2, openstack, seed-dir  |

platform, right? not platform_type.

i put some text in about 'cloud_name' at https://hackmd.io/EdCObZthR_O3u9Zcr5L3SA

This is an attempt to identify the specific cloud platform
instance that the system is running on. For example a system
running on Amazon Web Services will have cloud_name=‘aws’ and
platform_type=‘ec2’.

If a specific name is not provided by the platform or cannot
be obtained, then the platform_type will be used.

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


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