mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 15:33:45 +00:00
Repare le get_instance de role + renvoie les réglages supplémentaires optionaltopologie pour les switchs
This commit is contained in:
parent
4ec9008466
commit
46fe444ead
3 changed files with 33 additions and 5 deletions
|
@ -342,10 +342,15 @@ class OptionalMachineSerializer(NamespacedHMSerializer):
|
||||||
class OptionalTopologieSerializer(NamespacedHMSerializer):
|
class OptionalTopologieSerializer(NamespacedHMSerializer):
|
||||||
"""Serialize `preferences.models.OptionalTopologie` objects.
|
"""Serialize `preferences.models.OptionalTopologie` objects.
|
||||||
"""
|
"""
|
||||||
|
switchs_management_interface_ip= serializers.CharField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = preferences.OptionalTopologie
|
model = preferences.OptionalTopologie
|
||||||
fields = ('radius_general_policy', 'vlan_decision_ok',
|
fields = ('radius_general_policy', 'vlan_decision_ok',
|
||||||
'vlan_decision_nok')
|
'vlan_decision_nok', 'switchs_ip_type', 'switchs_web_management',
|
||||||
|
'switchs_web_management_ssl', 'switchs_rest_management',
|
||||||
|
'switchs_management_utils', 'switchs_management_interface_ip',
|
||||||
|
'provision_switchs_enabled')
|
||||||
|
|
||||||
|
|
||||||
class GeneralOptionSerializer(NamespacedHMSerializer):
|
class GeneralOptionSerializer(NamespacedHMSerializer):
|
||||||
|
|
|
@ -1534,18 +1534,23 @@ class Role(RevMixin, AclMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, machineid, *_args, **_kwargs):
|
def get_instance(cls, roleid, *_args, **_kwargs):
|
||||||
"""Get the Machine instance with machineid.
|
"""Get the Role instance with roleid.
|
||||||
:param userid: The id
|
:param userid: The id
|
||||||
:return: The user
|
:return: The user
|
||||||
"""
|
"""
|
||||||
return cls.objects.get(pk=machineid)
|
return cls.objects.get(pk=roleid)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface_for_roletype(cls, roletype):
|
def interface_for_roletype(cls, roletype):
|
||||||
"""Return interfaces for a roletype"""
|
"""Return interface for a roletype"""
|
||||||
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
|
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def all_interfaces_for_roletype(cls, roletype):
|
||||||
|
"""Return all interfaces for a roletype"""
|
||||||
|
return Interface.objects.filter(machine__interface__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)
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,24 @@ class OptionalTopologie(AclMixin, PreferencesModel):
|
||||||
return None
|
return None
|
||||||
return self.switchs_management_interface.ipv4
|
return self.switchs_management_interface.ipv4
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def switchs_management_utils(self):
|
||||||
|
"""Used for switch_conf, return a list of ip on vlans"""
|
||||||
|
from machines.models import Role, Ipv6List, Interface
|
||||||
|
def return_ips_dict(interfaces):
|
||||||
|
return {'ipv4' : [str(interface.ipv4) for interface in interfaces], 'ipv6' : Ipv6List.objects.filter(interface__in=interfaces).values_list('ipv6', flat=True)}
|
||||||
|
|
||||||
|
ntp_servers = Role.all_interfaces_for_roletype("ntp-server").filter(type__ip_type=self.switchs_ip_type)
|
||||||
|
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")
|
||||||
|
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}
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def provision_switchs_enabled(self):
|
def provision_switchs_enabled(self):
|
||||||
"""Return true if all settings are ok : switchs on automatic provision,
|
"""Return true if all settings are ok : switchs on automatic provision,
|
||||||
|
|
Loading…
Reference in a new issue