8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Affectation de configuration de ports à une interface.

This commit is contained in:
LEVY-FALK Hugo 2017-10-02 00:08:07 +02:00 committed by root
parent ad67b9cbd6
commit b57fed7423
6 changed files with 54 additions and 6 deletions

View file

@ -52,14 +52,14 @@ class BaseEditMachineForm(EditMachineForm):
class EditInterfaceForm(ModelForm):
class Meta:
model = Interface
fields = '__all__'
# fields = '__all__'
exclude = ['port_lists']
def __init__(self, *args, **kwargs):
super(EditInterfaceForm, self).__init__(*args, **kwargs)
self.fields['mac_address'].label = 'Adresse mac'
self.fields['type'].label = 'Type de machine'
self.fields['type'].empty_label = "Séléctionner un type de machine"
self.fields['port_lists'].label = "Configuration des ports"
if "machine" in self.fields:
self.fields['machine'].queryset = Machine.objects.all().select_related('user')
@ -232,10 +232,10 @@ class VlanForm(ModelForm):
class DelVlanForm(Form):
vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple)
class EditPortForm(ModelForm):
class EditPortConfigForm(ModelForm):
class Meta:
model = Port
fields = '__all__'
model = Interface
fields = ['port_lists']
class EditPortListForm(ModelForm):
class Meta:

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-01 15:27
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0060_port_io'),
]
operations = [
migrations.RemoveField(
model_name='portlist',
name='interfaces',
),
migrations.AddField(
model_name='interface',
name='port_lists',
field=models.ManyToManyField(to='machines.PortList'),
),
]

View file

@ -279,6 +279,9 @@ class Interface(models.Model):
domain = None
return str(domain)
def has_private_ip(self):
return IPAddress(str(self.ipv4)).is_private()
class Domain(models.Model):
PRETTY_NAME = "Domaine dns"

View file

@ -91,6 +91,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="glyphicon glyphicon-edit"></i> Gerer les alias
</a>
</li>
<li>
<a href="{% url 'machines:port-config' interface.id%}">
<i class="glyphicon glyphicon-edit"></i> Gerer la configuration des ports
</a>
</li>
<li>
<a href="{% url 'machines:history' 'interface' interface.id %}">
<i class="glyphicon glyphicon-time"></i> Historique

View file

@ -96,4 +96,6 @@ urlpatterns = [
url(r'^edit_portlist/(?P<pk>[0-9]+)$', views.edit_portlist, name='edit-portlist'),
url(r'^del_portlist/(?P<pk>[0-9]+)$', views.del_portlist, name='del-portlist'),
url(r'^add_portlist/$', views.add_portlist, name='add-portlist'),
url(r'^port_config/(?P<pk>[0-9]+)$', views.configure_ports, name='port-config'),
]

View file

@ -48,7 +48,7 @@ from reversion.models import Version
import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
from .forms import EditIpTypeForm, IpTypeForm, DelIpTypeForm, DomainForm, AliasForm, DelAliasForm, NsForm, DelNsForm, TextForm, DelTextForm, MxForm, DelMxForm, VlanForm, DelVlanForm, ServiceForm, DelServiceForm, NasForm, DelNasForm
from .forms import EditPortListForm, EditPortForm
from .forms import EditPortListForm, EditPortConfigForm
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text, PortList, Port
from users.models import User
from users.models import all_has_access
@ -993,6 +993,20 @@ def add_portlist(request):
return redirect("/machines/index_portlist/")
return form({'machineform' : port_list}, 'machines/machine.html', request)
@login_required
@permission_required('cableur')
def configure_ports(request, pk):
try:
interface_instance = Interface.objects.get(pk=pk)
except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" )
return redirect("/machines")
interface = EditPortConfigForm(request.POST or None, instance=interface_instance)
if interface.is_valid():
interface.save()
messages.success(request, "Configuration des ports mise à jour.")
return redirect("/machines/")
return form({'interfaceform' : interface}, 'machines/machine.html', request)
""" Framework Rest """