disk.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/6/25'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. blueprint = Blueprint(
  11. 'v_disk',
  12. __name__,
  13. url_prefix='/disk'
  14. )
  15. blueprints = Blueprint(
  16. 'v_disks',
  17. __name__,
  18. url_prefix='/disks'
  19. )
  20. def show():
  21. url = url_for('api_disks.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('disks_show.html', disks=ret['data']['disks'],
  30. resource_path=request.path,
  31. hosts_mapping_by_node_id=ret['data']['hosts_mapping_by_node_id'],
  32. page=ret['data']['page'], page_size=ret['data']['page_size'], keyword=ret['data']['keyword'],
  33. pages=ret['data']['pages'], order_by=ret['data']['order_by'], order=ret['data']['order'],
  34. last_page=ret['data']['last_page'], paging=ret['data']['paging'],
  35. show_area=ret['data']['show_area'], config=ret['data']['config'],
  36. show_on_host=ret['data']['show_on_host'])
  37. def create():
  38. return render_template('disk_create.html')
  39. def detail(uuid):
  40. disk_detail_url = url_for('api_disk.r_detail', uuid=uuid, _external=True)
  41. disk_detail_ret = requests.get(url=disk_detail_url, cookies=request.cookies)
  42. disk_detail_ret = json.loads(disk_detail_ret.content)
  43. return render_template('disk_detail.html', uuid=uuid, guest=disk_detail_ret['data']['guest'],
  44. os_template_image=disk_detail_ret['data']['os_template_image'],
  45. disk=disk_detail_ret['data']['disk'],
  46. config=disk_detail_ret['data']['config'])