Browse Source

IP réservé

Élie Bouttier 8 years ago
parent
commit
4bb6f63568

+ 20 - 0
services/migrations/0014_ipresource_reserved.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11 on 2017-05-06 15:42
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('services', '0013_auto_20170417_1640'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='ipresource',
+            name='reserved',
+            field=models.BooleanField(default=False),
+        ),
+    ]

+ 2 - 0
services/models.py

@@ -18,6 +18,7 @@ class IPResource(models.Model):
     ip = models.GenericIPAddressField(verbose_name='IP')
     mask = models.PositiveIntegerField(validators=[MaxValueValidator(128)],
                                        default=0, verbose_name='Masque')
+    reserved = models.BooleanField(default=False)
 
     @property
     def in_use(self):
@@ -31,6 +32,7 @@ class IPResource(models.Model):
             return None
 
     class Meta:
+        ordering = ['ip']
         verbose_name = 'ressource IP'
         verbose_name_plural = 'ressources IP'
 

+ 1 - 1
services/templates/services/ipresource_list.html

@@ -36,7 +36,7 @@
                 <a href="#" data-toggle="modal" data-target="#confirm-deallocate" data-action="{% url 'deallocate' ip.allocation.pk %}" data-ip="{{ ip }}" data-service="{{ ip.allocation.service }}" class="btn btn-xs btn-danger">
                     <span class="glyphicon glyphicon-remove"></span>&nbsp;Désallouer
                 </a>
-                {% else %}
+                {% elif not ip.reserved %}
                 <a href="{% url 'ip-allocate' ip.pk %}" class="btn btn-xs btn-success">
                     <span class="glyphicon glyphicon-plus"></span>&nbsp;Allouer
                 </a>

+ 4 - 2
services/views.py

@@ -53,7 +53,7 @@ class ServiceAllocate(PermissionRequiredMixin, CreateView):
         kwargs['initial'].update({'service': service.pk})
         form = self.get_form_class()(**kwargs)
         form.fields['service'].disabled = True
-        form.fields['resource'].queryset = IPResource.objects.exclude(get_active_filter('allocation'))
+        form.fields['resource'].queryset = IPResource.objects.filter(reserved=False).exclude(get_active_filter('allocation'))
         return form
 
     def get_success_url(self):
@@ -107,7 +107,9 @@ class IPResourceAllocate(PermissionRequiredMixin, CreateView):
     def get(self, request, *args, **kwargs):
         resource = get_object_or_404(IPResource, pk=self.kwargs['pk'])
         if resource.in_use:
-            return HttpResponseGone("Cette IP est déjà alloué !")
+            return HttpResponseGone("Cette IP est déjà allouée !")
+        if resource.reserved:
+            return HttpResponseGone("Cette IP est réservée !")
         return super().get(request, *args, **kwargs)
 
     def get_form(self):