8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Merge branch 'fix_sw_conf' into 'dev'

Fix sw conf

See merge request federez/re2o!379
This commit is contained in:
klafyvel 2019-01-03 01:09:27 +01:00
commit 05cdb751e4
16 changed files with 545 additions and 5 deletions

View file

@ -811,7 +811,8 @@ class SwitchPortSerializer(serializers.ModelSerializer):
model = topologie.Switch
fields = ('short_name', 'model', 'switchbay', 'ports', 'ipv4', 'ipv6',
'interfaces_subnet', 'interfaces6_subnet', 'automatic_provision', 'rest_enabled',
'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value')
'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value',
'list_modules')
# LOCAL EMAILS

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2019-01-02 23:45
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0097_extension_dnssec'),
]
operations = [
migrations.AlterField(
model_name='role',
name='specific_role',
field=models.CharField(blank=True, choices=[('dhcp-server', 'DHCP server'), ('switch-conf-server', 'Switches configuration server'), ('dns-recursif-server', 'Recursive DNS server'), ('dns-recursive-server', 'Recursive DNS server'), ('ntp-server', 'NTP server'), ('radius-server', 'RADIUS server'), ('log-server', 'Log server'), ('ldap-master-server', 'LDAP master server'), ('ldap-backup-server', 'LDAP backup server'), ('smtp-server', 'SMTP server'), ('postgresql-server', 'postgreSQL server'), ('mysql-server', 'mySQL server'), ('sql-client', 'SQL client'), ('gateway', 'Gateway')], max_length=32, null=True),
),
]

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2019-01-02 23:45
from __future__ import unicode_literals
from django.db import migrations, models
def migrate(apps, schema_editor):
Role = apps.get_model('machines', 'Role')
for role in Role.objects.filter(specific_role='dns-recursif-server'):
role.specific_role = 'dns-recursive-server'
role.save()
class Migration(migrations.Migration):
dependencies = [
('machines', '0098_auto_20190102_1745'),
]
operations = [
migrations.RunPython(migrate),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2019-01-02 23:53
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0099_role_recursive_dns'),
]
operations = [
migrations.AlterField(
model_name='role',
name='specific_role',
field=models.CharField(blank=True, choices=[('dhcp-server', 'DHCP server'), ('switch-conf-server', 'Switches configuration server'), ('dns-recursive-server', 'Recursive DNS server'), ('ntp-server', 'NTP server'), ('radius-server', 'RADIUS server'), ('log-server', 'Log server'), ('ldap-master-server', 'LDAP master server'), ('ldap-backup-server', 'LDAP backup server'), ('smtp-server', 'SMTP server'), ('postgresql-server', 'postgreSQL server'), ('mysql-server', 'mySQL server'), ('sql-client', 'SQL client'), ('gateway', 'Gateway')], max_length=32, null=True),
),
]

View file

@ -1612,7 +1612,7 @@ class Role(RevMixin, AclMixin, models.Model):
ROLE = (
('dhcp-server', _("DHCP server")),
('switch-conf-server', _("Switches configuration server")),
('dns-recursif-server', _("Recursive DNS server")),
('dns-recursive-server', _("Recursive DNS server")),
('ntp-server', _("NTP server")),
('radius-server', _("RADIUS server")),
('log-server', _("Log server")),

View file

@ -278,12 +278,13 @@ class OptionalTopologie(AclMixin, PreferencesModel):
log_servers = Role.all_interfaces_for_roletype("log-server").filter(type__ip_type=self.switchs_ip_type)
radius_servers = Role.all_interfaces_for_roletype("radius-server").filter(type__ip_type=self.switchs_ip_type)
dhcp_servers = Role.all_interfaces_for_roletype("dhcp-server")
dns_recursive_servers = Role.all_interfaces_for_roletype("dns-recursive-server").filter(type__ip_type=self.switchs_ip_type)
subnet = None
subnet6 = None
if self.switchs_ip_type:
subnet = self.switchs_ip_type.ip_set_full_info
subnet6 = self.switchs_ip_type.ip6_set_full_info
return {'ntp_servers': return_ips_dict(ntp_servers), 'log_servers': return_ips_dict(log_servers), 'radius_servers': return_ips_dict(radius_servers), 'dhcp_servers': return_ips_dict(dhcp_servers), 'subnet': subnet, 'subnet6': subnet6}
return {'ntp_servers': return_ips_dict(ntp_servers), 'log_servers': return_ips_dict(log_servers), 'radius_servers': return_ips_dict(radius_servers), 'dhcp_servers': return_ips_dict(dhcp_servers), 'dns_recursive_servers': return_ips_dict(dns_recursive_servers), 'subnet': subnet, 'subnet6': subnet6}
@cached_property
def provision_switchs_enabled(self):

View file

@ -55,6 +55,8 @@ from .models import (
SwitchBay,
Building,
PortProfile,
ModuleSwitch,
ModuleOnSwitch,
)
@ -269,3 +271,23 @@ class EditPortProfileForm(FormRevMixin, ModelForm):
prefix=prefix,
**kwargs)
class EditModuleForm(FormRevMixin, ModelForm):
"""Add and edit module instance"""
class Meta:
model = ModuleSwitch
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditSwitchModuleForm(FormRevMixin, ModelForm):
"""Add/edit a switch to a module"""
class Meta:
model = ModuleOnSwitch
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditSwitchModuleForm, self).__init__(*args, prefix=prefix, **kwargs)

View file

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-12-30 17:19
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('topologie', '0066_modelswitch_commercial_name'),
]
operations = [
migrations.CreateModel(
name='ModuleOnSwitch',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slot', models.CharField(help_text='Slot on switch', max_length=15, verbose_name='Slot')),
],
options={
'verbose_name': 'link between switchs and modules',
'permissions': (('view_moduleonswitch', 'Can view a moduleonswitch object'),),
},
bases=(re2o.mixins.AclMixin, re2o.mixins.RevMixin, models.Model),
),
migrations.CreateModel(
name='ModuleSwitch',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reference', models.CharField(help_text='Reference of a module', max_length=255, verbose_name='Module reference')),
('comment', models.CharField(blank=True, help_text='Comment', max_length=255, null=True, verbose_name='Comment')),
],
options={
'verbose_name': 'Module of a switch',
'permissions': (('view_moduleswitch', 'Can view a module object'),),
},
bases=(re2o.mixins.AclMixin, re2o.mixins.RevMixin, models.Model),
),
migrations.AddField(
model_name='modelswitch',
name='is_itself_module',
field=models.BooleanField(default=False, help_text='Does the switch, itself, considered as a module'),
),
migrations.AddField(
model_name='modelswitch',
name='is_modular',
field=models.BooleanField(default=False, help_text='Is this switch model modular'),
),
migrations.AddField(
model_name='moduleonswitch',
name='module',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='topologie.ModuleSwitch'),
),
migrations.AddField(
model_name='moduleonswitch',
name='switch',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='topologie.Switch'),
),
migrations.AlterUniqueTogether(
name='moduleonswitch',
unique_together=set([('slot', 'switch')]),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2019-01-02 23:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('topologie', '0067_auto_20181230_1819'),
]
operations = [
migrations.AlterField(
model_name='modelswitch',
name='is_itself_module',
field=models.BooleanField(default=False, help_text='Is the switch, itself, considered as a module'),
),
]

View file

@ -252,6 +252,7 @@ class Switch(AclMixin, Machine):
help_text='Provision automatique de ce switch',
)
class Meta:
unique_together = ('stack', 'stack_member_id')
permissions = (
@ -367,6 +368,17 @@ class Switch(AclMixin, Machine):
"""Return dict ip6:subnet for all ipv6 of the switch"""
return dict((str(interface.ipv6().first()), interface.type.ip_type.ip6_set_full_info) for interface in self.interface_set.all())
@cached_property
def list_modules(self):
"""Return modules of that switch, list of dict (rank, reference)"""
modules = []
if getattr(self.model, 'is_modular', None):
if self.model.is_itself_module:
modules.append((1, self.model.reference))
for module_of_self in self.moduleonswitch_set.all():
modules.append((module_of_self.slot, module_of_self.module.reference))
return modules
def __str__(self):
return str(self.get_name)
@ -389,6 +401,14 @@ class ModelSwitch(AclMixin, RevMixin, models.Model):
null=True,
blank=True
)
is_modular = models.BooleanField(
default=False,
help_text=_("Is this switch model modular"),
)
is_itself_module = models.BooleanField(
default=False,
help_text=_("Is the switch, itself, considered as a module"),
)
class Meta:
permissions = (
@ -404,6 +424,53 @@ class ModelSwitch(AclMixin, RevMixin, models.Model):
return str(self.constructor) + ' ' + self.reference
class ModuleSwitch(AclMixin, RevMixin, models.Model):
"""A module of a switch"""
reference = models.CharField(
max_length=255,
help_text=_("Reference of a module"),
verbose_name=_("Module reference")
)
comment = models.CharField(
max_length=255,
null=True,
blank=True,
help_text=_("Comment"),
verbose_name=_("Comment")
)
class Meta:
permissions = (
("view_moduleswitch", _("Can view a module object")),
)
verbose_name = _("Module of a switch")
def __str__(self):
return str(self.reference)
class ModuleOnSwitch(AclMixin, RevMixin, models.Model):
"""Link beetween module and switch"""
module = models.ForeignKey('ModuleSwitch', on_delete=models.CASCADE)
switch = models.ForeignKey('Switch', on_delete=models.CASCADE)
slot = models.CharField(
max_length=15,
help_text=_("Slot on switch"),
verbose_name=_("Slot")
)
class Meta:
permissions = (
("view_moduleonswitch", _("Can view a moduleonswitch object")),
)
verbose_name = _("link between switchs and modules")
unique_together = ['slot', 'switch']
def __str__(self):
return 'On slot ' + str(self.slot) + ' of ' + str(self.switch)
class ConstructorSwitch(AclMixin, RevMixin, models.Model):
"""Un constructeur de switch"""

View file

@ -0,0 +1,110 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
{% if module_list.paginator %}
{% include "pagination.html" with list=module_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Reference" %}</th>
<th>{% trans "Comment" %}</th>
<th>{% trans "Switchs" %}</th>
<th></th>
</tr>
</thead>
{% for module in module_list %}
<tr>
<td>{{ module.reference }}</td>
<td>{{ module.comment }}</td>
<td>
{% for module_switch in module.moduleonswitch_set.all %}
<b>Slot</b> {{ module_switch.slot }} <b>of</b> {{ module_switch.switch }}
{% can_edit module_switch %}
<a class="btn btn-primary btn-xs" role="button" title={% trans "Edit" %} href="{% url 'topologie:edit-module-on' module_switch.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
{% can_delete module_switch %}
<a class="btn btn-danger btn-xs" role="button" title={% trans "Delete" %} href="{% url 'topologie:del-module-on' module_switch.id %}">
<i class="fa fa-trash"></i>
</a>
{% acl_end %}
<br>
{% endfor %}
</td>
<td class="text-right">
{% can_edit module %}
<a class="btn btn-primary btn-sm" role="button" title={% trans "Add" %} href="{% url 'topologie:add-module-on' %}">
<i class="fa fa-plus"></i>
</a>
<a class="btn btn-primary btn-sm" role="button" title={% trans "Edit" %} href="{% url 'topologie:edit-module' module.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
{% history_button module %}
{% can_delete module %}
<a class="btn btn-danger btn-sm" role="button" title={% trans "Delete" %} href="{% url 'topologie:del-module' module.id %}">
<i class="fa fa-trash"></i>
</a>
{% acl_end %}
</td>
</tr>
{% endfor %}
</table>
{% if module_list.paginator %}
{% include "pagination.html" with list=module_list %}
{% endif %}
<h4>{% trans "All modular switchs" %}</h4>
<table class="table table-striped">
<thead>
<th>{% trans "Switch" %}</th>
<th>{% trans "Reference" %}</th>
<th>{% trans "Slot" %}</th>
<tbody>
{% for switch in modular_switchs %}
{% if switch.list_modules %}
<tr class="info">
<td colspan="4">
{{ switch }}
</td>
</tr>
{% for module in switch.list_modules %}
<tr>
<td></td>
<td>{{ module.1 }}</td>
<td>{{ module.0 }}</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</table>

View file

@ -0,0 +1,43 @@
{% extends "topologie/sidebar.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load bootstrap3 %}
{% load acl %}
{% load i18n %}
{% block title %}{% trans "Topology" %}{% endblock %}
{% block content %}
<h2>{% trans "Modules of switchs" %}</h2>
{% can_create ModuleSwitch %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:add-module' %}"><i class="fa fa-plus"></i>{% trans " Add a module" %}</a>
<hr>
{% acl_end %}
{% include "topologie/aff_modules.html" with module_list=module_list modular_switchs=modular_switchs %}
<br />
<br />
<br />
{% endblock %}

View file

@ -33,6 +33,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<a class="list-group-item list-group-item-info" href="{% url "topologie:index" %}">
<i class="fa fa-microchip"></i>
{% trans "Switches" %}
</a>
<a class="list-group-item list-group-item-info" href="{% url "topologie:index-module" %}">
<i class="fa fa-microchip"></i>
{% trans "Switches modules" %}
</a>
<a class="list-group-item list-group-item-info" href="{% url "topologie:index-port-profile" %}">
<i class="fa fa-cogs"></i>

View file

@ -37,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}
<form class="form" method="post">
{% csrf_token %}
{% massive_bootstrap_form topoform 'room,related,machine_interface,members,vlan_tagged' %}
{% massive_bootstrap_form topoform 'room,related,machine_interface,members,vlan_tagged,switch' %}
{% bootstrap_button action_name icon='ok' button_class='btn-success' %}
</form>
<br />

View file

@ -123,4 +123,15 @@ urlpatterns = [
url(r'^edit_vlanoptions/(?P<vlanid>[0-9]+)$',
views.edit_vlanoptions,
name='edit-vlanoptions'),
]
url(r'^add_module/$', views.add_module, name='add-module'),
url(r'^edit_module/(?P<moduleswitchid>[0-9]+)$',
views.edit_module,
name='edit-module'),
url(r'^del_module/(?P<moduleswitchid>[0-9]+)$', views.del_module, name='del-module'),
url(r'^index_module/$', views.index_module, name='index-module'),
url(r'^add_module_on/$', views.add_module_on, name='add-module-on'),
url(r'^edit_module_on/(?P<moduleonswitchid>[0-9]+)$',
views.edit_module_on,
name='edit-module-on'),
url(r'^del_module_on/(?P<moduleonswitchid>[0-9]+)$', views.del_module_on, name='del-module-on'),
]

View file

@ -86,6 +86,8 @@ from .models import (
Building,
Server,
PortProfile,
ModuleSwitch,
ModuleOnSwitch,
)
from .forms import (
EditPortForm,
@ -102,6 +104,8 @@ from .forms import (
EditSwitchBayForm,
EditBuildingForm,
EditPortProfileForm,
EditModuleForm,
EditSwitchModuleForm,
)
from subprocess import (
@ -316,6 +320,22 @@ def index_model_switch(request):
)
@login_required
@can_view_all(ModuleSwitch)
def index_module(request):
"""Display all modules of switchs"""
module_list = ModuleSwitch.objects.all()
modular_switchs = Switch.objects.filter(model__is_modular=True)
pagination_number = GeneralOption.get_cached_value('pagination_number')
module_list = re2o_paginator(request, module_list, pagination_number)
return render(
request,
'topologie/index_module.html',
{'module_list': module_list,
'modular_switchs': modular_switchs}
)
@login_required
@can_edit(Vlan)
def edit_vlanoptions(request, vlan_instance, **_kwargs):
@ -1048,6 +1068,115 @@ def del_port_profile(request, port_profile, **_kwargs):
)
@login_required
@can_create(ModuleSwitch)
def add_module(request):
""" View used to add a Module object """
module = EditModuleForm(request.POST or None)
if module.is_valid():
module.save()
messages.success(request, _("The module was created."))
return redirect(reverse('topologie:index-module'))
return form(
{'topoform': module, 'action_name': _("Create a module")},
'topologie/topo.html',
request
)
@login_required
@can_edit(ModuleSwitch)
def edit_module(request, module_instance, **_kwargs):
""" View used to edit a Module object """
module = EditModuleForm(request.POST or None, instance=module_instance)
if module.is_valid():
if module.changed_data:
module.save()
messages.success(request, _("The module was edited."))
return redirect(reverse('topologie:index-module'))
return form(
{'topoform': module, 'action_name': _("Edit")},
'topologie/topo.html',
request
)
@login_required
@can_delete(ModuleSwitch)
def del_module(request, module, **_kwargs):
"""Compleete delete a module"""
if request.method == "POST":
try:
module.delete()
messages.success(request, _("The module was deleted."))
except ProtectedError:
messages.error(
request,
(_("The module %s is used by another object, impossible to"
" deleted it.") % module)
)
return redirect(reverse('topologie:index-module'))
return form(
{'objet': module, 'objet_name': _("Module")},
'topologie/delete.html',
request
)
@login_required
@can_create(ModuleOnSwitch)
def add_module_on(request):
"""Add a module to a switch"""
module_switch = EditSwitchModuleForm(request.POST or None)
if module_switch.is_valid():
module_switch.save()
messages.success(request, _("The module added to that switch"))
return redirect(reverse('topologie:index-module'))
return form(
{'topoform': module_switch, 'action_name': _("Create")},
'topologie/topo.html',
request
)
@login_required
@can_edit(ModuleOnSwitch)
def edit_module_on(request, module_instance, **_kwargs):
""" View used to edit a Module object """
module = EditSwitchModuleForm(request.POST or None, instance=module_instance)
if module.is_valid():
if module.changed_data:
module.save()
messages.success(request, _("The module was edited."))
return redirect(reverse('topologie:index-module'))
return form(
{'topoform': module, 'action_name': _("Edit")},
'topologie/topo.html',
request
)
@login_required
@can_delete(ModuleOnSwitch)
def del_module_on(request, module, **_kwargs):
"""Compleete delete a module"""
if request.method == "POST":
try:
module.delete()
messages.success(request, _("The module was deleted."))
except ProtectedError:
messages.error(
request,
(_("The module %s is used by another object, impossible to"
" deleted it.") % module)
)
return redirect(reverse('topologie:index-module'))
return form(
{'objet': module, 'objet_name': _("Module")},
'topologie/delete.html',
request
)
def make_machine_graph():
"""
Create the graph of switchs, machines and access points.