Coverage for netbox_interface_name_rules / api / views.py: 100.00%
13 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-16 10:13 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-16 10:13 +0000
1# SPDX-License-Identifier: Apache-2.0
2# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
3from netbox.api.viewsets import NetBoxModelViewSet
4from rest_framework.exceptions import ValidationError
6from netbox_interface_name_rules import branching
7from netbox_interface_name_rules.models import InterfaceNameRule
9from .serializers import InterfaceNameRuleSerializer
11BACKGROUND_IN_A_BRANCH = (
12 "A background request runs on main, not in the active branch. Send the request without background=true."
13)
16class InterfaceNameRuleViewSet(NetBoxModelViewSet):
17 """REST API viewset for InterfaceNameRule."""
19 queryset = InterfaceNameRule.objects.all()
20 serializer_class = InterfaceNameRuleSerializer
22 def _enqueue_bulk_job(self, request, *args, **kwargs):
23 """Refuse a background request in a branch before NetBox enqueues it: its job runs on main."""
24 if branching.branch_identity() is not None:
25 raise ValidationError(BACKGROUND_IN_A_BRANCH)
26 return super()._enqueue_bulk_job(request, *args, **kwargs)