host.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from flask import Blueprint, render_template, url_for, request
  5. import requests
  6. __author__ = 'James Iter'
  7. __date__ = '2017/8/10'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. blueprint = Blueprint(
  11. 'v_host',
  12. __name__,
  13. url_prefix='/host'
  14. )
  15. blueprints = Blueprint(
  16. 'v_hosts',
  17. __name__,
  18. url_prefix='/hosts'
  19. )
  20. def show():
  21. url = url_for('api_hosts.r_show', _external=True)
  22. if request.args.__len__() >= 1:
  23. args = list()
  24. for k, v in request.args.items():
  25. args.append('='.join([k, v]))
  26. url += '?' + '&'.join(args)
  27. ret = requests.get(url=url, cookies=request.cookies)
  28. ret = json.loads(ret.content)
  29. return render_template('hosts_show.html', hosts=ret['data']['hosts'], resource_path=request.path,
  30. keyword=ret['data']['keyword'])
  31. def detail(node_id):
  32. host_url = url_for('api_hosts.r_get', nodes_id=node_id, _external=True)
  33. host_ret = requests.get(url=host_url, cookies=request.cookies)
  34. host_ret = json.loads(host_ret.content)
  35. return render_template('host_detail.html', node_id=node_id, host=host_ret['data'])