mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Serialisation de la conf des swicthes
This commit is contained in:
parent
916ec9789f
commit
aec2c645a2
4 changed files with 82 additions and 2 deletions
|
@ -467,16 +467,30 @@ class BuildingSerializer(NamespacedHMSerializer):
|
|||
class SwitchPortSerializer(NamespacedHMSerializer):
|
||||
"""Serialize `topologie.models.Port` objects
|
||||
"""
|
||||
|
||||
get_port_profil = NamespacedHIField(view_name='portprofile-detail', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = topologie.Port
|
||||
fields = ('switch', 'port', 'room', 'machine_interface', 'related',
|
||||
'custom_profile', 'state', 'details', 'api_url')
|
||||
'custom_profile', 'state', 'get_port_profil', 'details', 'api_url')
|
||||
extra_kwargs = {
|
||||
'related': {'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):
|
||||
"""Serialize `topologie.models.Room` objects
|
||||
"""
|
||||
|
@ -644,6 +658,45 @@ class ServiceRegenSerializer(NamespacedHMSerializer):
|
|||
'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
|
||||
|
||||
|
|
|
@ -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/switchbay', views.SwitchBayViewSet)
|
||||
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(r'topologie/portprofile', views.PortProfileViewSet)
|
||||
# USERS
|
||||
|
@ -105,6 +106,8 @@ router.register_view(r'localemail/users', views.LocalEmailUsersView),
|
|||
# Firewall
|
||||
router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView),
|
||||
router.register_view(r'firewall/interface-ports', views.InterfacePortsOpenView),
|
||||
# Switches config
|
||||
router.register_view(r'switchs/ports-config', views.SwitchPortView),
|
||||
# DNS
|
||||
router.register_view(r'dns/zones', views.DNSZonesView),
|
||||
router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView),
|
||||
|
|
16
api/views.py
16
api/views.py
|
@ -397,6 +397,13 @@ class SwitchPortViewSet(viewsets.ReadOnlyModelViewSet):
|
|||
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):
|
||||
"""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)
|
||||
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
|
||||
|
||||
|
|
|
@ -292,6 +292,14 @@ class Switch(AclMixin, Machine):
|
|||
def get_name(self):
|
||||
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):
|
||||
return str(self.get_name)
|
||||
|
||||
|
|
Loading…
Reference in a new issue