def static_add(request): all_instances = vyos.instance_getall() hostname_default = vyos.get_hostname_prefered(request) static_list = vyos.get_route_static(hostname_default) is_superuser = perms.get_is_superuser(request.user) error_message = None if 'subnet' in request.POST and 'nexthop' in request.POST: return1 = vyos.set_route_static(hostname_default, request.POST['subnet'], request.POST['nexthop']) if return1 == False: error_message = 'Cannot add static route.' else: return redirect('static:static-list') ippath = vyos.ip_route(hostname_default) template = loader.get_template('static/add.html') context = { 'instances': all_instances, 'hostname_default': hostname_default, 'static_list' : static_list, 'error_message' : error_message, 'username': request.user, 'is_superuser' : is_superuser, } return HttpResponse(template.render(context, request))
def static_add(request): msg = vmsg.msg() all_instances = vyos.instance_getall() hostname_default = vyos.get_hostname_prefered(request) static_list = vyos.get_route_static(hostname_default) is_superuser = perms.get_is_superuser(request.user) if 'subnet' in request.POST and 'nexthop' in request.POST: v = vapi.set_route_static(hostname_default, request.POST['subnet'], request.POST['nexthop']) if v.success == False: msg.add_error("Static route add fail - " + v.reason) else: msg.add_success("Static route added") ippath = vyos.ip_route(hostname_default) template = loader.get_template('static/add.html') context = { 'instances': all_instances, 'hostname_default': hostname_default, 'static_list': static_list, 'username': request.user, 'is_superuser': is_superuser, 'msg': msg.get_all(), } return HttpResponse(template.render(context, request))
def static_remove(request, route, nexthop): all_instances = vyos.instance_getall() hostname_default = vyos.get_hostname_prefered(request) static_list = vyos.get_route_static(hostname_default) print(route) print(routeunpack(route)) if route and nexthop: return1 = vyos.delete_route_static(hostname_default, routeunpack(route), nexthop) return redirect('static:static-list')
def static_list(request): all_instances = vyos.instance_getall() hostname_default = vyos.get_hostname_prefered(request) static_dict = vyos.get_route_static(hostname_default) is_superuser = perms.get_is_superuser(request.user) static_list = [] for s in static_dict['route']: static_list.append({ 'route': s, 'nexthop': static_dict['route'][s]['next-hop'], }) template = loader.get_template('static/list.html') context = { 'instances': all_instances, 'hostname_default': hostname_default, 'static_list' : static_list, 'username': request.user, 'is_superuser' : is_superuser, } return HttpResponse(template.render(context, request))