views.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. from django.template import loader
  4. import vyos
  5. from config.models import Instance
  6. def index(request):
  7. hostname_default = vyos.get_hostname_prefered(request)
  8. all_instances = vyos.instance_getall()
  9. interfaces = vyos.get_interfaces(hostname_default)
  10. template = loader.get_template('interface/index.html')
  11. context = {
  12. 'interfaces': interfaces,
  13. 'instances': all_instances,
  14. 'hostname_default': hostname_default,
  15. }
  16. return HttpResponse(template.render(context, request))
  17. def interfaceshow(request, interface_type, interface_name):
  18. all_instances = vyos.instance_getall()
  19. hostname_default = vyos.get_hostname_prefered(request)
  20. interface = vyos.get_interface(interface_type, interface_name, hostname=hostname_default)
  21. template = loader.get_template('interface/show.html')
  22. context = {
  23. 'interface': interface,
  24. 'instances': all_instances,
  25. 'hostname_default': hostname_default,
  26. }
  27. return HttpResponse(template.render(context, request))