host.py 1.2 KB

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