Browse Source

static routes not work on vyos api - bug module routes static #27 - not solved

Roberto Berto 5 years ago
parent
commit
d1b54be7ff
4 changed files with 52 additions and 6 deletions
  1. 11 1
      vycenter/static/templates/static/list.html
  2. 2 0
      vycenter/static/urls.py
  3. 30 1
      vycenter/static/views.py
  4. 9 4
      vycenter/vyos.py

+ 11 - 1
vycenter/static/templates/static/list.html

@@ -8,6 +8,16 @@
 {% endblock %}
 
 {% block content %}
-content
+
+
+
+<p>
+    <a href="{% url 'static:static' %}">Create new static route</a>
+</p>
+
+    
+
+
+
 {% endblock %}
 

+ 2 - 0
vycenter/static/urls.py

@@ -7,6 +7,8 @@ app_name = 'static'
 
 urlpatterns = [
     path('', views.index, name='static-list'),
+    path('static', views.static, name='static'),
+
 ]
 
 

+ 30 - 1
vycenter/static/views.py

@@ -15,7 +15,7 @@ def index(request):
         
     all_instances = vyos.instance_getall()
     hostname_default = vyos.get_hostname_prefered(request)
-    static_list = vyos.get_static(hostname_default)
+    #static_list = vyos.get_route_static(hostname_default)
 
     template = loader.get_template('static/list.html')
     context = { 
@@ -25,3 +25,32 @@ def index(request):
     }   
     return HttpResponse(template.render(context, request))
 
+
+
+def static(request):
+    if not request.user.is_authenticated:
+        return redirect('%s?next=%s' % (reverse('registration-login'), request.path))
+        
+    all_instances = vyos.instance_getall()
+    hostname_default = vyos.get_hostname_prefered(request)
+    static_list = vyos.get_route_static(hostname_default)
+
+    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'])
+        return1 = False
+        if return1 == False: 
+            error_message = 'Cannot add static route.'
+        else:
+           return redirect('static:static-list')
+
+
+    template = loader.get_template('static/static.html')
+    context = { 
+        'instances': all_instances,
+        'hostname_default': hostname_default,
+        'static_list' : static_list,
+        'error_message' : error_message,
+    }   
+    return HttpResponse(template.render(context, request))
+

+ 9 - 4
vycenter/vyos.py

@@ -47,6 +47,7 @@ def api(type, hostname, cmd):
     else:
         return False
 
+    pprint.pprint(cmd)
     print(json.dumps(cmd))
     post = {'key': get_key(hostname), 'data': json.dumps(cmd)}
     print(post)   
@@ -180,10 +181,14 @@ def insert_firewall_rules(hostname, cmd):
     result1 = api_set(hostname, cmd)
     return result1
 
+def get_route_static(hostname):
+    cmd = {"op": "showConfig", "path": ["show","protocols","route","static"]}
 
+    result1 = api_get(hostname, cmd)
+    return result1
 
-def get_static(hostname):
-    cmd = {"op": "showConfig", "path": ["show","ip","route","static"]}
+def set_route_static(hostname, subnet, nexthop):
+    cmd = {"op": "set", "path": ["set","protocols","static","route", subnet, "next-hop", nexthop]}
 
-    result1 = api_get(hostname, cmd)
-    return result1
+    result1 = api_set(hostname, cmd)
+    return result1