示例#1
0
def image_checkout():
    eimage_name = request.values.get('image_name')
    if not eimage_name:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    # 判断当前image状态是否正常
    image_manage_data = im_s.ImageManageService().get_img_manage_data_by_name(eimage_name)
    os_type = image_manage_data[1]["os_type"]
    image_manage_stat = image_manage_data[1]["status"]
    if image_manage_stat != ImageManage.EDITING:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='当前模板机状态不允许此操作')

    # template vm remove ip
    update_action = im_m_act.IP_REMOVE
    ret, message = im_man_act.img_tem_rm_ip(eimage_name, os_type)
    if not ret:
        state_tag = im_m_act_sta.FAILED
        im_s.ImageStatusService().add_image_status_action(eimage_name, update_action, state_tag, message)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)
    else:
        state_tag = im_m_act_sta.SUCCESSED
        im_s.ImageStatusService().add_image_status_action(eimage_name, update_action, state_tag, message)

    # template vm shutdown
    update_action = im_m_act.VEM_SHUTDOWN
    ret, message = im_man_act._img_tem_shutdown(eimage_name)
    if not ret:
        state_tag = im_m_act_sta.FAILED
        im_s.ImageStatusService().add_image_status_action(eimage_name, update_action, state_tag, message)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)
    else:
        state_tag = im_m_act_sta.SUCCESSED
        im_s.ImageStatusService().add_image_status_action(eimage_name, update_action, state_tag, message)

    # 更新template vm状态为关机
    update_data = {
        'template_status': img_tmp_status.SHUTDOWN
    }
    where_data = {
        'eimage_name': eimage_name
    }
    im_s.ImageManageService().update_image_info(update_data, where_data)

    # 更新template_status
    message = ''
    im_s.ImageManageService().update_image_manage_status(eimage_name, message, ImageManage.CHECKOUT)
    message = '模板机%s 生成模板成功' % eimage_name
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS, msg=message)
def image_manage_list():
    params = {
        'ORDER': [
            ['id', 'desc'],
        ],
        'PAGINATION': {
            'page_size': request.values.get('page_size', 20),
            'page_no': request.values.get('page_no', 1),
        }
    }

    total_nums, data = image_service.ImageManageService().query_data(**params)
    resp = ImageListResp()
    resp.total = total_nums
    for i in data:
        _image_info = image_manage_info.ImageManagerInfo().init_from_db(i)
        resp.rows.append(_image_info)
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS, data=resp.to_json())
示例#3
0
def image_edit():
    eimage_name = request.values.get('image_name')
    if not eimage_name:
        # message =  {
        #     'code': ErrorCode.SYS_ERR,
        #     'msg': "入参缺失"
        # }
        # socketio.emit('image_edit_resp', message, namespace='/image_edit_return')
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    # 判断当前image状态是否正常
    image_manage_data = im_s.ImageManageService().get_img_manage_data_by_name(
        eimage_name)
    image_manage_stat = image_manage_data[1]["status"]
    image_manage_type = image_manage_data[1]["os_type"]
    image_manage_osver = image_manage_data[1]["version"]
    enable_stat = [ImageManage.INIT, ImageManage.CHECKOUT, ImageManage.USABLE]
    if image_manage_stat not in enable_stat:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='当前模板机状态不允许此操作')

    # template vm start
    ret, message = im_man_act._img_tem_start(eimage_name)
    update_action = im_m_act.START_VEM
    if not ret:
        state_tag = im_m_act_sta.FAILED
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, message)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)
    else:
        state_tag = im_m_act_sta.SUCCESSED
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, message)

    # update template vm stat
    update_data = {'template_status': img_tmp_status.RUNNING}
    where_data = {'eimage_name': eimage_name}
    im_s.ImageManageService().update_image_info(update_data, where_data)

    # template vm inject ip
    ret, res_data = im_s.ImageManageService().get_img_manage_data_by_name(
        eimage_name)
    update_action = im_m_act.IP_INJECT
    if not ret:
        state_tag = im_m_act_sta.FAILED
        error_msg = res_data
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='获取镜像信息失败')
    ip_address = res_data['template_vm_ip']
    segment_data = segment_s.SegmentService().get_segment_for_img_tmp()
    if not segment_data:
        error_msg = '获取镜像模板专用网段失败'
        state_tag = im_m_act_sta.FAILED
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='获取镜像模板专用网段失败')
    netmask_int = int(segment_data['netmask'])
    netmask = exchange_maskint(netmask_int)
    gateway = segment_data['gateway_ip']
    dns1 = segment_data['dns1']
    dns2 = segment_data['dns2']
    res, message = im_man_act._img_tem_inject(eimage_name, ip_address, netmask,
                                              gateway, image_manage_type,
                                              image_manage_osver, dns1, dns2)
    update_action = im_m_act.IP_INJECT
    if not res:
        error_msg = message
        state_tag = im_m_act_sta.FAILED
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        im_s.ImageManageService().update_image_manage_msg(eimage_name, message)
        msg = '模板机%s 初始化注入失败' % eimage_name
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=msg)
    else:
        state_tag = im_m_act_sta.SUCCESSED
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, message)
    # 更新template_status
    message = ''
    im_s.ImageManageService().update_image_manage_status(
        eimage_name, message, ImageManage.EDITING)
    message = '模板机%s 开机编辑成功' % eimage_name
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS, msg=message)
示例#4
0
def image_release_by_new():
    name = request.values.get('name')
    displayname = request.values.get('displayname'),
    system = request.values.get('system'),
    version = request.values.get('version')
    image_manage_data = im_s.ImageManageService().get_img_manage_data_by_name(
        name)
    create_type = image_manage_data[1]['create_type']
    if not name or not displayname or not system or not version:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    # 判断当前image状态是否正常
    image_manage_stat = image_manage_data[1]["status"]
    if image_manage_stat != ImageManage.CHECKOUT:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='当前模板机状态不允许此操作')

    # 更新image_manage状态为发布中
    message = ''
    eimage_name = name
    im_s.ImageManageService().update_image_manage_status(
        eimage_name, message, ImageManage.RELEASING)
    image_info_list = image_disk_md5_together(name)

    # 获取镜像文件的list
    res, image_list_info = ansibleCmdV2.get_image_disk_list(
        IMAGE_EDIT_SERVER, eimage_name)
    update_action = im_m_act.RELEASE_IMGSERVER
    if not res:
        # 更新image_manage表和image_update_status
        error_msg = image_list_info
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    image_disk_list = list(image_list_info)

    # 更新镜像服务器
    ret, message = img_server_update_img(eimage_name, image_disk_list,
                                         create_type)
    if not ret:
        error_msg = message
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    # 如果为全新创建则跳过更新缓存服务器
    if create_type == image_ceate_type.ALL_NEW or create_type == image_ceate_type.FROM_EXIST:
        pass
    else:
        # 更新镜像缓存服务器
        ret, message = img_cache_server_update_img(eimage_name,
                                                   image_disk_list)
        update_action = im_m_act.RELEASE_CACHESERVER
        if not ret:
            error_msg = message
            state_tag = im_m_act_sta.FAILED
            im_s.ImageManageService().update_image_manage_status(
                eimage_name, error_msg, ImageManage.CHECKOUT)
            im_s.ImageStatusService().add_image_status_action(
                eimage_name, update_action, state_tag, error_msg)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=error_msg)
    # 更新db
    tag = randomUUID()
    # 如果类型为现有补录,则update image表
    if create_type == image_ceate_type.UPDATE_EXIST:
        for index, i in enumerate(image_info_list):
            if index == 0:
                url_i = ('/' + name) * 2
            else:
                url_i = ('/' + name) * 2 + '_disk' + str(index + 1)
            update_data = {
                'md5': i['md5'],
                'actual_size_mb': i['actual_size_mb'],
                'tag': tag,
                'updated_at': get_datetime_str(),
            }
            where_data = {
                'url': url_i,
            }
            ret = im_s.ImageService().update_image_info(
                update_data, where_data)
            if ret < 0:
                logging.error("release image error, update_data:%s",
                              str(update_data))
                error_msg = "发布镜像 %s 失败,更新image表信息失败", str(update_data)
                state_tag = im_m_act_sta.FAILED
                im_s.ImageManageService().update_image_manage_status(
                    eimage_name, error_msg, ImageManage.CHECKOUT)
                im_s.ImageStatusService().add_image_status_action(
                    eimage_name, update_action, state_tag, error_msg)
                return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                                   msg=error_msg)
    # 新建镜像则add image表记录
    else:
        for index, i in enumerate(image_info_list):
            if index == 0:
                url_i = ('/' + name) * 2
                # image_info_list中第一个数据是系统盘
                type = '0'
                description = u'系统盘'
                size_gb = get_image_size_gb(name, name)
            else:
                url_i = ('/' + name) * 2 + '_disk' + str(index + 1)
                name_i = name + '_disk' + str(index + 1)
                type = '1'
                description = u'数据盘'
                size_gb = get_image_size_gb(name, name_i)

            insert_data = {
                'name': name,
                'displayname': displayname,
                'system': system,
                'version': version,
                'description': description,
                'md5': i['md5'],
                'format': 'qcow2',
                'actual_size_mb': i['actual_size_mb'],
                'size_gb': size_gb,
                'isdeleted': '0',
                'created_at': get_datetime_str(),
                'url': url_i,
                'type': type,
                # todo;uuid
                'tag': tag,
            }
            ret = im_s.ImageService().add_image_info(insert_data)
            if ret.get('row_num') <= 0:
                logging.error("add image error, insert_data:%s",
                              str(insert_data))
                error_msg = "发布新镜像 %s 失败,更新image表失败" % eimage_name
                state_tag = im_m_act_sta.FAILED
                im_s.ImageManageService().update_image_manage_status(
                    eimage_name, error_msg, ImageManage.CHECKOUT)
                im_s.ImageStatusService().add_image_status_action(
                    eimage_name, update_action, state_tag, error_msg)
                return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                                   msg=error_msg)
    update_data = {'status': '0', 'create_type': image_ceate_type.USING}
    where_data = {'eimage_name': name}

    chan_status = im_s.ImageManageService().update_image_info(
        update_data, where_data)
    if chan_status < 0:
        logging.error("release image error, update_data:%s", str(update_data))
        error_msg = "发布镜像 %s 失败,更新image_manage表信息失败", eimage_name
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    state_tag = im_m_act_sta.SUCCESSED
    message = '发布成功'
    im_s.ImageStatusService().add_image_status_action(eimage_name,
                                                      update_action, state_tag,
                                                      message)
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS)
示例#5
0
def image_create_new():
    eimage_name = request.values.get('image_name')
    displayname = request.values.get('displayname')
    template_ostype = request.values.get('os_type')
    version = request.values.get('version')
    if not eimage_name or not displayname or not version or not template_ostype:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    # 判断当前image表是否有同名镜像
    image_nums, image_data = image_service.ImageService().get_images_by_name(
        eimage_name)
    if image_data:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='image表已存在同名镜像')

    # 判断当前image_manage表是否有同名镜像
    eimage_data = image_service.ImageManageService(
    ).get_image_manage_info_by_name(eimage_name)
    if eimage_data:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='image_manage表已存在同名镜像')

    # 获取IP资源,先判断是否有人也在分配IP资源,有则等待1s,时间之后再优化
    ip_lock_unused = False
    while not ip_lock_unused:
        ret_ip_lock_status = ip_l_s.IpLockService().get_ip_lock_info('ip')
        if not ret_ip_lock_status:
            logging.error('创建新镜像 %s 失败:检查IP时无法获取资源锁状态') % eimage_name
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg='检查IP时无法获取资源锁状态')
        if ret_ip_lock_status['istraceing'] == IpLockStatus.USED:
            time.sleep(1)
        else:
            ip_lock_unused = True
    # 更新ip_lock表istraceing字段为1
    ret_ip_lock_used_status, ret_ip_lock_used_datas = __update_ip_lock_used()
    if not ret_ip_lock_used_status:
        logging.error(ret_ip_lock_used_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ip_lock_used_datas)
    try:
        ret_ips_status, ret_ips_data = __check_ip_resource()
    except Exception as e:
        _msg = '创建全新镜像:判断IP资源是否足够出现异常 : check ip resource exception when create new image ,err:%s' % e
        logging.error(_msg)
        ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
        )
        if not ret_ip_lock_unused_status:
            logging.error(ret_ip_lock_unused_datas)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=_msg)

    if not ret_ips_status:
        ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
        )
        if not ret_ip_lock_unused_status:
            logging.error(ret_ip_lock_unused_datas)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ips_data)

    # 更新ip_lock表istraceing字段为0
    ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
    )
    if not ret_ip_lock_unused_status:
        logging.error(ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ip_lock_unused_datas)

    #segment_data = segment_s.SegmentService().get_segment_for_img_tmp()
    ip_data = ret_ips_data
    message = '模板机 %s 创建预分配IP成功' % eimage_name
    logging.info(message)

    # 模板机define
    ret, message = im_man_act._img_tem_define(eimage_name)
    if not ret:
        logging.error(message)
        # 将预分频的ip释放
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)

    tag = randomUUID()
    # 添加信息到image_manage表
    insert_data = {
        'eimage_name': eimage_name,
        'displayname': displayname,
        # status=-1:初始化;0:使用中;1:编辑中;2:待发布
        'status': ImageManage.INIT,
        'related_image_tag': tag,
        'os_type': template_ostype,
        'version': version,
        #创建全新镜像,template_status值默认1
        'template_status': img_tmp_status.SHUTDOWN,
        'template_vm_ip': ip_data['ip_address'],
        'message': '创建完成',
        'create_type': image_ceate_type.ALL_NEW,
        'create_time': get_datetime_str()
    }
    # 创建全新的镜像
    ret = image_service.ImageManageService().add_image_info(insert_data)
    if ret.get('row_num') <= 0:
        logging.error("add image error, insert_data:%s", str(insert_data))
        error_msg = "添加新镜像 %s 失败", str(insert_data)
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS)
示例#6
0
def image_update_by_exist():
    eimage_name = request.values.get('eimage_name')
    displayname = request.values.get('displayname')
    version = request.values.get('version')
    template_ostype = request.values.get('os_type')
    tag = randomUUID()
    if not eimage_name or not displayname or not version or not template_ostype:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    # 判断当前image表是否有该镜像信息
    image_nums, image_data = image_service.ImageService().get_images_by_name(
        eimage_name)
    if not image_data:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='image表不存在此镜像')

    # 判断当前image_manage表是否有同名镜像
    eimage_data = image_service.ImageManageService(
    ).get_image_manage_info_by_name(eimage_name)
    if eimage_data:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='image_manage表已存在同名镜像')

    # 获取IP资源,先判断是否有人也在分配IP资源,有则等待1s,时间之后再优化
    ip_lock_unused = False
    while not ip_lock_unused:
        ret_ip_lock_status = ip_l_s.IpLockService().get_ip_lock_info('ip')
        if not ret_ip_lock_status:
            logging.error('创建新镜像 %s 失败:检查IP时无法获取资源锁状态') % eimage_name
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg='检查IP时无法获取资源锁状态')
        if ret_ip_lock_status['istraceing'] == IpLockStatus.USED:
            time.sleep(1)
        else:
            ip_lock_unused = True
    # 更新ip_lock表istraceing字段为1
    ret_ip_lock_used_status, ret_ip_lock_used_datas = __update_ip_lock_used()
    if not ret_ip_lock_used_status:
        logging.error(ret_ip_lock_used_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ip_lock_used_datas)
    try:
        ret_ips_status, ret_ips_data = __check_ip_resource()
    except Exception as e:
        _msg = '已有镜像补录:判断IP资源是否足够出现异常 : check ip resource exception when image update by exist ,err:%s' % e
        logging.error(_msg)
        ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
        )
        if not ret_ip_lock_unused_status:
            logging.error(ret_ip_lock_unused_datas)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=_msg)

    if not ret_ips_status:
        ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
        )
        if not ret_ip_lock_unused_status:
            logging.error(ret_ip_lock_unused_datas)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ips_data)

    # 更新ip_lock表istraceing字段为0
    ret_ip_lock_unused_status, ret_ip_lock_unused_datas = __update_ip_lock_unused(
    )
    if not ret_ip_lock_unused_status:
        logging.error(ret_ip_lock_unused_datas)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=ret_ip_lock_unused_datas)

    ip_data = ret_ips_data
    message = '模板机 %s 创建预分配IP成功' % eimage_name
    logging.info(message)

    # 在镜像编辑服务器上创建相应文件夹
    dest_dir = '/app/image/' + eimage_name
    ret, msg = ansibleCmdV2.create_destdir(IMAGE_EDIT_SERVER, dest_dir)
    if not ret:
        logging.error(msg)
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=msg)

    # 获取新镜像文件的list到镜像编辑服务器
    ret, message = im_man_act._img_create_from_exist(eimage_name, eimage_name)
    if not ret:
        logging.error(message)
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)

    # 模板机define
    ret, message = im_man_act._img_tem_define(eimage_name)
    if not ret:
        logging.error(message)
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg=message)

    # 根据已有镜像生成镜像的接口
    insert_data = {
        'eimage_name': eimage_name,
        'displayname': displayname,
        # status=-1:初始化;0:使用中;1:编辑中;2:待发布
        'status': ImageManage.INIT,
        'related_image_tag': tag,
        'version': version,
        # 根据已有的镜像创建,template_status只默认1
        'template_status': img_tmp_status.SHUTDOWN,
        'template_vm_ip': ip_data['ip_address'],
        'message': '创建完成',
        'create_type': image_ceate_type.UPDATE_EXIST,
        'create_time': get_datetime_str(),
        'os_type': template_ostype,
    }
    ret = image_service.ImageManageService().add_image_info(insert_data)
    if ret.get('row_num') <= 0:
        logging.error("add image error, insert_data:%s", str(insert_data))
        error_msg = "添加新镜像 %s 失败", str(insert_data)
        _set_ip_init(ip_data)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)

    return json_helper.format_api_resp(code=ErrorCode.SUCCESS)
def image_release_by_exist():
    # 发布已有模板的镜像
    '''
    image_info_list = [{'actual_size_mb':1200.8, 'md5':'32234234234342'}]
    :return:
    '''
    name = request.values.get('name')
    if not name:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR, msg='入参缺失')

    image_manage_data = im_s.ImageManageService().get_img_manage_data_by_name(
        name)
    create_type = image_manage_data[1]['create_type']

    # 判断当前image状态是否正常
    image_manage_stat = image_manage_data[1]["status"]
    if image_manage_stat != ImageManage.CHECKOUT:
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg='当前模板机状态不允许此操作')

    # 更新image_manage状态为发布中
    message = ''
    eimage_name = name
    im_s.ImageManageService().update_image_manage_status(
        eimage_name, message, ImageManage.RELEASING)
    image_info_list = image_disk_md5_together(name)

    # 获取镜像文件的list
    res, image_list_info = ansibleCmdV2.get_image_disk_list(
        IMAGE_EDIT_SERVER, eimage_name)
    update_action = im_m_act.RELEASE_IMGSERVER
    if not res:
        # 更新image_manage表和iamge_update_status
        error_msg = image_list_info
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, message)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    image_disk_list = list(image_list_info)

    # 更新镜像服务器
    ret, message = img_server_update_img(eimage_name, image_disk_list,
                                         create_type)
    if not ret:
        error_msg = message
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)

    if create_type == image_ceate_type.ALL_NEW or create_type == image_ceate_type.FROM_EXIST:
        pass
    else:
        # 更新镜像缓存服务器
        ret, message = img_cache_server_update_img(eimage_name,
                                                   image_disk_list)
        update_action = im_m_act.RELEASE_CACHESERVER
        if not ret:
            error_msg = message
            state_tag = im_m_act_sta.FAILED
            im_s.ImageManageService().update_image_manage_status(
                eimage_name, error_msg, ImageManage.CHECKOUT)
            im_s.ImageStatusService().add_image_status_action(
                eimage_name, update_action, state_tag, error_msg)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=error_msg)
    # 更新db
    for index, i in enumerate(image_info_list):
        if index == 0:
            url_i = ('/' + name) * 2
        else:
            url_i = ('/' + name) * 2 + '_disk' + str(index + 1)
        update_data = {
            'md5': i['md5'],
            'actual_size_mb': i['actual_size_mb'],
            'updated_at': get_datetime_str(),
        }
        where_data = {
            'url': url_i,
        }
        ret = im_s.ImageService().update_image_info(update_data, where_data)
        if ret < 0:
            logging.error("release image error, update_data:%s",
                          str(update_data))
            error_msg = "发布镜像 %s 失败,更新image表信息失败", str(update_data)
            state_tag = im_m_act_sta.FAILED
            im_s.ImageManageService().update_image_manage_status(
                eimage_name, error_msg, ImageManage.CHECKOUT)
            im_s.ImageStatusService().add_image_status_action(
                eimage_name, update_action, state_tag, error_msg)
            return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                               msg=error_msg)
    update_data = {
        'status': ImageManage.USABLE,
        'create_type': image_ceate_type.USING
    }
    where_data = {'eimage_name': name}
    change_status = im_s.ImageManageService().update_image_info(
        update_data, where_data)
    if change_status < 0:
        logging.error("release image error, update_data:%s", str(update_data))
        error_msg = "发布镜像 %s 失败,更新image_manage表信息失败" % eimage_name
        state_tag = im_m_act_sta.FAILED
        im_s.ImageManageService().update_image_manage_status(
            eimage_name, error_msg, ImageManage.CHECKOUT)
        im_s.ImageStatusService().add_image_status_action(
            eimage_name, update_action, state_tag, error_msg)
        return json_helper.format_api_resp(code=ErrorCode.SYS_ERR,
                                           msg=error_msg)
    state_tag = im_m_act_sta.SUCCESSED
    message = '发布成功'
    im_s.ImageStatusService().add_image_status_action(eimage_name,
                                                      update_action, state_tag,
                                                      message)
    return json_helper.format_api_resp(code=ErrorCode.SUCCESS)