mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Add count_fhrp_groups to interface serializers
This commit is contained in:
parent
bbb98083eb
commit
67c73768c1
@ -94,6 +94,9 @@ Support for single sign-on (SSO) authentication has been added via the [python-s
|
|||||||
|
|
||||||
* Added the following endpoints for ASNs:
|
* Added the following endpoints for ASNs:
|
||||||
* `/api/ipam/asn/`
|
* `/api/ipam/asn/`
|
||||||
|
* Added the following endpoints for FHRP groups:
|
||||||
|
* `/api/ipam/fhrp-groups/`
|
||||||
|
* `/api/ipam/fhrp-group-assignments/`
|
||||||
* Added the following endpoints for contacts:
|
* Added the following endpoints for contacts:
|
||||||
* `/api/tenancy/contact-assignments/`
|
* `/api/tenancy/contact-assignments/`
|
||||||
* `/api/tenancy/contact-groups/`
|
* `/api/tenancy/contact-groups/`
|
||||||
@ -127,6 +130,8 @@ Support for single sign-on (SSO) authentication has been added via the [python-s
|
|||||||
* dcim.DeviceType
|
* dcim.DeviceType
|
||||||
* Added `airflow` field
|
* Added `airflow` field
|
||||||
* dcim.Interface
|
* dcim.Interface
|
||||||
|
* `cable_peer` has been renamed to `link_peer`
|
||||||
|
* `cable_peer_type` has been renamed to `link_peer_type`
|
||||||
* Added `bridge` field
|
* Added `bridge` field
|
||||||
* Added `rf_channel` field
|
* Added `rf_channel` field
|
||||||
* Added `rf_channel_frequency` field
|
* Added `rf_channel_frequency` field
|
||||||
@ -135,8 +140,7 @@ Support for single sign-on (SSO) authentication has been added via the [python-s
|
|||||||
* Added `tx_power` field
|
* Added `tx_power` field
|
||||||
* Added `wireless_link` field
|
* Added `wireless_link` field
|
||||||
* Added `wwn` field
|
* Added `wwn` field
|
||||||
* `cable_peer` has been renamed to `link_peer`
|
* Added `count_fhrp_groups` read-only field
|
||||||
* `cable_peer_type` has been renamed to `link_peer_type`
|
|
||||||
* dcim.Location
|
* dcim.Location
|
||||||
* Added `tenant` field
|
* Added `tenant` field
|
||||||
* dcim.Site
|
* dcim.Site
|
||||||
@ -145,3 +149,4 @@ Support for single sign-on (SSO) authentication has been added via the [python-s
|
|||||||
* Added the `conditions` field
|
* Added the `conditions` field
|
||||||
* virtualization.VMInterface
|
* virtualization.VMInterface
|
||||||
* Added `bridge` field
|
* Added `bridge` field
|
||||||
|
* Added `count_fhrp_groups` read-only field
|
||||||
|
@ -6,8 +6,10 @@ from timezone_field.rest_framework import TimeZoneSerializerField
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants import *
|
from dcim.constants import *
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
from ipam.api.nested_serializers import NestedASNSerializer, NestedIPAddressSerializer, NestedVLANSerializer
|
from ipam.api.nested_serializers import (
|
||||||
from ipam.models import ASN, VLAN
|
NestedASNSerializer, NestedFHRPGroupAssignmentSerializer, NestedIPAddressSerializer, NestedVLANSerializer,
|
||||||
|
)
|
||||||
|
from ipam.models import ASN, FHRPGroupAssignment, VLAN
|
||||||
from netbox.api import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
from netbox.api import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
||||||
from netbox.api.serializers import (
|
from netbox.api.serializers import (
|
||||||
NestedGroupModelSerializer, PrimaryModelSerializer, ValidatedModelSerializer, WritableNestedSerializer,
|
NestedGroupModelSerializer, PrimaryModelSerializer, ValidatedModelSerializer, WritableNestedSerializer,
|
||||||
@ -636,6 +638,7 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con
|
|||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
count_ipaddresses = serializers.IntegerField(read_only=True)
|
count_ipaddresses = serializers.IntegerField(read_only=True)
|
||||||
|
count_fhrp_groups = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Interface
|
model = Interface
|
||||||
@ -645,7 +648,7 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con
|
|||||||
'rf_channel_width', 'tx_power', 'untagged_vlan', 'tagged_vlans', 'mark_connected', 'cable', 'wireless_link',
|
'rf_channel_width', 'tx_power', 'untagged_vlan', 'tagged_vlans', 'mark_connected', 'cable', 'wireless_link',
|
||||||
'link_peer', 'link_peer_type', 'wireless_lans', 'connected_endpoint', 'connected_endpoint_type',
|
'link_peer', 'link_peer_type', 'wireless_lans', 'connected_endpoint', 'connected_endpoint_type',
|
||||||
'connected_endpoint_reachable', 'tags', 'custom_fields', 'created', 'last_updated', 'count_ipaddresses',
|
'connected_endpoint_reachable', 'tags', 'custom_fields', 'created', 'last_updated', 'count_ipaddresses',
|
||||||
'_occupied',
|
'count_fhrp_groups', '_occupied',
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
@ -548,7 +548,7 @@ class PowerOutletViewSet(PathEndpointMixin, ModelViewSet):
|
|||||||
class InterfaceViewSet(PathEndpointMixin, ModelViewSet):
|
class InterfaceViewSet(PathEndpointMixin, ModelViewSet):
|
||||||
queryset = Interface.objects.prefetch_related(
|
queryset = Interface.objects.prefetch_related(
|
||||||
'device', 'parent', 'bridge', 'lag', '_path__destination', 'cable', '_link_peer', 'wireless_lans',
|
'device', 'parent', 'bridge', 'lag', '_path__destination', 'cable', '_link_peer', 'wireless_lans',
|
||||||
'untagged_vlan', 'tagged_vlans', 'ip_addresses', 'tags'
|
'untagged_vlan', 'tagged_vlans', 'ip_addresses', 'fhrp_group_assignments', 'tags'
|
||||||
)
|
)
|
||||||
serializer_class = serializers.InterfaceSerializer
|
serializer_class = serializers.InterfaceSerializer
|
||||||
filterset_class = filtersets.InterfaceFilterSet
|
filterset_class = filtersets.InterfaceFilterSet
|
||||||
|
@ -498,6 +498,10 @@ class BaseInterface(models.Model):
|
|||||||
def count_ipaddresses(self):
|
def count_ipaddresses(self):
|
||||||
return self.ip_addresses.count()
|
return self.ip_addresses.count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count_fhrp_groups(self):
|
||||||
|
return self.fhrp_group_assignments.count()
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
||||||
|
@ -91,6 +91,10 @@ class NestedFHRPGroupSerializer(WritableNestedSerializer):
|
|||||||
fields = ['id', 'url', 'display', 'protocol', 'group_id']
|
fields = ['id', 'url', 'display', 'protocol', 'group_id']
|
||||||
|
|
||||||
|
|
||||||
|
class NestedFHRPGroupAssignmentSerializer(WritableNestedSerializer):
|
||||||
|
url = serializers.HyperlinkedIdentityField(view_name='ipam-api:fhrpgroupassignment-detail')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# VLANs
|
# VLANs
|
||||||
#
|
#
|
||||||
|
@ -117,13 +117,14 @@ class VMInterfaceSerializer(PrimaryModelSerializer):
|
|||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
count_ipaddresses = serializers.IntegerField(read_only=True)
|
count_ipaddresses = serializers.IntegerField(read_only=True)
|
||||||
|
count_fhrp_groups = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address',
|
'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address',
|
||||||
'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags', 'custom_fields', 'created', 'last_updated',
|
'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
'count_ipaddresses',
|
'count_ipaddresses', 'count_fhrp_groups',
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
@ -80,7 +80,7 @@ class VirtualMachineViewSet(ConfigContextQuerySetMixin, CustomFieldModelViewSet)
|
|||||||
|
|
||||||
class VMInterfaceViewSet(ModelViewSet):
|
class VMInterfaceViewSet(ModelViewSet):
|
||||||
queryset = VMInterface.objects.prefetch_related(
|
queryset = VMInterface.objects.prefetch_related(
|
||||||
'virtual_machine', 'parent', 'tags', 'untagged_vlan', 'tagged_vlans', 'ip_addresses'
|
'virtual_machine', 'parent', 'tags', 'untagged_vlan', 'tagged_vlans', 'ip_addresses', 'fhrp_group_assignments',
|
||||||
)
|
)
|
||||||
serializer_class = serializers.VMInterfaceSerializer
|
serializer_class = serializers.VMInterfaceSerializer
|
||||||
filterset_class = filtersets.VMInterfaceFilterSet
|
filterset_class = filtersets.VMInterfaceFilterSet
|
||||||
|
Loading…
Reference in New Issue
Block a user