def _format_image(context, image, os_image, images_dict, ids_dict, snapshot_ids=None): ec2_image = { 'imageId': image['id'], 'imageOwnerId': os_image.owner, 'imageType': IMAGE_TYPES[ec2utils.get_ec2_id_kind(image['id'])], 'isPublic': os_image.is_public, 'architecture': os_image.properties.get('architecture'), 'creationDate': os_image.created_at } if 'description' in image: ec2_image['description'] = image['description'] if 'state' in image: state = image['state'] else: state = GLANCE_STATUS_TO_EC2.get(os_image.status, 'error') if state in ('available', 'pending'): state = _s3_image_state_map.get(os_image.properties.get('image_state'), state) ec2_image['imageState'] = state kernel_id = os_image.properties.get('kernel_id') if kernel_id: ec2_image['kernelId'] = ec2utils.os_id_to_ec2_id( context, 'aki', kernel_id, items_by_os_id=images_dict, ids_by_os_id=ids_dict) ramdisk_id = os_image.properties.get('ramdisk_id') if ramdisk_id: ec2_image['ramdiskId'] = ec2utils.os_id_to_ec2_id( context, 'ari', ramdisk_id, items_by_os_id=images_dict, ids_by_os_id=ids_dict) name = os_image.name img_loc = os_image.properties.get('image_location') if img_loc: ec2_image['imageLocation'] = img_loc else: ec2_image['imageLocation'] = "%s (%s)" % (img_loc, name) if not name and img_loc: # This should only occur for images registered with ec2 api # prior to that api populating the glance name ec2_image['name'] = img_loc else: ec2_image['name'] = name properties = ec2utils.deserialize_os_image_properties(os_image) root_device_name = ( ec2utils.block_device_properties_root_device_name(properties)) mappings = _format_mappings(context, properties, root_device_name, snapshot_ids, os_image.owner) if mappings: ec2_image['blockDeviceMapping'] = mappings root_device_type = 'instance-store' if root_device_name: ec2_image['rootDeviceName'] = root_device_name short_root_device_name = ec2utils.block_device_strip_dev( root_device_name) if any((short_root_device_name == ec2utils.block_device_strip_dev( bdm.get('deviceName'))) for bdm in mappings): root_device_type = 'ebs' ec2_image['rootDeviceType'] = root_device_type return ec2_image
def _root_device_name_attribute(os_image, image, result): properties = ec2utils.deserialize_os_image_properties(os_image) result['rootDeviceName'] = ( ec2utils.block_device_properties_root_device_name(properties))
def _block_device_mapping_attribute(os_image, image, result): properties = ec2utils.deserialize_os_image_properties(os_image) mappings = _format_mappings(context, properties) if mappings: result['blockDeviceMapping'] = mappings
def _format_image(context, image, os_image, images_dict, ids_dict, snapshot_ids=None): ec2_image = {'imageId': image['id'], 'imageOwnerId': os_image.owner, 'imageType': IMAGE_TYPES[ ec2utils.get_ec2_id_kind(image['id'])], 'isPublic': os_image.is_public, 'architecture': os_image.properties.get('architecture'), 'creationDate': os_image.created_at } if 'description' in image: ec2_image['description'] = image['description'] if 'state' in image: state = image['state'] else: state = GLANCE_STATUS_TO_EC2.get(os_image.status, 'error') if state in ('available', 'pending'): state = _s3_image_state_map.get(os_image.properties.get('image_state'), state) ec2_image['imageState'] = state kernel_id = os_image.properties.get('kernel_id') if kernel_id: ec2_image['kernelId'] = ec2utils.os_id_to_ec2_id( context, 'aki', kernel_id, items_by_os_id=images_dict, ids_by_os_id=ids_dict) ramdisk_id = os_image.properties.get('ramdisk_id') if ramdisk_id: ec2_image['ramdiskId'] = ec2utils.os_id_to_ec2_id( context, 'ari', ramdisk_id, items_by_os_id=images_dict, ids_by_os_id=ids_dict) name = os_image.name img_loc = os_image.properties.get('image_location') if img_loc: ec2_image['imageLocation'] = img_loc else: ec2_image['imageLocation'] = "%s (%s)" % (img_loc, name) if not name and img_loc: # This should only occur for images registered with ec2 api # prior to that api populating the glance name ec2_image['name'] = img_loc else: ec2_image['name'] = name properties = ec2utils.deserialize_os_image_properties(os_image) root_device_name = ( ec2utils.block_device_properties_root_device_name(properties)) mappings = _format_mappings(context, properties, root_device_name, snapshot_ids, os_image.owner) if mappings: ec2_image['blockDeviceMapping'] = mappings root_device_type = 'instance-store' if root_device_name: ec2_image['rootDeviceName'] = root_device_name short_root_device_name = ec2utils.block_device_strip_dev( root_device_name) if any((short_root_device_name == ec2utils.block_device_strip_dev(bdm.get('deviceName'))) for bdm in mappings): root_device_type = 'ebs' ec2_image['rootDeviceType'] = root_device_type return ec2_image