api.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:enjoliver 作者: JulienBalestra 项目源码 文件源码
def change_lifecycle_rolling(request_raw_query):
    """
    Lifecycle Rolling Update
    Change the current policy for a given machine by MAC
    ---
    tags:
      - lifecycle
    parameters:
      - name: request_raw_query
        in: path
        description: Pass the mac as 'mac=<mac>'
        required: true
        type: string
    responses:
      200:
        description: Rolling Update is enable
        schema:
            type: dict
      401:
        description: Mac address is not in database
        schema:
            type: dict
    """

    app.logger.info("%s %s" % (request.method, request.url))
    try:
        strategy = json.loads(request.get_data())["strategy"]
        app.logger.info("%s %s rolling strategy: setting to %s" % (request.method, request.url, strategy))
    except (KeyError, ValueError):
        # JSONDecodeError is a subclass of ValueError
        # Cannot use JSONDecodeError because the import is not consistent between python3.X
        app.logger.info("%s %s rolling strategy: setting default to kexec" % (request.method, request.url))
        strategy = "kexec"

    @smartdb.cockroach_transaction
    def op(caller=request.url_rule):
        with SMART.new_session() as session:
            try:
                life = crud.InjectLifecycle(session, request_raw_query)
                life.apply_lifecycle_rolling(True, strategy)
                return jsonify({"enable": True, "request_raw_query": request_raw_query, "strategy": strategy}), 200
            except AttributeError:
                return jsonify({"enable": None, "request_raw_query": request_raw_query, "strategy": strategy}), 401

    return op(caller=request.url_rule)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号