mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 21:02:23 -06:00
15156 Add display_url to REST API (#16412)
* 15156 add display_url to REST API * 15156 fix view name * 15156 fix typo * 15156 fix tests * 15156 add url display_url to base class * 15156 add url display_url to base class * 15156 add url display_url to base class * 15156 review changes * 15156 review changes * 15156 review changes * 15156 review changes * 15156 remove bogus code * 15156 remove bogus code * 15156 review changes * 15156 review changes * 15156 review changes --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
@@ -23,82 +23,60 @@ __all__ = (
|
||||
exclude_fields=('tunnel_count',),
|
||||
)
|
||||
class NestedTunnelGroupSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:tunnelgroup-detail')
|
||||
tunnel_count = RelatedObjectCountField('tunnels')
|
||||
|
||||
class Meta:
|
||||
model = models.TunnelGroup
|
||||
fields = ['id', 'url', 'display', 'name', 'slug', 'tunnel_count']
|
||||
fields = ['id', 'url', 'display_url', 'display', 'name', 'slug', 'tunnel_count']
|
||||
|
||||
|
||||
class NestedTunnelSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:tunnel-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.Tunnel
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
class NestedTunnelTerminationSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:tunneltermination-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.TunnelTermination
|
||||
fields = ('id', 'url', 'display')
|
||||
fields = ('id', 'url', 'display_url', 'display')
|
||||
|
||||
|
||||
class NestedIKEProposalSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ikeproposal-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.IKEProposal
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
class NestedIKEPolicySerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ikepolicy-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.IKEPolicy
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
class NestedIPSecProposalSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecproposal-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.IPSecProposal
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
class NestedIPSecPolicySerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecpolicy-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.IPSecPolicy
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
class NestedIPSecProfileSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecprofile-detail'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.IPSecProfile
|
||||
fields = ('id', 'url', 'display', 'name')
|
||||
fields = ('id', 'url', 'display_url', 'display', 'name')
|
||||
|
||||
|
||||
#
|
||||
@@ -106,21 +84,19 @@ class NestedIPSecProfileSerializer(WritableNestedSerializer):
|
||||
#
|
||||
|
||||
class NestedL2VPNSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:l2vpn-detail')
|
||||
|
||||
class Meta:
|
||||
model = models.L2VPN
|
||||
fields = [
|
||||
'id', 'url', 'display', 'identifier', 'name', 'slug', 'type'
|
||||
'id', 'url', 'display', 'display_url', 'identifier', 'name', 'slug', 'type'
|
||||
]
|
||||
|
||||
|
||||
class NestedL2VPNTerminationSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:l2vpntermination-detail')
|
||||
l2vpn = NestedL2VPNSerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.L2VPNTermination
|
||||
fields = [
|
||||
'id', 'url', 'display', 'l2vpn'
|
||||
'id', 'url', 'display_url', 'display', 'l2vpn'
|
||||
]
|
||||
|
||||
@@ -15,9 +15,6 @@ __all__ = (
|
||||
|
||||
|
||||
class IKEProposalSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ikeproposal-detail'
|
||||
)
|
||||
authentication_method = ChoiceField(
|
||||
choices=AuthenticationMethodChoices
|
||||
)
|
||||
@@ -34,17 +31,14 @@ class IKEProposalSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = IKEProposal
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'description', 'authentication_method', 'encryption_algorithm',
|
||||
'authentication_algorithm', 'group', 'sa_lifetime', 'comments', 'tags', 'custom_fields', 'created',
|
||||
'last_updated',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'authentication_method',
|
||||
'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime', 'comments', 'tags',
|
||||
'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class IKEPolicySerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ikepolicy-detail'
|
||||
)
|
||||
version = ChoiceField(
|
||||
choices=IKEVersionChoices
|
||||
)
|
||||
@@ -62,16 +56,13 @@ class IKEPolicySerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = IKEPolicy
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'comments',
|
||||
'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'version', 'mode', 'proposals',
|
||||
'preshared_key', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class IPSecProposalSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecproposal-detail'
|
||||
)
|
||||
encryption_algorithm = ChoiceField(
|
||||
choices=EncryptionAlgorithmChoices
|
||||
)
|
||||
@@ -82,16 +73,13 @@ class IPSecProposalSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = IPSecProposal
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'description', 'encryption_algorithm', 'authentication_algorithm',
|
||||
'sa_lifetime_seconds', 'sa_lifetime_data', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'encryption_algorithm',
|
||||
'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class IPSecPolicySerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecpolicy-detail'
|
||||
)
|
||||
proposals = SerializedPKRelatedField(
|
||||
queryset=IPSecProposal.objects.all(),
|
||||
serializer=IPSecProposalSerializer,
|
||||
@@ -107,16 +95,13 @@ class IPSecPolicySerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = IPSecPolicy
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'description', 'proposals', 'pfs_group', 'comments', 'tags',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'proposals', 'pfs_group', 'comments', 'tags',
|
||||
'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class IPSecProfileSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:ipsecprofile-detail'
|
||||
)
|
||||
mode = ChoiceField(
|
||||
choices=IPSecModeChoices
|
||||
)
|
||||
@@ -130,7 +115,7 @@ class IPSecProfileSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = IPSecProfile
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'description', 'mode', 'ike_policy', 'ipsec_policy', 'comments', 'tags',
|
||||
'custom_fields', 'created', 'last_updated',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'mode', 'ike_policy', 'ipsec_policy',
|
||||
'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
@@ -18,7 +18,6 @@ __all__ = (
|
||||
|
||||
|
||||
class L2VPNSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:l2vpn-detail')
|
||||
type = ChoiceField(choices=L2VPNTypeChoices, required=False)
|
||||
import_targets = SerializedPKRelatedField(
|
||||
queryset=RouteTarget.objects.all(),
|
||||
@@ -39,14 +38,13 @@ class L2VPNSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = L2VPN
|
||||
fields = [
|
||||
'id', 'url', 'display', 'identifier', 'name', 'slug', 'type', 'import_targets', 'export_targets',
|
||||
'description', 'comments', 'tenant', 'tags', 'custom_fields', 'created', 'last_updated'
|
||||
'id', 'url', 'display_url', 'display', 'identifier', 'name', 'slug', 'type', 'import_targets',
|
||||
'export_targets', 'description', 'comments', 'tenant', 'tags', 'custom_fields', 'created', 'last_updated'
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'identifier', 'name', 'slug', 'type', 'description')
|
||||
|
||||
|
||||
class L2VPNTerminationSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:l2vpntermination-detail')
|
||||
l2vpn = L2VPNSerializer(
|
||||
nested=True
|
||||
)
|
||||
@@ -58,7 +56,7 @@ class L2VPNTerminationSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = L2VPNTermination
|
||||
fields = [
|
||||
'id', 'url', 'display', 'l2vpn', 'assigned_object_type', 'assigned_object_id',
|
||||
'id', 'url', 'display_url', 'display', 'l2vpn', 'assigned_object_type', 'assigned_object_id',
|
||||
'assigned_object', 'tags', 'custom_fields', 'created', 'last_updated'
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'l2vpn')
|
||||
|
||||
@@ -23,7 +23,6 @@ __all__ = (
|
||||
#
|
||||
|
||||
class TunnelGroupSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='vpn-api:tunnelgroup-detail')
|
||||
|
||||
# Related object counts
|
||||
tunnel_count = RelatedObjectCountField('tunnels')
|
||||
@@ -31,16 +30,13 @@ class TunnelGroupSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = TunnelGroup
|
||||
fields = [
|
||||
'id', 'url', 'display', 'name', 'slug', 'description', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'tunnel_count',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'tags', 'custom_fields',
|
||||
'created', 'last_updated', 'tunnel_count',
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'tunnel_count')
|
||||
|
||||
|
||||
class TunnelSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:tunnel-detail'
|
||||
)
|
||||
status = ChoiceField(
|
||||
choices=TunnelStatusChoices
|
||||
)
|
||||
@@ -70,16 +66,14 @@ class TunnelSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = Tunnel
|
||||
fields = (
|
||||
'id', 'url', 'display', 'name', 'status', 'group', 'encapsulation', 'ipsec_profile', 'tenant', 'tunnel_id',
|
||||
'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'terminations_count',
|
||||
'id', 'url', 'display_url', 'display', 'name', 'status', 'group', 'encapsulation', 'ipsec_profile',
|
||||
'tenant', 'tunnel_id', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'terminations_count',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class TunnelTerminationSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name='vpn-api:tunneltermination-detail'
|
||||
)
|
||||
tunnel = TunnelSerializer(
|
||||
nested=True
|
||||
)
|
||||
@@ -101,8 +95,8 @@ class TunnelTerminationSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = TunnelTermination
|
||||
fields = (
|
||||
'id', 'url', 'display', 'tunnel', 'role', 'termination_type', 'termination_id', 'termination', 'outside_ip',
|
||||
'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'id', 'url', 'display_url', 'display', 'tunnel', 'role', 'termination_type', 'termination_id',
|
||||
'termination', 'outside_ip', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user