<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def check_glance(session, image_name):
 """Check that the base image is available. Fails if the base image isn't added. This means the image should be added manually. """

    gclient = glance.Client(GLANCE_VERSION, session=session,
                            region_name=os.environ['OS_REGION_NAME'])
    images = gclient.images.list()
    name_ids = [{'name': i['name'], 'id': i['id']} for i in images]
    if image_name not in list(map(itemgetter('name'), name_ids)):
        logger.error("[glance]: Image %s is missing" % image_name)
        raise Exception("Image %s is missing" % image_name)
    else:
        image = [i for i in name_ids if i['name'] == image_name]
        image_id = image[0]['id']
        logger.info("[glance]: Using image %s:%s" % (image_name, image_id))
    return image_id