From bc812e493729151c84bb44124fc4a5cf0907bc04 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 8 Jul 2021 17:30:40 -0400 Subject: [PATCH] Closes #5223: Remove the console/power/interface connections REST API endpoints --- docs/release-notes/version-3.0.md | 6 ++++++ netbox/dcim/api/serializers.py | 25 ------------------------ netbox/dcim/api/urls.py | 5 ----- netbox/dcim/api/views.py | 32 ------------------------------- 4 files changed, 6 insertions(+), 62 deletions(-) diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 9ed9a9492ae..73ed38d8d18 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -8,6 +8,7 @@ * Support for queryset caching configuration (`caching_config`) has been removed from the plugins API (see [#6639](https://github.com/netbox-community/netbox/issues/6639)). * The `cacheops_*` metrics have been removed from the Prometheus exporter (see [#6639](https://github.com/netbox-community/netbox/issues/6639)). * The `invalidate` management command has been removed. +* The redundant REST API endpoints for console, power, and interface connections have been removed. The same data can be retrieved using the respective model endpoints with the `?connected=True` filter applied. ### New Features @@ -63,6 +64,7 @@ CustomValidator can also be subclassed to enforce more complex logic by overridi ### Other Changes +* [#5223](https://github.com/netbox-community/netbox/issues/5223) - Remove the console/power/interface connections REST API endpoints * [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6 * [#5994](https://github.com/netbox-community/netbox/issues/5994) - Drop support for `display_field` argument on ObjectVar * [#6068](https://github.com/netbox-community/netbox/issues/6068) - Drop support for legacy static CSV export @@ -79,6 +81,10 @@ CustomValidator can also be subclassed to enforce more complex logic by overridi * Added the `/api/users/tokens/` endpoint * The `provision/` child endpoint can be used to provision new REST API tokens by supplying a valid username and password +* Removed the following "connections" endpoints: + * `/api/dcim/console-connections` + * `/api/dcim/power-connections` + * `/api/dcim/interface-connections` * dcim.Cable * `length` is now a decimal value * dcim.Device diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index deb73fba410..1cdcc252f61 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -841,31 +841,6 @@ def get_path(self, obj): return ret -# -# Interface connections -# - -class InterfaceConnectionSerializer(ValidatedModelSerializer): - interface_a = serializers.SerializerMethodField() - interface_b = NestedInterfaceSerializer(source='_path.destination') - connected_endpoint_reachable = serializers.SerializerMethodField(read_only=True) - - class Meta: - model = Interface - fields = ['interface_a', 'interface_b', 'connected_endpoint_reachable'] - - @swagger_serializer_method(serializer_or_field=NestedInterfaceSerializer) - def get_interface_a(self, obj): - context = {'request': self.context['request']} - return NestedInterfaceSerializer(instance=obj, context=context).data - - @swagger_serializer_method(serializer_or_field=serializers.BooleanField) - def get_connected_endpoint_reachable(self, obj): - if obj._path is not None: - return obj._path.is_active - return None - - # # Virtual chassis # diff --git a/netbox/dcim/api/urls.py b/netbox/dcim/api/urls.py index 43f956cb21c..491f4e7f29c 100644 --- a/netbox/dcim/api/urls.py +++ b/netbox/dcim/api/urls.py @@ -46,11 +46,6 @@ router.register('device-bays', views.DeviceBayViewSet) router.register('inventory-items', views.InventoryItemViewSet) -# Connections -router.register('console-connections', views.ConsoleConnectionViewSet, basename='consoleconnections') -router.register('power-connections', views.PowerConnectionViewSet, basename='powerconnections') -router.register('interface-connections', views.InterfaceConnectionViewSet, basename='interfaceconnections') - # Cables router.register('cables', views.CableViewSet) diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index 47ab2682828..9592dabae54 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -570,38 +570,6 @@ class InventoryItemViewSet(ModelViewSet): brief_prefetch_fields = ['device'] -# -# Connections -# - -class ConsoleConnectionViewSet(ListModelMixin, GenericViewSet): - queryset = ConsolePort.objects.prefetch_related('device', '_path').filter( - _path__destination_id__isnull=False - ) - serializer_class = serializers.ConsolePortSerializer - filterset_class = filtersets.ConsoleConnectionFilterSet - - -class PowerConnectionViewSet(ListModelMixin, GenericViewSet): - queryset = PowerPort.objects.prefetch_related('device', '_path').filter( - _path__destination_id__isnull=False - ) - serializer_class = serializers.PowerPortSerializer - filterset_class = filtersets.PowerConnectionFilterSet - - -class InterfaceConnectionViewSet(ListModelMixin, GenericViewSet): - queryset = Interface.objects.prefetch_related('device', '_path').filter( - # Avoid duplicate connections by only selecting the lower PK in a connected pair - _path__destination_type__app_label='dcim', - _path__destination_type__model='interface', - _path__destination_id__isnull=False, - pk__lt=F('_path__destination_id') - ) - serializer_class = serializers.InterfaceConnectionSerializer - filterset_class = filtersets.InterfaceConnectionFilterSet - - # # Cables #