8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Serialisation de la conf des swicthes

This commit is contained in:
Gabriel Detraz 2018-07-02 11:00:32 +02:00 committed by grizzly
parent 916ec9789f
commit aec2c645a2
4 changed files with 82 additions and 2 deletions

View file

@ -467,16 +467,30 @@ class BuildingSerializer(NamespacedHMSerializer):
class SwitchPortSerializer(NamespacedHMSerializer): class SwitchPortSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Port` objects """Serialize `topologie.models.Port` objects
""" """
get_port_profil = NamespacedHIField(view_name='portprofile-detail', read_only=True)
class Meta: class Meta:
model = topologie.Port model = topologie.Port
fields = ('switch', 'port', 'room', 'machine_interface', 'related', fields = ('switch', 'port', 'room', 'machine_interface', 'related',
'custom_profile', 'state', 'details', 'api_url') 'custom_profile', 'state', 'get_port_profil', 'details', 'api_url')
extra_kwargs = { extra_kwargs = {
'related': {'view_name': 'switchport-detail'}, 'related': {'view_name': 'switchport-detail'},
'api_url': {'view_name': 'switchport-detail'}, 'api_url': {'view_name': 'switchport-detail'},
} }
class PortProfileSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Room` objects
"""
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', 'dhcpv6_snooping', 'arp_protect',
'ra_guard', 'loop_protect', 'api_url')
class RoomSerializer(NamespacedHMSerializer): class RoomSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Room` objects """Serialize `topologie.models.Room` objects
""" """
@ -644,6 +658,45 @@ class ServiceRegenSerializer(NamespacedHMSerializer):
'api_url': {'view_name': 'serviceregen-detail'} 'api_url': {'view_name': 'serviceregen-detail'}
} }
# Switches et ports
class ProfilSerializer(NamespacedHMSerializer):
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')
class ModelSwitchSerializer(NamespacedHMSerializer):
class Meta:
model = topologie.ModelSwitch
fields = ('reference',)
class SwitchBaySerializer(NamespacedHMSerializer):
class Meta:
model = topologie.SwitchBay
fields = ('name',)
class PortsSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ipv6List` objects.
"""
get_port_profil = ProfilSerializer(read_only=True)
class Meta:
model = topologie.Port
fields = ('state', 'port', 'get_port_profil')
class SwitchPortSerializer(serializers.ModelSerializer):
"""Serialize the data about the switches"""
ports = PortsSerializer(many=True, read_only=True)
model = ModelSwitchSerializer(read_only=True)
switchbay = SwitchBaySerializer(read_only=True)
class Meta:
model = topologie.Switch
fields = ('short_name', 'model', 'switchbay', 'ports', 'subnet', 'subnet6')
# LOCAL EMAILS # LOCAL EMAILS

View file

@ -81,7 +81,8 @@ router.register_viewset(r'topologie/modelswitch', views.ModelSwitchViewSet)
router.register_viewset(r'topologie/constructorswitch', views.ConstructorSwitchViewSet) router.register_viewset(r'topologie/constructorswitch', views.ConstructorSwitchViewSet)
router.register_viewset(r'topologie/switchbay', views.SwitchBayViewSet) router.register_viewset(r'topologie/switchbay', views.SwitchBayViewSet)
router.register_viewset(r'topologie/building', views.BuildingViewSet) router.register_viewset(r'topologie/building', views.BuildingViewSet)
router.register(r'topologie/switchport', views.SwitchPortViewSet, base_name='switchport') router.register_viewset(r'topologie/switchport', views.SwitchPortViewSet, base_name='switchport')
router.register_viewset(r'topologie/portprofile', views.PortProfileViewSet, base_name='portprofile')
router.register_viewset(r'topologie/room', views.RoomViewSet) router.register_viewset(r'topologie/room', views.RoomViewSet)
router.register(r'topologie/portprofile', views.PortProfileViewSet) router.register(r'topologie/portprofile', views.PortProfileViewSet)
# USERS # USERS
@ -105,6 +106,8 @@ router.register_view(r'localemail/users', views.LocalEmailUsersView),
# Firewall # Firewall
router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView), router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView),
router.register_view(r'firewall/interface-ports', views.InterfacePortsOpenView), router.register_view(r'firewall/interface-ports', views.InterfacePortsOpenView),
# Switches config
router.register_view(r'switchs/ports-config', views.SwitchPortView),
# DNS # DNS
router.register_view(r'dns/zones', views.DNSZonesView), router.register_view(r'dns/zones', views.DNSZonesView),
router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView), router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView),

View file

@ -397,6 +397,13 @@ class SwitchPortViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = serializers.SwitchPortSerializer serializer_class = serializers.SwitchPortSerializer
class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.PortProfile` objects.
"""
queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer
class RoomViewSet(viewsets.ReadOnlyModelViewSet): class RoomViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Room` objects. """Exposes list and details of `topologie.models.Room` objects.
""" """
@ -515,6 +522,15 @@ class ServiceRegenViewSet(viewsets.ModelViewSet):
queryset = queryset.filter(server__domain__name__iexact=hostname) queryset = queryset.filter(server__domain__name__iexact=hostname)
return queryset return queryset
# Config des switches
class SwitchPortView(generics.ListAPIView):
"""Exposes the associations between hostname, mac address and IPv4 in
order to build the DHCP lease files.
"""
queryset = topologie.Switch.objects.all().prefetch_related('ports__custom_profile')
serializer_class = serializers.SwitchPortSerializer
# LOCAL EMAILS # LOCAL EMAILS

View file

@ -292,6 +292,14 @@ class Switch(AclMixin, Machine):
def get_name(self): def get_name(self):
return self.name or self.main_interface().domain.name return self.name or self.main_interface().domain.name
@cached_property
def subnet(self):
return self.main_interface().type.ip_type.ip_set_full_info
@cached_property
def subnet6(self):
return self.main_interface().type.ip_type.ip6_set_full_info
def __str__(self): def __str__(self):
return str(self.get_name) return str(self.get_name)