mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-08-19 13:43:40 +00:00
Crée spécific role, l'utilise pour get l'ip du serveur des config switchs
This commit is contained in:
parent
1596550a1e
commit
4ec9008466
6 changed files with 57 additions and 2 deletions
|
@ -670,7 +670,7 @@ class RoleSerializer(NamespacedHMSerializer):
|
|||
|
||||
class Meta:
|
||||
model = machines.Role
|
||||
fields = ('role_type', 'servers')
|
||||
fields = ('role_type', 'servers', 'specific_role')
|
||||
|
||||
|
||||
class VlanPortSerializer(NamespacedHMSerializer):
|
||||
|
|
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),
|
||||
),
|
||||
]
|
|
@ -1533,6 +1533,19 @@ class Role(RevMixin, AclMixin, models.Model):
|
|||
("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):
|
||||
super(Role, self).save(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Nom du role</th>
|
||||
<th>Role spécifique</th>
|
||||
<th>Serveurs inclus</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 %}
|
||||
<tr>
|
||||
<td>{{ role.role_type }}</td>
|
||||
<td>{{ role.specific_role }}</td>
|
||||
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit role %}
|
||||
|
|
|
@ -242,11 +242,27 @@ class OptionalTopologie(AclMixin, PreferencesModel):
|
|||
from topologie.models import Switch
|
||||
return Switch.objects.filter(automatic_provision=True)
|
||||
|
||||
@cached_property
|
||||
def switchs_management_interface(self):
|
||||
"""Return the ip of the interface that the switch have to contact to get it's config"""
|
||||
if self.switchs_ip_type:
|
||||
from machines.models import Role, Interface
|
||||
return Interface.objects.filter(machine__interface__in=Role.interface_for_roletype("switch-conf-server")).filter(type__ip_type=self.switchs_ip_type).first()
|
||||
else:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def switchs_management_interface_ip(self):
|
||||
"""Same, but return the ipv4"""
|
||||
if not self.switchs_management_interface:
|
||||
return None
|
||||
return self.switchs_management_interface.ipv4
|
||||
|
||||
@cached_property
|
||||
def provision_switchs_enabled(self):
|
||||
"""Return true if all settings are ok : switchs on automatic provision,
|
||||
ip_type"""
|
||||
return bool(self.provisioned_switchs and self.switchs_ip_type and SwitchManagementCred.objects.filter(default_switch=True).exists())
|
||||
return bool(self.provisioned_switchs and self.switchs_ip_type and SwitchManagementCred.objects.filter(default_switch=True).exists() and self.switchs_management_interface_ip)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
|
|
@ -143,6 +143,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th>Plage d'ip de management des switchs</th>
|
||||
<td>{{ topologieoptions.switchs_ip_type }} {% if topologieoptions.switchs_ip_type %}<span class="label label-success"> OK{% else %}<span class="label label-danger">Manquant{% endif %}</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Serveur des config des switchs</th>
|
||||
<td>{{ topologieoptions.switchs_management_interface }} {% if topologieoptions.switchs_management_interface %} - {{ topologieoptions.switchs_management_interface_ip }} <span class="label label-success"> OK{% else %}<span class="label label-danger">Manquant{% endif %}</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h6>Creds de management des switchs</h6>
|
||||
|
|
Loading…
Reference in a new issue