mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -06:00
Move ServicePort api serialization from ipam
to dcim
This commit is contained in:
parent
2563ce624c
commit
b5174f8d43
@ -1,6 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from ipam.models import IPAddress
|
from ipam.models import IPAddress, ServicePort
|
||||||
from dcim.models import (
|
from dcim.models import (
|
||||||
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, DeviceType,
|
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, DeviceType,
|
||||||
DeviceRole, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet,
|
DeviceRole, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet,
|
||||||
@ -442,3 +442,32 @@ class InterfaceConnectionSerializer(serializers.ModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = InterfaceConnection
|
model = InterfaceConnection
|
||||||
fields = ['id', 'interface_a', 'interface_b', 'connection_status']
|
fields = ['id', 'interface_a', 'interface_b', 'connection_status']
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Service Ports
|
||||||
|
#
|
||||||
|
|
||||||
|
class ServicePortSerializer(serializers.ModelSerializer):
|
||||||
|
device = DeviceNestedSerializer()
|
||||||
|
ip_address = DeviceIPAddressNestedSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ServicePort
|
||||||
|
fields = ['id', 'device', 'ip_address', 'port', 'protocol', 'name', 'description']
|
||||||
|
|
||||||
|
|
||||||
|
class ServicePortNestedSerializer(ServicePortSerializer):
|
||||||
|
device = DeviceNestedSerializer()
|
||||||
|
ip_address = DeviceIPAddressNestedSerializer()
|
||||||
|
|
||||||
|
class Meta(ServicePortSerializer.Meta):
|
||||||
|
fields = ['id', 'device', 'ip_address', 'port', 'protocol']
|
||||||
|
|
||||||
|
|
||||||
|
class ServicePortDetailSerializer(ServicePortSerializer):
|
||||||
|
device = DeviceNestedSerializer()
|
||||||
|
ip_address = DeviceIPAddressNestedSerializer()
|
||||||
|
|
||||||
|
class Meta(ServicePortSerializer.Meta):
|
||||||
|
fields = ['id', 'device', 'ip_address', 'port', 'protocol', 'name', 'description']
|
||||||
|
@ -69,6 +69,10 @@ urlpatterns = [
|
|||||||
url(r'^interface-connections/$', InterfaceConnectionListView.as_view(), name='interfaceconnection_list'),
|
url(r'^interface-connections/$', InterfaceConnectionListView.as_view(), name='interfaceconnection_list'),
|
||||||
url(r'^interface-connections/(?P<pk>\d+)/$', InterfaceConnectionView.as_view(), name='interfaceconnection_detail'),
|
url(r'^interface-connections/(?P<pk>\d+)/$', InterfaceConnectionView.as_view(), name='interfaceconnection_detail'),
|
||||||
|
|
||||||
|
# Service ports
|
||||||
|
url(r'^service-ports/$', ServicePortListView.as_view(), name='serviceport_list'),
|
||||||
|
url(r'^service-ports/(?P<pk>\d+)/$', ServicePortDetailView.as_view(), name='serviceport_detail'),
|
||||||
|
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
url(r'^related-connections/$', RelatedConnectionsView.as_view(), name='related_connections'),
|
url(r'^related-connections/$', RelatedConnectionsView.as_view(), name='related_connections'),
|
||||||
url(r'^topology-maps/(?P<slug>[\w-]+)/$', TopologyMapView.as_view(), name='topology_map'),
|
url(r'^topology-maps/(?P<slug>[\w-]+)/$', TopologyMapView.as_view(), name='topology_map'),
|
||||||
|
@ -16,6 +16,7 @@ from dcim.models import (
|
|||||||
from dcim import filters
|
from dcim import filters
|
||||||
from extras.api.views import CustomFieldModelAPIView
|
from extras.api.views import CustomFieldModelAPIView
|
||||||
from extras.api.renderers import BINDZoneRenderer, FlatJSONRenderer
|
from extras.api.renderers import BINDZoneRenderer, FlatJSONRenderer
|
||||||
|
from ipam.models import ServicePort
|
||||||
from utilities.api import ServiceUnavailable
|
from utilities.api import ServiceUnavailable
|
||||||
from .exceptions import MissingFilterException
|
from .exceptions import MissingFilterException
|
||||||
from . import serializers
|
from . import serializers
|
||||||
@ -422,6 +423,26 @@ class LLDPNeighborsView(APIView):
|
|||||||
return Response(lldp_neighbors)
|
return Response(lldp_neighbors)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Service Port
|
||||||
|
#
|
||||||
|
|
||||||
|
class ServicePortListView(generics.ListAPIView):
|
||||||
|
"""
|
||||||
|
List IP addresses (filterable)
|
||||||
|
"""
|
||||||
|
queryset = ServicePort.objects.select_related('device', 'ip_address', 'port', 'protocol', 'name', 'description')
|
||||||
|
serializer_class = serializers.ServicePortSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ServicePortDetailView(generics.RetrieveAPIView):
|
||||||
|
"""
|
||||||
|
Retrieve a single IP address
|
||||||
|
"""
|
||||||
|
queryset = ServicePort.objects.select_related('device', 'ip_address', 'port', 'protocol', 'name', 'description')
|
||||||
|
serializer_class = serializers.ServicePortSerializer
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
#
|
#
|
||||||
|
@ -2,7 +2,7 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from dcim.api.serializers import SiteNestedSerializer, InterfaceNestedSerializer
|
from dcim.api.serializers import SiteNestedSerializer, InterfaceNestedSerializer
|
||||||
from extras.api.serializers import CustomFieldSerializer
|
from extras.api.serializers import CustomFieldSerializer
|
||||||
from ipam.models import VRF, Role, RIR, Aggregate, Prefix, IPAddress, VLAN, VLANGroup, ServicePort
|
from ipam.models import VRF, Role, RIR, Aggregate, Prefix, IPAddress, VLAN, VLANGroup
|
||||||
from tenancy.api.serializers import TenantNestedSerializer
|
from tenancy.api.serializers import TenantNestedSerializer
|
||||||
|
|
||||||
|
|
||||||
@ -170,29 +170,3 @@ class IPAddressNestedSerializer(IPAddressSerializer):
|
|||||||
|
|
||||||
IPAddressSerializer._declared_fields['nat_inside'] = IPAddressNestedSerializer()
|
IPAddressSerializer._declared_fields['nat_inside'] = IPAddressNestedSerializer()
|
||||||
IPAddressSerializer._declared_fields['nat_outside'] = IPAddressNestedSerializer()
|
IPAddressSerializer._declared_fields['nat_outside'] = IPAddressNestedSerializer()
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Service Ports
|
|
||||||
#
|
|
||||||
|
|
||||||
class ServicePortSerializer(serializers.ModelSerializer):
|
|
||||||
ip_address = IPAddressNestedSerializer()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ServicePort
|
|
||||||
fields = ['id', 'ip_address', 'port', 'protocol', 'name', 'description']
|
|
||||||
|
|
||||||
|
|
||||||
class ServicePortNestedSerializer(ServicePortSerializer):
|
|
||||||
ip_address = IPAddressNestedSerializer()
|
|
||||||
|
|
||||||
class Meta(ServicePortSerializer.Meta):
|
|
||||||
fields = ['id', 'ip_address', 'port', 'protocol']
|
|
||||||
|
|
||||||
|
|
||||||
class ServicePortDetailSerializer(ServicePortSerializer):
|
|
||||||
ip_address = IPAddressNestedSerializer()
|
|
||||||
|
|
||||||
class Meta(ServicePortSerializer.Meta):
|
|
||||||
fields = ['id', 'ip_address', 'port', 'protocol', 'name', 'description']
|
|
||||||
|
@ -29,10 +29,6 @@ urlpatterns = [
|
|||||||
url(r'^ip-addresses/$', IPAddressListView.as_view(), name='ipaddress_list'),
|
url(r'^ip-addresses/$', IPAddressListView.as_view(), name='ipaddress_list'),
|
||||||
url(r'^ip-addresses/(?P<pk>\d+)/$', IPAddressDetailView.as_view(), name='ipaddress_detail'),
|
url(r'^ip-addresses/(?P<pk>\d+)/$', IPAddressDetailView.as_view(), name='ipaddress_detail'),
|
||||||
|
|
||||||
# Service ports
|
|
||||||
url(r'^service-ports/$', ServicePortListView.as_view(), name='serviceport_list'),
|
|
||||||
url(r'^service-ports/(?P<pk>\d+)/$', ServicePortDetailView.as_view(), name='serviceport_detail'),
|
|
||||||
|
|
||||||
# VLAN groups
|
# VLAN groups
|
||||||
url(r'^vlan-groups/$', VLANGroupListView.as_view(), name='vlangroup_list'),
|
url(r'^vlan-groups/$', VLANGroupListView.as_view(), name='vlangroup_list'),
|
||||||
url(r'^vlan-groups/(?P<pk>\d+)/$', VLANGroupDetailView.as_view(), name='vlangroup_detail'),
|
url(r'^vlan-groups/(?P<pk>\d+)/$', VLANGroupDetailView.as_view(), name='vlangroup_detail'),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
|
|
||||||
from ipam.models import VRF, Role, RIR, Aggregate, Prefix, IPAddress, VLAN, VLANGroup, ServicePort
|
from ipam.models import VRF, Role, RIR, Aggregate, Prefix, IPAddress, VLAN, VLANGroup
|
||||||
from ipam import filters
|
from ipam import filters
|
||||||
|
|
||||||
from extras.api.views import CustomFieldModelAPIView
|
from extras.api.views import CustomFieldModelAPIView
|
||||||
@ -135,26 +135,6 @@ class IPAddressDetailView(CustomFieldModelAPIView, generics.RetrieveAPIView):
|
|||||||
serializer_class = serializers.IPAddressSerializer
|
serializer_class = serializers.IPAddressSerializer
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Service Port
|
|
||||||
#
|
|
||||||
|
|
||||||
class ServicePortListView(generics.ListAPIView):
|
|
||||||
"""
|
|
||||||
List IP addresses (filterable)
|
|
||||||
"""
|
|
||||||
queryset = ServicePort.objects.select_related('device', 'ip_address', 'port', 'protocol', 'name', 'description')
|
|
||||||
serializer_class = serializers.ServicePortSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class ServicePortDetailView(generics.RetrieveAPIView):
|
|
||||||
"""
|
|
||||||
Retrieve a single IP address
|
|
||||||
"""
|
|
||||||
queryset = ServicePort.objects.select_related('device', 'ip_address', 'port', 'protocol', 'name', 'description')
|
|
||||||
serializer_class = serializers.ServicePortSerializer
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# VLAN groups
|
# VLAN groups
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user