mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Crée spécific role, l'utilise pour get l'ip du serveur des config switchs
This commit is contained in:
parent
6c41f90398
commit
ae0f134cc7
5 changed files with 55 additions and 2 deletions
|
@ -696,7 +696,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),
|
||||
),
|
||||
]
|
|
@ -1652,6 +1652,19 @@ class Role(RevMixin, AclMixin, models.Model):
|
|||
machine__interface__role=cls.objects.filter(specific_role=roletype)
|
||||
)
|
||||
|
||||
@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)
|
||||
|
||||
|
|
|
@ -231,11 +231,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 = (
|
||||
|
|
|
@ -152,6 +152,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