mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-08-19 13:43:40 +00:00
Attribut ipv6 sur les interfaces
This commit is contained in:
parent
12fe768754
commit
5c9c9c3a29
9 changed files with 71 additions and 7 deletions
|
@ -142,7 +142,7 @@ class DelMachineTypeForm(Form):
|
|||
class IpTypeForm(ModelForm):
|
||||
class Meta:
|
||||
model = IpType
|
||||
fields = ['type','extension','need_infra','domaine_ip_start','domaine_ip_stop', 'vlan']
|
||||
fields = ['type','extension','need_infra','domaine_ip_start','domaine_ip_stop', 'prefix_v6', 'vlan']
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -151,7 +151,7 @@ class IpTypeForm(ModelForm):
|
|||
|
||||
class EditIpTypeForm(IpTypeForm):
|
||||
class Meta(IpTypeForm.Meta):
|
||||
fields = ['extension','type','need_infra', 'vlan']
|
||||
fields = ['extension','type','need_infra', 'prefix_v6', 'vlan']
|
||||
|
||||
class DelIpTypeForm(Form):
|
||||
iptypes = forms.ModelMultipleChoiceField(queryset=IpType.objects.all(), label="Types d'ip actuelles", widget=forms.CheckboxSelectMultiple)
|
||||
|
|
20
machines/migrations/0059_iptype_prefix_v6.py
Normal file
20
machines/migrations/0059_iptype_prefix_v6.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-10-02 16:33
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machines', '0058_auto_20171002_0350'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='iptype',
|
||||
name='prefix_v6',
|
||||
field=models.GenericIPAddressField(blank=True, null=True, protocol='IPv6'),
|
||||
),
|
||||
]
|
|
@ -70,6 +70,7 @@ class IpType(models.Model):
|
|||
need_infra = models.BooleanField(default=False)
|
||||
domaine_ip_start = models.GenericIPAddressField(protocol='IPv4')
|
||||
domaine_ip_stop = models.GenericIPAddressField(protocol='IPv4')
|
||||
prefix_v6 = models.GenericIPAddressField(protocol='IPv6', null=True, blank=True)
|
||||
vlan = models.ForeignKey('Vlan', on_delete=models.PROTECT, blank=True, null=True)
|
||||
|
||||
@cached_property
|
||||
|
@ -122,6 +123,9 @@ class IpType(models.Model):
|
|||
for element in IpType.objects.all().exclude(pk=self.pk):
|
||||
if not self.ip_set.isdisjoint(element.ip_set):
|
||||
raise ValidationError("Le range indiqué n'est pas disjoint des ranges existants")
|
||||
# On formate le prefix v6
|
||||
if self.prefix_v6:
|
||||
self.prefix_v6 = str(IPNetwork(self.prefix_v6 + '/64').network)
|
||||
return
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
@ -218,7 +222,6 @@ class Interface(models.Model):
|
|||
PRETTY_NAME = "Interface"
|
||||
|
||||
ipv4 = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
|
||||
#ipv6 = models.GenericIPAddressField(protocol='IPv6', null=True)
|
||||
mac_address = MACAddressField(integer=False, unique=True)
|
||||
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
|
||||
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
|
||||
|
@ -232,6 +235,18 @@ class Interface(models.Model):
|
|||
user = self.machine.user
|
||||
return machine.active and user.has_access()
|
||||
|
||||
|
||||
@cached_property
|
||||
def ipv6_object(self):
|
||||
if self.type.ip_type.prefix_v6:
|
||||
return EUI(self.mac_address).ipv6(IPNetwork(self.type.ip_type.prefix_v6).network)
|
||||
else:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def ipv6(self):
|
||||
return str(self.ipv6_object)
|
||||
|
||||
def mac_bare(self):
|
||||
return str(EUI(self.mac_address, dialect=mac_bare)).lower()
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th>Nécessite l'autorisation infra</th>
|
||||
<th>Début</th>
|
||||
<th>Fin</th>
|
||||
<th>Préfixe v6</th>
|
||||
<th>Sur vlan</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
|
@ -42,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<td>{{ type.need_infra }}</td>
|
||||
<td>{{ type.domaine_ip_start }}</td>
|
||||
<td>{{ type.domaine_ip_stop }}</td>
|
||||
<td>{{ type.prefix_v6 }}</td>
|
||||
<td>{{ type.vlan }}</td>
|
||||
<td class="text-right">
|
||||
{% if is_infra %}
|
||||
|
|
|
@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th>Nom dns</th>
|
||||
<th>Type</th>
|
||||
<th>Mac</th>
|
||||
<th>Ipv4</th>
|
||||
<th>IP</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -74,7 +74,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
</td>
|
||||
<td>{{ interface.type }}</td>
|
||||
<td>{{ interface.mac_address }}</td>
|
||||
<td>{{ interface.ipv4 }}</td>
|
||||
<td>{{ interface.ipv4 }}
|
||||
{{ interface.ipv6 }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="editioninterface" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
|
|
20
preferences/migrations/0020_optionalmachine_ipv6.py
Normal file
20
preferences/migrations/0020_optionalmachine_ipv6.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-10-02 16:14
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('preferences', '0019_remove_optionaltopologie_mac_autocapture'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='optionalmachine',
|
||||
name='ipv6',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -45,6 +45,7 @@ class OptionalMachine(models.Model):
|
|||
password_machine = models.BooleanField(default=False)
|
||||
max_lambdauser_interfaces = models.IntegerField(default=10)
|
||||
max_lambdauser_aliases = models.IntegerField(default=10)
|
||||
ipv6 = models.BooleanField(default=False)
|
||||
|
||||
class OptionalTopologie(models.Model):
|
||||
PRETTY_NAME = "Options topologie"
|
||||
|
|
|
@ -72,6 +72,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<th>Alias dns autorisé par utilisateur</th>
|
||||
<td>{{ machineoptions.max_lambdauser_aliases }}</td>
|
||||
<th>Support de l'ipv6</th>
|
||||
<td>{{ machineoptions.ipv6 }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h4>Préférences topologie</h4>
|
||||
|
|
|
@ -23,10 +23,11 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from machines.models import Interface, Machine
|
||||
from preferences.models import GeneralOption
|
||||
from preferences.models import GeneralOption, OptionalMachine
|
||||
|
||||
def context_user(request):
|
||||
general_options, created = GeneralOption.objects.get_or_create()
|
||||
machine_options, created = OptionalMachine.objects.get_or_create()
|
||||
user = request.user
|
||||
if user.is_authenticated():
|
||||
interfaces = user.user_interfaces()
|
||||
|
@ -54,4 +55,5 @@ def context_user(request):
|
|||
'is_admin' : is_admin,
|
||||
'interfaces': interfaces,
|
||||
'site_name': general_options.site_name,
|
||||
'ipv6_enabled' : machine_options.ipv6,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue