mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Fixes #1982: Swagger NAPALM documentation
This commit is contained in:
parent
770f4c962c
commit
ea05b5b606
@ -2,6 +2,7 @@
|
||||
|
||||
## Enhancements
|
||||
|
||||
* [#1982](https://github.com/netbox-community/netbox/issues/1982) - Improved NAPALM method documentation in Swagger
|
||||
* [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link
|
||||
* [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations
|
||||
|
||||
|
@ -370,6 +370,10 @@ class DeviceWithConfigContextSerializer(DeviceSerializer):
|
||||
return obj.get_config_context()
|
||||
|
||||
|
||||
class DeviceNAPALMSerializer(serializers.Serializer):
|
||||
method = serializers.DictField()
|
||||
|
||||
|
||||
class ConsoleServerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
|
||||
device = NestedDeviceSerializer()
|
||||
cable = NestedCableSerializer(read_only=True)
|
||||
|
@ -327,6 +327,13 @@ class DeviceViewSet(CustomFieldModelViewSet):
|
||||
)
|
||||
filterset_class = filters.DeviceFilter
|
||||
|
||||
_method = Parameter(
|
||||
name='method',
|
||||
in_='query',
|
||||
required=True,
|
||||
type=openapi.TYPE_STRING
|
||||
)
|
||||
|
||||
def get_serializer_class(self):
|
||||
"""
|
||||
Select the specific serializer based on the request context.
|
||||
@ -358,11 +365,15 @@ class DeviceViewSet(CustomFieldModelViewSet):
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
@swagger_auto_schema(manual_parameters=[_method], responses={'200': serializers.DeviceNAPALMSerializer})
|
||||
@action(detail=True, url_path='napalm')
|
||||
def napalm(self, request, pk):
|
||||
"""
|
||||
Execute a NAPALM method on a Device
|
||||
"""
|
||||
if not request.GET.get('method'):
|
||||
raise ServiceUnavailable('No NAPALM methods were specified.')
|
||||
|
||||
device = get_object_or_404(Device, pk=pk)
|
||||
if not device.primary_ip:
|
||||
raise ServiceUnavailable("This device does not have a primary IP address configured.")
|
||||
|
Loading…
Reference in New Issue
Block a user