monitor_group.py 文件源码

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

项目:irisett 作者: beebyte 项目源码 文件源码
def update_monitor_group(dbcon: DBConnection, monitor_group_id: int, data: Dict[str, Any]):
    """Update a monitor group in the database.

    Data is a dict with parent_id/name values that will be updated.
    """
    async def _run(cur: Cursor) -> None:
        for key, value in data.items():
            if key not in ['parent_id', 'name']:
                raise errors.IrisettError('invalid monitor_group key %s' % key)
            if key == 'parent_id' and value:
                if monitor_group_id == int(value):
                    raise errors.InvalidArguments('monitor group can\'t be its own parent')
                if not await monitor_group_exists(dbcon, value):
                    raise errors.InvalidArguments('parent monitor group does not exist')
            q = """update monitor_groups set %s=%%s where id=%%s""" % key
            q_args = (value, monitor_group_id)
            await cur.execute(q, q_args)

    await dbcon.transact(_run)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号