(name, image_file_path)
:param name: name of the image to be uploaded
    :param image_file_path: full filesystem path as string to the image
    :return: json encoded results string from glance REST api
def upload_image_to_glance_old(name, image_file_path):
    """

    :param name: name of the image to be uploaded
    :param image_file_path: full filesystem path as string to the image
    :return: json encoded results string from glance REST api
    """
    logger.debug("--- upload_image_to_glance ---")

    url = create_glance_url('/images')

    try:
        f = open(image_file_path, 'rb')
        fio = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)

        request = urllib2.Request(url, fio)
        request.add_header("X-Auth-Token", _auth_token)
        request.add_header("Content-Type", "application/octet-stream")
        request.add_header("x-image-meta-name", name)
        request.add_header("x-image-meta-disk_format", "qcow2")
        request.add_header("x-image-meta-container_format", "bare")
        request.add_header("x-image-meta-is_public", "true")
        request.add_header("x-image-meta-min_ram", "1024")
        request.add_header("x-image-meta-min_disk", "1")
        result = urllib2.urlopen(request)
        return result.read()
    except Exception as e:
        logger.error("Could not upload image to glance")
        logger.error("error was %s" % str(e))

    finally:
        fio.close()
        f.close()
        return None
def upload_image_to_glance_old ( name , image_file_path ) : logger . debug ( "--- upload_image_to_glance ---" ) url = create_glance_url ( '/images' ) try : f = open ( image_file_path , 'rb' ) fio = mmap . mmap ( f . fileno ( ) , 0 , access = mmap . ACCESS_READ ) request = urllib2 . Request ( url , fio ) request . add_header ( "X-Auth-Token" , _auth_token ) request . add_header ( "Content-Type" , "application/octet-stream" ) request . add_header ( "x-image-meta-name" , name ) request . add_header ( "x-image-meta-disk_format" , "qcow2" ) request . add_header ( "x-image-meta-container_format" , "bare" ) request . add_header ( "x-image-meta-is_public" , "true" ) request . add_header ( "x-image-meta-min_ram" , "1024" ) request . add_header ( "x-image-meta-min_disk" , "1" ) result = urllib2 . urlopen ( request ) return result . read ( ) except Exception as e : logger . error ( "Could not upload image to glance" ) logger . error ( "error was %s" % str ( e ) ) finally : fio . close ( ) f . close ( ) return None