Prechádzať zdrojové kódy

list instances, add instance, only db work

Roberto Berto 5 rokov pred
rodič
commit
7639503c34

+ 25 - 0
vycenter/config/migrations/0001_initial.py

@@ -0,0 +1,25 @@
+# Generated by Django 2.0.3 on 2020-04-26 04:50
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Instance',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('alias', models.CharField(max_length=30)),
+                ('hostname', models.CharField(max_length=120)),
+                ('port', models.IntegerField(max_length=5)),
+                ('key', models.CharField(max_length=100)),
+                ('https', models.BinaryField()),
+            ],
+        ),
+    ]

+ 18 - 0
vycenter/config/migrations/0002_auto_20200426_0450.py

@@ -0,0 +1,18 @@
+# Generated by Django 2.0.3 on 2020-04-26 04:50
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('config', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='instance',
+            name='port',
+            field=models.IntegerField(),
+        ),
+    ]

+ 18 - 0
vycenter/config/migrations/0003_auto_20200426_1259.py

@@ -0,0 +1,18 @@
+# Generated by Django 2.0.3 on 2020-04-26 12:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('config', '0002_auto_20200426_0450'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='instance',
+            name='https',
+            field=models.BooleanField(),
+        ),
+    ]

+ 10 - 1
vycenter/config/models.py

@@ -1,3 +1,12 @@
 from django.db import models
 
-# Create your models here.
+
+class Instance(models.Model):
+    alias = models.CharField(max_length=30)
+    hostname = models.CharField(max_length=120)
+    port = models.IntegerField()
+    key = models.CharField(max_length=100)
+    https = models.BooleanField()
+
+
+

+ 0 - 13
vycenter/config/templates/config/instance.html

@@ -1,13 +0,0 @@
-{% extends "base.html" %}
-
-{% block header_title %}list of instances{% endblock %}
-{% block section_title %}list of instances{% endblock %}
-
-{% block content %}
-
-<p>List of instances, group owners</p>
-
-{% url 'instance-add' as instance_add %}
-<p><a href="{{ instance_add }}">Add a new instance</a></p>
-
-{% endblock %}

+ 38 - 5
vycenter/config/templates/config/instance_add.html

@@ -1,12 +1,45 @@
 {% extends "base.html" %}
 
-{% block header_title %}Add a new instances{% endblock %}
-{% block section_title %}Add a new instances{% endblock %}
+{% block header_title %}Add new instance{% endblock %}
+{% block section_title %}Add new instance{% endblock %}
 
 {% block content %}
-<p>List of instances, group owners</p>
 
-{% url 'instance-add' as instance_add %}
-<p>Add a new instance</p>
+{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
+
+<form action="{% url 'config:instance-add' %}" method="post">
+{% csrf_token %}
+
+<p>
+<label for="alias">Alias</label><br>
+<input type="text" name="alias" id="alias" value="{{ alias }}" size="20">
+</p>
+
+<p>
+<label for="hostname">VyOS API Hosname/IP</label><br>
+<input type="text" name="hostname" id="hostname" value="{{ hostname }}" size="60">
+</p>
+
+<p>
+<label for="port">VyOS API TCP Port</label><br>
+<input type="text" name="port" id="port" value="{{ port }}" size="5">
+</p>
+
+<p>
+<label for="key">VyOS API Key</label><br>
+<input type="text" name="key" id="key" value="{{ key }}" size="60">
+</p>
+
+
+<p>
+<label for="https">VyOS is https?</label><br>
+<input type="checkbox" name="https" id="https" value="1" checked="checked">
+</p>
+
+<input type="submit" value="Add Instance">
+</form>
+
+
+
 {% endblock %}
 

+ 30 - 0
vycenter/config/templates/config/instances.html

@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+
+{% block header_title %}List instances{% endblock %}
+{% block section_title %}List instances{% endblock %}
+
+{% block content %}
+
+{% if instances %}
+
+    <table border="1" width="100%">
+    <tr><th>alias</th><th>hostname</th><th>port</th><th>key</th><th>https</th></tr>
+
+    {% for instance in instances %}
+    <tr>
+        <td>{{ instance.alias }}</td>
+        <td>{{ instance.hostname }}</td>
+        <td>{{ instance.port }}</td>
+        <td>{{ instance.key }}</td>
+        <td>{{ instance.https }}</td>
+    </tr>
+
+    {% endfor %}
+
+    </table>   
+{% else %}
+    <p>No instances.</p>
+{% endif %}
+
+
+{% endblock %}

+ 4 - 1
vycenter/config/urls.py

@@ -2,9 +2,12 @@ from django.urls import path
 
 from . import views
 
+
+app_name = 'config'
+
 urlpatterns = [
     path('', views.index, name='index'),
     path('instance-add', views.instance_add, name='instance-add'),
-    path('instance', views.instance, name='instance'),
+    path('instances', views.instances, name='instances'),
 
 ]

+ 22 - 6
vycenter/config/views.py

@@ -4,6 +4,8 @@ from django.template import loader
 
 import vyos
 
+from .models import Instance
+
 
 def index(request):
     #interfaces = vyos.get_interfaces()
@@ -16,21 +18,35 @@ def index(request):
 
 
 
-def instance(request):
-    #interfaces = vyos.get_interfaces()
-    
-    template = loader.get_template('config/instance.html')
+def instances(request):
+    all_instances = Instance.objects.all()
+
+    template = loader.get_template('config/instances.html')
     context = { 
-        #'interfaces': interfaces,
+        'instances': all_instances,
     }   
     return HttpResponse(template.render(context, request))
 
 def instance_add(request):
     #interfaces = vyos.get_interfaces()
     
+    if len(request.POST) > 0:
+        instance = Instance()
+        instance.alias = request.POST['alias']
+        instance.hostname = request.POST['hostname']
+        instance.port = request.POST['port']
+        instance.key = request.POST['key']
+        if 'https' in request.POST:
+            instance.https = request.POST['https']
+        else:
+            instance.https = False
+        instance_id = instance.save()
+    else:
+        instance_id = 0
+
     template = loader.get_template('config/instance_add.html')
     context = { 
-        #'interfaces': interfaces,
+        'instance_id': instance_id,
     }   
     return HttpResponse(template.render(context, request))
 

+ 28 - 7
vycenter/vycenter/templates/base.html

@@ -9,14 +9,35 @@
     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
 
     <title>{% block header_title %}{% endblock %} - VyCenter</title>
+
+    <style>
+    body {
+        background-color: black;
+        color: white;
+        
+    }
+    .container {
+        color: black;
+    }
+    .menu { 
+        background-color: #aaa;
+        padding: 5px;
+    }
+    .content { 
+        background-color: #ccc;
+        padding: 5px;
+    }
+
+
+    </style>
   </head>
-  <body>
-    <h1>VyCenter</h1>
+  <body >
+    <h1 align="center">VyCenter</h1>
 
 
-<div class="container" style="background-color: #dcc">
+<div class="container">
   <div class="row">
-    <div class="col-3" style="background-color: #ccc">
+    <div class="col-3 menu">
 
     <h2>Manage VyOS</h2>
     <p><select name="vyos-id"><option>xxxx - 192.168.4.4</option></select></p>
@@ -33,8 +54,8 @@
    
     <h2>Manage VyGUI</h2>
     <ol>
-    {% url 'config:instance-add' as url_config_instance_add %}<li><a href="{{ url_config_instance_add }}/config/instance-add">Add a new instance</a></li>
-    {% url 'config:instance-add' as url_config_instance_add %}<li><a href="{{ url_config_instance_add }}/config/instance">List instances</a></li>
+    <li><a href="{% url 'config:instance-add' %}">Add new instance</a></li>
+    <li><a href="{% url 'config:instances' %}">List instances</a></li>
 
     <li>GUI Users</li>
     <li>GUI Groups</li>
@@ -42,7 +63,7 @@
 
 
     </div>
-    <div class="col">
+    <div class="col content">
         <h2>{% block section_title %}{% endblock %}</h2>
         {% block content %}{% endblock %}
     </div>