Commit 8a93e0db authored by Brandon Dunn's avatar Brandon Dunn
Browse files

added new list and update views

parent 2d3935f7
{
"python.pythonPath": "/usr/local/bin/python3",
"python.pythonPath": "/usr/bin/python3",
"python.linting.pylintEnabled": false,
"python.linting.enabled": false,
"python.linting.pylamaEnabled": true
......
# Generated by Django 2.2 on 2019-05-05 17:05
# Generated by Django 2.2 on 2019-05-07 16:56
from django.conf import settings
from django.db import migrations, models
......@@ -21,6 +21,13 @@ class Migration(migrations.Migration):
('adapter_name', models.CharField(default='Adapter', max_length=50)),
],
),
migrations.CreateModel(
name='Host',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('host_name', models.CharField(default='Host', max_length=256)),
],
),
migrations.CreateModel(
name='Preamble',
fields=[
......@@ -37,27 +44,28 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name='Record',
name='Role',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('record_type', models.CharField(choices=[('A', 'A'), ('AAAA', 'AAAA'), ('ALIAS', 'ALIAS'), ('cname', 'cname'), ('MX', 'MX'), ('NS', 'NS'), ('PTR', 'PTR'), ('SOA', 'SOA')], max_length=12)),
('role_name', models.CharField(default='Role', max_length=50)),
('user', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Role',
name='Subnet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('role_name', models.CharField(default='Role', max_length=50)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='Role', to=settings.AUTH_USER_MODEL)),
('subnet_name', models.CharField(default='Sub', max_length=128)),
('preamble', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Subnet', to='ipam.Preamble')),
('role', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Subnet', to='ipam.Role')),
],
),
migrations.CreateModel(
name='Subnet',
name='Record',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subnet_name', models.CharField(default='Sub', max_length=128)),
('preamble', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Subnet', to='ipam.Preamble')),
('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Subnet', to='ipam.Role')),
('record_type', models.CharField(choices=[('A', 'A'), ('AAAA', 'AAAA'), ('ALIAS', 'ALIAS'), ('cname', 'cname'), ('MX', 'MX'), ('NS', 'NS'), ('PTR', 'PTR'), ('SOA', 'SOA')], max_length=12)),
('host', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Host', to='ipam.Host')),
],
),
migrations.CreateModel(
......@@ -65,7 +73,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mac', models.CharField(max_length=18)),
('adapter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Mac', to='ipam.Adapter')),
('adapter', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Mac', to='ipam.Adapter')),
],
),
migrations.CreateModel(
......@@ -74,21 +82,13 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ipv4', models.CharField(blank=True, max_length=12, null=True)),
('ipv6', models.CharField(blank=True, max_length=40, null=True)),
('mac_addr', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='IP', to='ipam.Mac_Addr')),
('mac_addr', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='IP', to='ipam.Mac_Addr')),
('subnet', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='IP', to='ipam.Subnet')),
],
),
migrations.CreateModel(
name='Host',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('host_name', models.CharField(default='Host', max_length=256)),
('record', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Host', to='ipam.Record')),
],
),
migrations.AddField(
model_name='adapter',
name='host',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Adapter', to='ipam.Host'),
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Adapter', to='ipam.Host'),
),
]
# Generated by Django 2.2 on 2019-05-05 17:38
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('ipam', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='role',
name='user',
),
migrations.AddField(
model_name='role',
name='user',
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
),
]
# Generated by Django 2.2 on 2019-05-05 17:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('ipam', '0002_auto_20190505_1238'),
]
operations = [
migrations.AlterField(
model_name='subnet',
name='role',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Subnet', to='ipam.Role'),
),
]
# Generated by Django 2.2 on 2019-05-05 17:49
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('ipam', '0003_auto_20190505_1243'),
]
operations = [
migrations.AlterField(
model_name='adapter',
name='host',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Adapter', to='ipam.Host'),
),
migrations.AlterField(
model_name='ip',
name='mac_addr',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='IP', to='ipam.Mac_Addr'),
),
migrations.AlterField(
model_name='mac_addr',
name='adapter',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Mac', to='ipam.Adapter'),
),
migrations.AlterField(
model_name='subnet',
name='preamble',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Subnet', to='ipam.Preamble'),
),
migrations.AlterField(
model_name='subnet',
name='role',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Subnet', to='ipam.Role'),
),
]
# Generated by Django 2.2 on 2019-05-05 17:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ipam', '0004_auto_20190505_1249'),
]
operations = [
migrations.RemoveField(
model_name='host',
name='record',
),
migrations.AddField(
model_name='host',
name='record',
field=models.ManyToManyField(to='ipam.Record'),
),
]
......@@ -2,6 +2,11 @@ from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Host(models.Model):
host_name = models.CharField(max_length=256, default='Host')
def __str__(self):
return self.host_name + ', id: ' + str(self.id)
class Record(models.Model):
RECORD_TYPES = (('A', 'A'), ('AAAA', 'AAAA'), ('ALIAS', 'ALIAS'), ('cname', 'cname'),
('MX', 'MX'), ('NS', 'NS'), ('PTR', "PTR"), ('SOA', 'SOA'))
......@@ -9,32 +14,27 @@ class Record(models.Model):
max_length=12,
choices=RECORD_TYPES,
)
host = models.ForeignKey(Host, related_name='Host', on_delete=models.CASCADE)
def __str__(self):
return self.record_type
class Host(models.Model):
record = models.ManyToManyField(Record)
host_name = models.CharField(max_length=256, default='Host')
def __str__(self):
return self.host_name
return self.record_type + ', id: ' + str(self.id)
class Adapter(models.Model):
host = models.OneToOneField(Host, related_name='Adapter', on_delete=models.CASCADE)
adapter_name = models.CharField(max_length=50, default='Adapter')
def __str__(self):
return self.adapter_name
return self.adapter_name + ', id: ' + str(self.id)
class Mac_Addr(models.Model):
adapter = models.OneToOneField(Adapter, related_name='Mac',on_delete=models.CASCADE)
mac = models.CharField(max_length=18)
def __str__(self):
return self.mac
return self.mac + ', id: ' + str(self.id)
class Role(models.Model):
user = models.ManyToManyField(User)
role_name = models.CharField(max_length=50, default='Role')
def __str__(self):
return self.role_name
return self.role_name + ', id: ' + str(self.id)
class Preamble(models.Model):
pa_subnet_name = models.CharField(max_length=50, default='pre')
......@@ -47,14 +47,14 @@ class Preamble(models.Model):
refresh = models.CharField(max_length=50)
nxdomain_ttl = models.CharField(max_length=50)
def __str__(self):
return self.pa_subnet_name
return self.pa_subnet_name + ', id: ' + str(self.id)
class Subnet(models.Model):
preamble = models.OneToOneField(Preamble, related_name='Subnet',on_delete=models.CASCADE)
role = models.OneToOneField(Role, related_name='Subnet', on_delete=models.SET_NULL, blank=True, null=True)
subnet_name = models.CharField(max_length=128, default='Sub')
def __str__(self):
return self.subnet_name
return self.subnet_name + ', id: ' + str(self.id)
class IP(models.Model):
mac_addr = models.OneToOneField(Mac_Addr, related_name='IP', on_delete=models.SET_NULL, blank=True, null=True)
......@@ -63,6 +63,6 @@ class IP(models.Model):
ipv6 = models.CharField(max_length=40, blank=True, null=True)
def __str__(self):
if self.ipv4 is not None:
return self.ipv4
return self.ipv4 + ', id: ' + str(self.id)
if self.ipv6 is not None:
return self.ipv6
\ No newline at end of file
return self.ipv6 + ', id: ' + str(self.id)
......@@ -41,4 +41,10 @@ class IPSerializer(serializers.ModelSerializer):
class Meta:
model = IP
fields = '__all__'
depth = 10
depth = 5
class SubentSerializer(serializers.ModelSerializer):
class Meta:
model = Subnet
fields = '__all__'
depth = 3
......@@ -17,6 +17,20 @@ class ListAllIps(generics.ListAPIView):
# permission_classes = (permissions.IsAuthenticated)
serializer_class = serializers.IPSerializer
class ListSubnet(generics.ListAPIView):
queryset = models.Subnet.objects.all()
#permission_class = (permissions.IsAuthenticated)
serializer_class = serializers.SubnetSerializer
class ListRecords(generics.ListAPIView):
serializer_class = serializers.RecordSerializer
def get_queryset(self):
queryset = models.Records.objects.all()
hostid = self.request.query_params.get('host')
queryset = models.Record.objects.filter(host==hostid)
return queryset
class ListIPRange(generics.ListAPIView):
queryset = models.IP.objects.all()
# permission_classes = (permissions.IsAuthenticated)
......@@ -53,9 +67,9 @@ class UpdateIp(generics.UpdateAPIView):
serializer_class = serializers.IPSerializer
class DeleteHost(generics.DestroyAPIView):
queryset = models.Record.objects.all()
queryset = models.Host.objects.all()
# permission_classes - (permissions.IsAuthenticated)
serializer_class = serializers.RecordSerializer
serializer_class = serializers.HostSerializer
class UpdateRecord(generics.UpdateAPIView):
queryset = models.Record.objects.all()
......@@ -75,4 +89,4 @@ class UpdateAdapter(generics.UpdateAPIView):
class UpdateMac(generics.UpdateAPIView):
queryset = models.Mac_Addr.objects.all()
# permission_classes = (permissions.IsAuthenticated)
serializer_class = serializers.MacAddrSerializer
\ No newline at end of file
serializer_class = serializers.MacAddrSerializer
......@@ -6,6 +6,8 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ipam/listavailaleips/', view=views.ListAvailaleIPs.as_view()),
url(r'^ipam/listallips/', view=views.ListAllIps.as_view()),
url(r'^ipam/listsubnets/', view=views.ListSubnet.as_view()),
url(r'^ipam/listrecords/', view=views.ListRecords.as_view()),
url(r'^ipam/createrecord/', view=views.CreateRecord.as_view()),
url(r'^ipam/createhost/', view=views.CreateHost.as_view()),
url(r'^ipam/createadapter/', view=views.CreateAdapter.as_view()),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment