1
0

plugin.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. __author__ = 'Ulric Qin'
  16. from rrd import app
  17. from flask import jsonify, render_template, request, g
  18. from rrd.model.portal.host_group import HostGroup
  19. from rrd.model.portal.plugin_dir import PluginDir
  20. @app.route('/portal/group/<group_id>/plugins')
  21. def plugin_list_get(group_id):
  22. group_id = int(group_id)
  23. group = HostGroup.read(where='id = %s', params=[group_id])
  24. if not group:
  25. return jsonify(msg='no such group %s' % group_id)
  26. plugins = PluginDir.select_vs(where='grp_id = %s', params=[group_id])
  27. return render_template('portal/plugin/list.html', group=group, plugins=plugins)
  28. @app.route('/portal/plugin/bind', methods=['POST'])
  29. def plugin_bind_post():
  30. group_id = int(request.form['group_id'].strip())
  31. plugin_dir = request.form['plugin_dir'].strip()
  32. group = HostGroup.read(where='id = %s', params=[group_id])
  33. if not group:
  34. return jsonify(msg='no such group %s' % group_id)
  35. PluginDir.insert({'grp_id': group_id, 'dir': plugin_dir, 'create_user': g.user.name})
  36. return jsonify(msg='')
  37. @app.route('/portal/plugin/delete/<plugin_id>')
  38. def plugin_delete_get(plugin_id):
  39. plugin_id = int(plugin_id)
  40. plugin = PluginDir.read(where='id = %s', params=[plugin_id])
  41. if not plugin:
  42. return jsonify(msg='no such plugin dir %s' % plugin_id)
  43. PluginDir.delete_one(plugin_id)
  44. return jsonify(msg='')