Exemplo n.º 1
0
def create_image(auth_info, data):
    ret = None
    glance = glancebase.get_glance(fun_name(), auth_info)

    exist_img = [
        img for img in glance.images.list() if img.name == data["image_name"]
    ]
    if exist_img:
        ret = [
            0, {
                "id": exist_img[0].id,
                "name": data["image_name"],
                const.RES_TYPE_KEY: const.RES_TYPE_EXIST
            }
        ]
    else:
        img = glance.images.create(name=data["image_name"],
                                   disk_format=data["image_type"],
                                   visibility='public',
                                   container_format='bare')
        ret = [
            0, {
                "id": img.id,
                "name": data["image_name"],
                const.RES_TYPE_KEY: const.RES_TYPE_NEW
            }
        ]
        try:
            ImageUploadThread(glance, img.id, data["image_path"]).start()
        except:
            logger.error(traceback.format_exc())
            logger.error(str(sys.exc_info()))
    return ret
Exemplo n.º 2
0
def delete_image(auth_info, image_id):
    from glanceclient.exc import HTTPNotFound
    glance = glancebase.get_glance(fun_name(), auth_info)
    try:
        glance.images.delete(image_id)
    except HTTPNotFound:
        logger.warn("Exception: %s" % str(sys.exc_info()))
        return [0, "Image(%s) does not exist" % image_id]
    return [0, "Image(%s) has been deleted" % image_id]
Exemplo n.º 3
0
def get_image(auth_info, image_id):
    from glanceclient.exc import HTTPNotFound
    glance = glancebase.get_glance(fun_name(), auth_info)
    img = None
    try:
        img = glance.images.get(image_id)
    except HTTPNotFound:
        logger.warn("Exception: %s" % str(sys.exc_info()))
        return [2, "Image(%s) does not exist" % image_id]
    ret_img_info = get_single_image(img)
    if 'status' in ret_img_info and 'deleted' == ret_img_info["status"]:
        return [2, "Image(%s) is deleted" % image_id]
    return [0, ret_img_info]
Exemplo n.º 4
0
def get_images(auth_info):
    glance = glancebase.get_glance(fun_name(), auth_info)
    imgs = glance.images.list()
    return [0, {"image_list": [get_single_image(img) for img in imgs]}]