views.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. from django.template import loader
  4. from django.shortcuts import redirect
  5. from django.conf import settings
  6. from django.urls import reverse
  7. import vyos
  8. def index(request):
  9. if not request.user.is_authenticated:
  10. return redirect('%s?next=%s' % (reverse('registration-login'), request.path))
  11. all_instances = vyos.instance_getall()
  12. hostname_default = vyos.get_hostname_prefered(request)
  13. #static_list = vyos.get_route_static(hostname_default)
  14. static_list = None
  15. template = loader.get_template('static/list.html')
  16. context = {
  17. 'instances': all_instances,
  18. 'hostname_default': hostname_default,
  19. 'static_list' : static_list
  20. }
  21. return HttpResponse(template.render(context, request))
  22. def static(request):
  23. if not request.user.is_authenticated:
  24. return redirect('%s?next=%s' % (reverse('registration-login'), request.path))
  25. all_instances = vyos.instance_getall()
  26. hostname_default = vyos.get_hostname_prefered(request)
  27. static_list = vyos.get_route_static(hostname_default)
  28. error_message = None
  29. if 'subnet' in request.POST and 'nexthop' in request.POST:
  30. #return1 = vyos.set_route_static(hostname_default, request.POST['subnet'], request.POST['nexthop'])
  31. return1 = False
  32. if return1 == False:
  33. error_message = 'Cannot add static route.'
  34. else:
  35. return redirect('static:static-list')
  36. template = loader.get_template('static/static.html')
  37. context = {
  38. 'instances': all_instances,
  39. 'hostname_default': hostname_default,
  40. 'static_list' : static_list,
  41. 'error_message' : error_message,
  42. }
  43. return HttpResponse(template.render(context, request))