disk.py 2.0 KB

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