I'll have to double check on UEC images and whether cloud-init is
included in those image types, but we should be able to depend on the
following function that that is the case:

def add_cloud_info(report):
    # EC2 and Ubuntu Enterprise Cloud instances
    try:
     instance_data = json.loads(
        subprocess.check_output(['cloud-init', 'query', '--all']).decode())
    except subprocess.CalledProcessError as e:
        return
    report = {}
    if instance_data.get('platform') == 'ec2':
        ami = instance_data.get('ds', {}).get('meta_data', {}).get('ami_id')
        if ami and ami.startswith('ami'):
            report['Ec2AMI'] = ami
            fields = {
                'Ec2AMIManifest': 'ds.meta_data.ami_manifest_path',
                'Ec2Kernel': 'ds.dynamic.instance_identity.document.kernelId',
                'Ec2Ramdisk':
                    'ds.dynamic.instance_identity.document.ramdiskId',
                'Ec2InstanceType': 'ds.meta_data.instance_type',
                'Ec2AvailabilityZone': 'availability_zone'}
            for key, path in fields.items():
                value = instance_data
                for path_part in path.split('.'):
                    value = value.get(path_part)
                    if not value:
                        break
                report[key] = value if value else 'unavailable'
        else:
            add_tag(report, 'uec-images')

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1855616

Title:
  apport tries to hit ec2 metadata service if cloud-init is installed

Status in apport package in Ubuntu:
  New

Bug description:
  This probably made sense in 2012 but in focal all servers are going to
  have cloud-init installed. I *think* apport should consult "< /run
  /cloud-init/instance-data.json jq .v1.platform" but someone from
  server should probably check that.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1855616/+subscriptions

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to