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
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1855616

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

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

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to