mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
IPAddressFunctionAssignments - api mvp
This commit is contained in:
parent
603f021465
commit
4920539c52
@ -4,7 +4,7 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from dcim.api.nested_serializers import NestedDeviceSerializer, NestedSiteSerializer
|
from dcim.api.nested_serializers import NestedDeviceSerializer, NestedSiteSerializer
|
||||||
from ipam.choices import *
|
from ipam.choices import *
|
||||||
from ipam.constants import IPADDRESS_ASSIGNMENT_MODELS, VLANGROUP_SCOPE_TYPES
|
from ipam.constants import IPADDRESS_ASSIGNMENT_MODELS, VLANGROUP_SCOPE_TYPES, IPADDRESS_FUNCTION_ASSIGNMENT_MODELS
|
||||||
from ipam.models import *
|
from ipam.models import *
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import NetBoxModelSerializer
|
||||||
@ -445,6 +445,29 @@ class AvailableIPSerializer(serializers.Serializer):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class IPAddressFunctionAssignmentsSerializer(NetBoxModelSerializer):
|
||||||
|
url = serializers.HyperlinkedIdentityField(view_name='ipam-api:ipaddressfunctionassignments-detail')
|
||||||
|
assigned_object_type = ContentTypeField(
|
||||||
|
queryset=ContentType.objects.filter(IPADDRESS_FUNCTION_ASSIGNMENT_MODELS),
|
||||||
|
)
|
||||||
|
assigned_object = serializers.SerializerMethodField(read_only=True)
|
||||||
|
assigned_ip = NestedIPAddressSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IPAddressFunctionAssignments
|
||||||
|
fields = [
|
||||||
|
'id', 'url', 'display', 'assigned_ip', 'function',
|
||||||
|
'assigned_object_type', 'assigned_object_id', 'assigned_object',
|
||||||
|
'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
|
]
|
||||||
|
|
||||||
|
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||||
|
def get_assigned_object(self, instance):
|
||||||
|
serializer = get_serializer_for_model(instance.assigned_object, prefix=NESTED_SERIALIZER_PREFIX)
|
||||||
|
context = {'request': self.context['request']}
|
||||||
|
return serializer(instance.assigned_object, context=context).data
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Services
|
# Services
|
||||||
#
|
#
|
||||||
|
@ -17,6 +17,7 @@ router.register('roles', views.RoleViewSet)
|
|||||||
router.register('prefixes', views.PrefixViewSet)
|
router.register('prefixes', views.PrefixViewSet)
|
||||||
router.register('ip-ranges', views.IPRangeViewSet)
|
router.register('ip-ranges', views.IPRangeViewSet)
|
||||||
router.register('ip-addresses', views.IPAddressViewSet)
|
router.register('ip-addresses', views.IPAddressViewSet)
|
||||||
|
router.register('ip-address-function-assignments', views.IPAddressFunctionAssignmentsViewSet)
|
||||||
router.register('fhrp-groups', views.FHRPGroupViewSet)
|
router.register('fhrp-groups', views.FHRPGroupViewSet)
|
||||||
router.register('fhrp-group-assignments', views.FHRPGroupAssignmentViewSet)
|
router.register('fhrp-group-assignments', views.FHRPGroupAssignmentViewSet)
|
||||||
router.register('vlan-groups', views.VLANGroupViewSet)
|
router.register('vlan-groups', views.VLANGroupViewSet)
|
||||||
|
@ -131,6 +131,12 @@ class IPAddressViewSet(NetBoxModelViewSet):
|
|||||||
return super().destroy(request, *args, **kwargs)
|
return super().destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class IPAddressFunctionAssignmentsViewSet(NetBoxModelViewSet):
|
||||||
|
queryset = IPAddressFunctionAssignments.objects.prefetch_related('assigned_ip', 'assigned_object', 'tags')
|
||||||
|
serializer_class = serializers.IPAddressFunctionAssignmentsSerializer
|
||||||
|
# filterset_class = filtersets. # TODO add filterset
|
||||||
|
|
||||||
|
|
||||||
class FHRPGroupViewSet(NetBoxModelViewSet):
|
class FHRPGroupViewSet(NetBoxModelViewSet):
|
||||||
queryset = FHRPGroup.objects.prefetch_related('ip_addresses', 'tags')
|
queryset = FHRPGroup.objects.prefetch_related('ip_addresses', 'tags')
|
||||||
serializer_class = serializers.FHRPGroupSerializer
|
serializer_class = serializers.FHRPGroupSerializer
|
||||||
|
@ -94,16 +94,17 @@ class IPAddressRoleChoices(ChoiceSet):
|
|||||||
(ROLE_CARP, 'CARP', 'green'),
|
(ROLE_CARP, 'CARP', 'green'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class IPAddressFunctionChoices(ChoiceSet):
|
class IPAddressFunctionChoices(ChoiceSet):
|
||||||
|
|
||||||
FUNC_OOB = 'Out Of Band'
|
FUNC_OOB = 'Out Of Band'
|
||||||
# Future planning, depreciate primary_ip
|
# Future planning, depreciate primary_ip
|
||||||
# FUNC_PRIMARY_IP = 'Primary IP'
|
# FUNC_PRIMARY_IP = 'Primary IP'
|
||||||
|
|
||||||
CHOICES = (
|
CHOICES = (
|
||||||
(FUNC_OOB, 'Out Of Band', 'gray'),
|
(FUNC_OOB, 'Out Of Band', 'gray'),
|
||||||
# Future planning, depreciate primary_ip
|
# Future planning, depreciate primary_ip
|
||||||
# (FUNC_PRIMARY_IP, 'Primary IP', 'blue'),
|
# (FUNC_PRIMARY_IP, 'Primary IP', 'blue'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user