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请求参数解析

      1. _args = menu_get_parser.parse_args() #请求参数解析校验,添加默认值
      2. args = {attr: value if value is not None else '' for attr, value in _args.items()}
      3. if args['limit'] == -1:
      4. args['limit'] = 10000
      5. 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 分页后的页面数据

  1. - get
  2. - 查询菜单分页数据
  3. - post
  4. - 菜单对象增删改查
  5. - /menu/<menu_id>
  6. - get #查询指定menuid信息,及所有父亲menu_id信息
  7. - put #修改menu菜单信息
  8. - post 删除menu关联信息
  9. - UserGroupMenuRelationships 分组菜单关联表 表名:group_menu_relationships
  10. - 删除menu_id对应的用户组关系
  11. ```python
  12. {
  13. "data": [
  14. {
  15. "child": [],
  16. "icon": "parent_obj.icon",
  17. "id": 1,
  18. "key": "/index/home/dashboard",
  19. "title": "Dashboard"
  20. },
  21. {
  22. "child": [
  23. {
  24. "icon": "child_obj.icon",
  25. "key": "/index/galaxy/machine",
  26. "title": "机器管理"
  27. },
  28. {
  29. "icon": "child_obj.icon",
  30. "key": "/index/galaxy/service",
  31. "title": "服务管理"
  32. },
  33. {
  34. "icon": "child_obj.icon",
  35. "key": "/index/galaxy/group",
  36. "title": "群组信息"
  37. }
  38. ],
  39. "icon": "parent_obj.icon",
  40. "id": 2,
  41. "key": "/index/galaxy",
  42. "title": "CMDB PRO"
  43. },
  44. {
  45. "child": [
  46. {
  47. "icon": "child_obj.icon",
  48. "key": "/index/resource/ecs",
  49. "title": "云服务器"
  50. },
  51. {
  52. "icon": "child_obj.icon",
  53. "key": "/index/resource/slb",
  54. "title": "负载均衡"
  55. },
  56. {
  57. "icon": "child_obj.icon",
  58. "key": "/index/resource/billing",
  59. "title": "Billing"
  60. },
  61. {
  62. "icon": "child_obj.icon",
  63. "key": "/index/resource/add",
  64. "title": "购买机器"
  65. }
  66. ],
  67. "icon": "parent_obj.icon",
  68. "id": 7,
  69. "key": "/index/resource",
  70. "title": "云平台中心"
  71. },
  72. {
  73. "child": [
  74. {
  75. "icon": "child_obj.icon",
  76. "key": "/index/domain/inner",
  77. "title": "内网域名"
  78. },
  79. {
  80. "icon": "child_obj.icon",
  81. "key": "/index/domain/public",
  82. "title": "外网域名"
  83. }
  84. ],
  85. "icon": "parent_obj.icon",
  86. "id": 12,
  87. "key": "/index/domain",
  88. "title": "域名管理"
  89. },
  90. {
  91. "child": [
  92. {
  93. "icon": "child_obj.icon",
  94. "key": "/index/dingtalk/rebot",
  95. "title": "FAQ管理"
  96. },
  97. {
  98. "icon": "child_obj.icon",
  99. "key": "/index/dingtalk/command",
  100. "title": "自定义指令"
  101. },
  102. {
  103. "icon": "child_obj.icon",
  104. "key": "/index/dingtalk/duty",
  105. "title": "Duty管理"
  106. },
  107. {
  108. "icon": "child_obj.icon",
  109. "key": "/index/dingtalk/history",
  110. "title": "记录统计"
  111. }
  112. ],
  113. "icon": "parent_obj.icon",
  114. "id": 15,
  115. "key": "/index/dingtalk",
  116. "title": "Workflow"
  117. },
  118. {
  119. "child": [
  120. {
  121. "icon": "child_obj.icon",
  122. "key": "/index/alarm/dashboard",
  123. "title": "Dashboard"
  124. },
  125. {
  126. "icon": "child_obj.icon",
  127. "key": "/index/alarm/list",
  128. "title": "告警中心"
  129. },
  130. {
  131. "icon": "child_obj.icon",
  132. "key": "/index/alarm/topology",
  133. "title": "网络拓扑"
  134. }
  135. ],
  136. "icon": "parent_obj.icon",
  137. "id": 20,
  138. "key": "/index/alarm",
  139. "title": "监控告警"
  140. },
  141. {
  142. "child": [
  143. {
  144. "icon": "child_obj.icon",
  145. "key": "/index/task/list",
  146. "title": "流程列表"
  147. },
  148. {
  149. "icon": "child_obj.icon",
  150. "key": "/index/task/record",
  151. "title": "流程记录"
  152. }
  153. ],
  154. "icon": "parent_obj.icon",
  155. "id": 24,
  156. "key": "/index/task",
  157. "title": "流程管理"
  158. },
  159. {
  160. "child": [
  161. {
  162. "icon": "child_obj.icon",
  163. "key": "/index/notify/list",
  164. "title": "钉钉群管理"
  165. },
  166. {
  167. "icon": "child_obj.icon",
  168. "key": "/index/notify/record",
  169. "title": "发送记录"
  170. }
  171. ],
  172. "icon": "parent_obj.icon",
  173. "id": 27,
  174. "key": "/index/notify",
  175. "title": "Notify"
  176. },
  177. {
  178. "child": [
  179. {
  180. "icon": "child_obj.icon",
  181. "key": "/index/infomation/postcode",
  182. "title": "发布码管控"
  183. },
  184. {
  185. "icon": "child_obj.icon",
  186. "key": "/index/infomation/slb",
  187. "title": "SLB信息"
  188. },
  189. {
  190. "icon": "child_obj.icon",
  191. "key": "/index/infomation/proxy",
  192. "title": "中间件信息"
  193. },
  194. {
  195. "icon": "child_obj.icon",
  196. "key": "/index/infomation/appkey",
  197. "title": "AppKey查询"
  198. },
  199. {
  200. "icon": "child_obj.icon",
  201. "key": "/index/infomation/oss",
  202. "title": "OSS信息查询"
  203. }
  204. ],
  205. "icon": "parent_obj.icon",
  206. "id": 31,
  207. "key": "/index/infomation",
  208. "title": "信息汇总"
  209. },
  210. {
  211. "child": [
  212. {
  213. "icon": "child_obj.icon",
  214. "key": "/index/manage/account",
  215. "title": "云账号管理"
  216. },
  217. {
  218. "icon": "child_obj.icon",
  219. "key": "/index/manage/department",
  220. "title": "部门管理"
  221. },
  222. {
  223. "icon": "child_obj.icon",
  224. "key": "/index/manage/user",
  225. "title": "用户管理"
  226. },
  227. {
  228. "icon": "child_obj.icon",
  229. "key": "/index/manage/operation",
  230. "title": "操作记录"
  231. },
  232. {
  233. "icon": "child_obj.icon",
  234. "key": "/index/manage/business",
  235. "title": "业务管理"
  236. },
  237. {
  238. "icon": "child_obj.icon",
  239. "key": "/index/manage/cloud/index",
  240. "title": "云平台管理"
  241. },
  242. {
  243. "icon": "child_obj.icon",
  244. "key": "/index/manage/ansible/log",
  245. "title": "Ansible任务系统"
  246. }
  247. ],
  248. "icon": "parent_obj.icon",
  249. "id": 38,
  250. "key": "/index/manage",
  251. "title": "后台管理"
  252. },
  253. {
  254. "child": [],
  255. "icon": "parent_obj.icon",
  256. "id": 44,
  257. "key": "/index/user/info",
  258. "title": "个人信息"
  259. },
  260. {
  261. "child": [],
  262. "icon": "parent_obj.icon",
  263. "id": 100,
  264. "key": "/index/home/document",
  265. "title": "Document"
  266. },
  267. {
  268. "child": [
  269. {
  270. "icon": "child_obj.icon",
  271. "key": "/index/cmdb/host",
  272. "title": "云-服务器"
  273. },
  274. {
  275. "icon": "child_obj.icon",
  276. "key": "/index/cmdb/database",
  277. "title": "云-数据库"
  278. },
  279. {
  280. "icon": "child_obj.icon",
  281. "key": "/index/cmdb/nat_gateway",
  282. "title": "云-Nat网关"
  283. },
  284. {
  285. "icon": "child_obj.icon",
  286. "key": "/index/cmdb/oss",
  287. "title": "云-对象存储"
  288. },
  289. {
  290. "icon": "child_obj.icon",
  291. "key": "/index/cmdb/domain",
  292. "title": "云-域名解析"
  293. }
  294. ],
  295. "icon": "parent_obj.icon",
  296. "id": 102,
  297. "key": "/index/cmdb",
  298. "title": "CMDB"
  299. },
  300. {
  301. "child": [
  302. {
  303. "icon": "child_obj.icon",
  304. "key": "/index/ansible/task",
  305. "title": "Ansible任务管理"
  306. },
  307. {
  308. "icon": "child_obj.icon",
  309. "key": "/index/ansible/log",
  310. "title": "Ansible任务日志"
  311. },
  312. {
  313. "icon": "child_obj.icon",
  314. "key": "/index/ansible/vars",
  315. "title": "Ansible变量管理"
  316. }
  317. ],
  318. "icon": "parent_obj.icon",
  319. "id": 112,
  320. "key": "/index/ansible",
  321. "title": "任务系统"
  322. }
  323. ],
  324. "msg": "获取菜单列表成功",
  325. "return_code": 0
  326. }

装饰器

  • @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 多个筛选条件

    服务管理

群组信息