← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~smoser/cloud-init:feature/ec2-ds-warn into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
> index c657fd0..cbcb61c 100644
> --- a/cloudinit/sources/DataSourceEc2.py
> +++ b/cloudinit/sources/DataSourceEc2.py
> @@ -22,6 +22,69 @@ LOG = logging.getLogger(__name__)
>  # Which version we are requesting of the ec2 metadata apis
>  DEF_MD_VERSION = '2009-04-04'
>  
> +LOOKALIKE_BEHAVIOR = 'skip'
> +LOOKALIKE_WARNING = """\
> +************************************************************************
> +This system is using the EC2 Metadata Service, but does not appear to be
> +running on Amazon EC2.  At a date yet to be determined, cloud-init will
> +stop reading metadata from the EC2 Metadata service unless the platform
> +can be identified.
> +
> +If you are seeing this message, please file a bug against cloud-init
> +at https://bugs.launchpad.net/cloud-init/+filebug .  Make sure to
> +include the cloud provider your instance is running on.
> +
> +After you have filed a bug, you can disable this warning by launching an
> +instance with the cloud-config below, or putting that content into
> +/etc/cloud/cloud.cfg.d/99-ec2-lookalike.cfg.
> +
> + #cloud-config
> + datasource:
> +  Ec2:
> +   look_alike:
> +    behavior: accept
> +
> +************************************************************************
> +"""
> +
> +
> +class _PoorMansEnum(object):
> +    """A thing with enum like behavior, here to avoid dependency on enum
> +       which is not present in python 2.x standard library."""
> +    def __init__(self, **kwargs):
> +        for (k, v) in kwargs.items():
> +            setattr(self, k, v)
> +        self._keys = tuple(sorted([k for k in kwargs.keys()]))
> +        self._values = tuple([kwargs[k] for k in self._keys])
> +
> +    def __contains__(self, k):
> +        return k in self._values
> +
> +    def keys(self):
> +        return self._keys
> +
> +    def values(self):
> +        return self._values
> +
> +    def dict(self):
> +        return dict(zip(self.keys(), self.values()))
> +
> +    def __str__(self):
> +        return str(self.dict())
> +
> +
> +Platforms = _PoorMansEnum(
> +    ALIYUN="AliYun",
> +    GENUINE_AWS="GenuineAWS",
> +    UNKNOWN="Unknown",
> +)

This seems unnecessarily clever.  Why not just:

  class Platforms:
    ALIYUN = 1
    GENUINE_AWS = 2
    UNKNOWN = 3

Then you can still do things like:

  return EC2.Platforms.ALIYUN

Or:

  if self.cloud_platform == Platforms.UNKNOWN

> +
> +LOOKALIKE_DEFAULT = {
> +    'behavior': 'skip',
> +    'platform': Platforms.UNKNOWN,
> +    'sleep': 10,
> +}
> +
>  
>  class DataSourceEc2(sources.DataSource):
>      # Default metadata urls that will be used if none are provided


-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/316033
Your team cloud init development team is requested to review the proposed merge of ~smoser/cloud-init:feature/ec2-ds-warn into cloud-init:master.


Follow ups

References