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')
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) :
subprocess. check_output( ['cloud- init', 'query', '--all']).decode()) CalledProcessEr ror as e: data.get( 'platform' ) == 'ec2': data.get( 'ds', {}).get( 'meta_data' , {}).get('ami_id') 'ami'):
report[ 'Ec2AMI' ] = ami
'Ec2AMIManife st': 'ds.meta_ data.ami_ manifest_ path',
'Ec2Kernel' : 'ds.dynamic. instance_ identity. document. kernelId' ,
'Ec2Ramdisk' :
' ds.dynamic. instance_ identity. document. ramdiskId' ,
'Ec2InstanceT ype': 'ds.meta_ data.instance_ type',
'Ec2Availabil ityZone' : 'availability_ zone'}
value = instance_data
value = value.get( path_part)
if not value:
break
report[ key] = value if value else 'unavailable'
add_ tag(report, 'uec-images')
# EC2 and Ubuntu Enterprise Cloud instances
try:
instance_data = json.loads(
except subprocess.
return
report = {}
if instance_
ami = instance_
if ami and ami.startswith(
fields = {
for key, path in fields.items():
for path_part in path.split('.'):
else: