mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-09 03:16:25 +00:00
Crée spécific role, l'utilise pour get l'ip du serveur des config switchs
This commit is contained in:
parent
35eb945404
commit
5dc59035f5
4 changed files with 79 additions and 0 deletions
|
@ -622,6 +622,50 @@ class ServiceRegenSerializer(NamespacedHMSerializer):
|
||||||
'api_url': {'view_name': 'serviceregen-detail'}
|
'api_url': {'view_name': 'serviceregen-detail'}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Switches et ports
|
||||||
|
|
||||||
|
class InterfaceVlanSerializer(NamespacedHMSerializer):
|
||||||
|
domain = serializers.CharField(read_only=True)
|
||||||
|
ipv4 = serializers.CharField(read_only=True)
|
||||||
|
ipv6 = Ipv6ListSerializer(read_only=True, many=True)
|
||||||
|
vlan_id = serializers.IntegerField(source='type.ip_type.vlan.vlan_id', read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = machines.Interface
|
||||||
|
fields = ('ipv4', 'ipv6', 'domain', 'vlan_id')
|
||||||
|
|
||||||
|
class InterfaceRoleSerializer(NamespacedHMSerializer):
|
||||||
|
interface = InterfaceVlanSerializer(source='machine.interface_set', read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = machines.Interface
|
||||||
|
fields = ('interface',)
|
||||||
|
|
||||||
|
|
||||||
|
class RoleSerializer(NamespacedHMSerializer):
|
||||||
|
"""Serialize `machines.models.OuverturePort` objects.
|
||||||
|
"""
|
||||||
|
servers = InterfaceRoleSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = machines.Role
|
||||||
|
fields = ('role_type', 'servers', 'specific_role')
|
||||||
|
|
||||||
|
|
||||||
|
class VlanPortSerializer(NamespacedHMSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = machines.Vlan
|
||||||
|
fields = ('vlan_id', 'name')
|
||||||
|
|
||||||
|
|
||||||
|
class ProfilSerializer(NamespacedHMSerializer):
|
||||||
|
vlan_untagged = VlanSerializer(read_only=True)
|
||||||
|
vlan_tagged = VlanPortSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = topologie.PortProfile
|
||||||
|
fields = ('name', 'profil_default', 'vlan_untagged', 'vlan_tagged', 'radius_type', 'radius_mode', 'speed', 'mac_limit', 'flow_control', 'dhcp_snooping', 'dhcpv6_snooping', 'arp_protect', 'ra_guard', 'loop_protect', 'vlan_untagged', 'vlan_tagged')
|
||||||
|
|
||||||
|
|
||||||
# LOCAL EMAILS
|
# LOCAL EMAILS
|
||||||
|
|
||||||
|
|
20
machines/migrations/0094_role_specific_role.py
Normal file
20
machines/migrations/0094_role_specific_role.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-07-11 16:49
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('machines', '0093_merge_20180710_0226'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='role',
|
||||||
|
name='specific_role',
|
||||||
|
field=models.CharField(blank=True, choices=[('dhcp-server', 'dhcp-server'), ('switch-conf-server', 'switch-conf-server'), ('dns-recursif-server', 'dns-recursif-server'), ('ntp-server', 'ntp-server'), ('radius-server', 'radius-server'), ('ntp-server', 'ntp-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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1478,6 +1478,19 @@ class Role(RevMixin, AclMixin, models.Model):
|
||||||
("view_role", "Peut voir un objet service"),
|
("view_role", "Peut voir un objet service"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_instance(cls, machineid, *_args, **_kwargs):
|
||||||
|
"""Get the Machine instance with machineid.
|
||||||
|
:param userid: The id
|
||||||
|
:return: The user
|
||||||
|
"""
|
||||||
|
return cls.objects.get(pk=machineid)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def interface_for_roletype(cls, roletype):
|
||||||
|
"""Return interfaces for a roletype"""
|
||||||
|
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Role, self).save(*args, **kwargs)
|
super(Role, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom du role</th>
|
<th>Nom du role</th>
|
||||||
|
<th>Role spécifique</th>
|
||||||
<th>Serveurs inclus</th>
|
<th>Serveurs inclus</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
@ -36,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% for role in role_list %}
|
{% for role in role_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ role.role_type }}</td>
|
<td>{{ role.role_type }}</td>
|
||||||
|
<td>{{ role.specific_role }}</td>
|
||||||
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{% can_edit role %}
|
{% can_edit role %}
|
||||||
|
|
Loading…
Reference in a new issue