ops-server/app/server/api
接口通用调用介绍
- xxx的api接口调用创建xxxService 对象
- 通过xxxService 封装对xxx的不同功能,再调用xxxRepo对象的对应方法
- xxxRepo对象2个功能
- 1.分页查询
- 2.简单的增删改查
登录页
login.py
接口
- /register 用户注册
- /login 登陆 : 登录成功获取: 登录token,刷新token
- 接口返回的accesstoken: 2 天过期 refreshtoken: 过期时间30天
- /testGetData 测试登录保护
- /refresh_token 只获取刷新token
装饰器
- @dingtalk_required #判断是否钉钉登录成功(前端会要求钉钉登录,登录成功后将token返回),校验钉钉返回的登录签名是否正确
- @ops_log.operation_log(verification=False) 如果接口被访问则记录日志到数据库
工具
- jwt生成token,校验token
页面布局
页面
- src/layouts/index.js
菜单页
menu.py
页面
- src/components/asideMenu/Index.js
接口
- /menu/list # 前端页面的menu数据
- 获取用户名
- 根据用户名找到用户分组,根据用户组找到关联的菜单id
- 根据菜单id找具体菜单信息列,菜单列表分子菜单,和父菜单
- 根据菜单id排序菜单
- 循环父菜单列表及子菜单列表,构建前端需要的菜单数据
/menu
menu_get_parser.parse_args() #get请求参数解析
_args = menu_get_parser.parse_args() #请求参数解析校验,添加默认值
args = {attr: value if value is not None else '' for attr, value in _args.items()}
if args['limit'] == -1:
args['limit'] = 10000
params = request.args.to_dict() 获取args转字典
MenuService 菜单分页服务 ```python
params : order_by=None, page=None, limit=None, sort=None
接口参数配置: ops-server/app/server/utils/args_parser.py
1.class MenuService() self.menurepo=MenuRepo(OrderedQueryBase(QueryHelper)._init(self, Menu, page, per_page, Menu.id)) #以menu.id作为order的key 2.MenuService().get_menus_page(params) === self.menu_repo.find_page(**params) === OrderedQueryBase(QueryHelper).find_page()
menu_repo() : 1.封装菜单的分页查询 2.封装菜单的增删改普通查询 find_page() : 1.排序 2.其他参数当做条件查询=complex_query 3.返回分页信息 —> QueryHelper(object).paginate_by_query(cls, query, page, per_page): —> query.paginate(page=page, per_page=per_page) #返回分页信息
3.pagination.items 分页后的页面数据
- get
- 查询菜单分页数据
- post
- 菜单对象增删改查
- /menu/<menu_id>
- get #查询指定menuid信息,及所有父亲menu_id信息
- put #修改menu菜单信息
- post 删除menu关联信息
- UserGroupMenuRelationships 分组菜单关联表 表名:group_menu_relationships
- 删除menu_id对应的用户组关系
```python
{
"data": [
{
"child": [],
"icon": "parent_obj.icon",
"id": 1,
"key": "/index/home/dashboard",
"title": "Dashboard"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/galaxy/machine",
"title": "机器管理"
},
{
"icon": "child_obj.icon",
"key": "/index/galaxy/service",
"title": "服务管理"
},
{
"icon": "child_obj.icon",
"key": "/index/galaxy/group",
"title": "群组信息"
}
],
"icon": "parent_obj.icon",
"id": 2,
"key": "/index/galaxy",
"title": "CMDB PRO"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/resource/ecs",
"title": "云服务器"
},
{
"icon": "child_obj.icon",
"key": "/index/resource/slb",
"title": "负载均衡"
},
{
"icon": "child_obj.icon",
"key": "/index/resource/billing",
"title": "Billing"
},
{
"icon": "child_obj.icon",
"key": "/index/resource/add",
"title": "购买机器"
}
],
"icon": "parent_obj.icon",
"id": 7,
"key": "/index/resource",
"title": "云平台中心"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/domain/inner",
"title": "内网域名"
},
{
"icon": "child_obj.icon",
"key": "/index/domain/public",
"title": "外网域名"
}
],
"icon": "parent_obj.icon",
"id": 12,
"key": "/index/domain",
"title": "域名管理"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/dingtalk/rebot",
"title": "FAQ管理"
},
{
"icon": "child_obj.icon",
"key": "/index/dingtalk/command",
"title": "自定义指令"
},
{
"icon": "child_obj.icon",
"key": "/index/dingtalk/duty",
"title": "Duty管理"
},
{
"icon": "child_obj.icon",
"key": "/index/dingtalk/history",
"title": "记录统计"
}
],
"icon": "parent_obj.icon",
"id": 15,
"key": "/index/dingtalk",
"title": "Workflow"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/alarm/dashboard",
"title": "Dashboard"
},
{
"icon": "child_obj.icon",
"key": "/index/alarm/list",
"title": "告警中心"
},
{
"icon": "child_obj.icon",
"key": "/index/alarm/topology",
"title": "网络拓扑"
}
],
"icon": "parent_obj.icon",
"id": 20,
"key": "/index/alarm",
"title": "监控告警"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/task/list",
"title": "流程列表"
},
{
"icon": "child_obj.icon",
"key": "/index/task/record",
"title": "流程记录"
}
],
"icon": "parent_obj.icon",
"id": 24,
"key": "/index/task",
"title": "流程管理"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/notify/list",
"title": "钉钉群管理"
},
{
"icon": "child_obj.icon",
"key": "/index/notify/record",
"title": "发送记录"
}
],
"icon": "parent_obj.icon",
"id": 27,
"key": "/index/notify",
"title": "Notify"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/infomation/postcode",
"title": "发布码管控"
},
{
"icon": "child_obj.icon",
"key": "/index/infomation/slb",
"title": "SLB信息"
},
{
"icon": "child_obj.icon",
"key": "/index/infomation/proxy",
"title": "中间件信息"
},
{
"icon": "child_obj.icon",
"key": "/index/infomation/appkey",
"title": "AppKey查询"
},
{
"icon": "child_obj.icon",
"key": "/index/infomation/oss",
"title": "OSS信息查询"
}
],
"icon": "parent_obj.icon",
"id": 31,
"key": "/index/infomation",
"title": "信息汇总"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/manage/account",
"title": "云账号管理"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/department",
"title": "部门管理"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/user",
"title": "用户管理"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/operation",
"title": "操作记录"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/business",
"title": "业务管理"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/cloud/index",
"title": "云平台管理"
},
{
"icon": "child_obj.icon",
"key": "/index/manage/ansible/log",
"title": "Ansible任务系统"
}
],
"icon": "parent_obj.icon",
"id": 38,
"key": "/index/manage",
"title": "后台管理"
},
{
"child": [],
"icon": "parent_obj.icon",
"id": 44,
"key": "/index/user/info",
"title": "个人信息"
},
{
"child": [],
"icon": "parent_obj.icon",
"id": 100,
"key": "/index/home/document",
"title": "Document"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/cmdb/host",
"title": "云-服务器"
},
{
"icon": "child_obj.icon",
"key": "/index/cmdb/database",
"title": "云-数据库"
},
{
"icon": "child_obj.icon",
"key": "/index/cmdb/nat_gateway",
"title": "云-Nat网关"
},
{
"icon": "child_obj.icon",
"key": "/index/cmdb/oss",
"title": "云-对象存储"
},
{
"icon": "child_obj.icon",
"key": "/index/cmdb/domain",
"title": "云-域名解析"
}
],
"icon": "parent_obj.icon",
"id": 102,
"key": "/index/cmdb",
"title": "CMDB"
},
{
"child": [
{
"icon": "child_obj.icon",
"key": "/index/ansible/task",
"title": "Ansible任务管理"
},
{
"icon": "child_obj.icon",
"key": "/index/ansible/log",
"title": "Ansible任务日志"
},
{
"icon": "child_obj.icon",
"key": "/index/ansible/vars",
"title": "Ansible变量管理"
}
],
"icon": "parent_obj.icon",
"id": 112,
"key": "/index/ansible",
"title": "任务系统"
}
],
"msg": "获取菜单列表成功",
"return_code": 0
}
装饰器
- @login_required 需要登录访问,校验request中的token
- @ops_log.operation_log(verification=False)
Dashboard
machine.py
页面
- src/pages/home/Dashboard.js
接口
- /host 查询主机信息(dns记录)
- /machine cmdb pro机器查询接口
- /machine/
根据机器id查询 - /galaxy/machines
- Avatar表 关联 : group_id service_id machine_id
- 根据部门id查询未绑定部门的机器
- /machine/statistical
- dashboard 机器相关数据统计
CMDB PRO 页面
机器管理
页面
- src/pages/galaxy/Machine.js
- 渲染所有机器信息 tabel
接口
ops-server/app/server/api/machine.py
- /machine 查询所有机器
- /machine?page=1&limit=10&zone_id__contains=hangzhou 筛选可用区
- /machine?page=1&limit=10&instance_idcontains=i-bp14lk95qe2zsdas90uz&zone_idcontains=hangzhou 多个筛选条件
服务管理