Explorar o código

Fixes #2170: Prevent the deletion of a virtual chassis when a cross-member LAG is present

Jeremy Stretch %!s(int64=6) %!d(string=hai) anos
pai
achega
462cede863
Modificáronse 2 ficheiros con 20 adicións e 1 borrados
  1. 1 0
      docs/release-notes/version-2.6.md
  2. 19 1
      netbox/dcim/models.py

+ 1 - 0
docs/release-notes/version-2.6.md

@@ -7,6 +7,7 @@
 
 ## Bug Fixes
 
+* [#2170](https://github.com/netbox-community/netbox/issues/2170) - Prevent the deletion of a virtual chassis when a cross-member LAG is present
 * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users
 
 # v2.6.8 (2019-12-10)

+ 19 - 1
netbox/dcim/models.py

@@ -9,7 +9,7 @@ from django.contrib.postgres.fields import ArrayField, JSONField
 from django.core.exceptions import ObjectDoesNotExist, ValidationError
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.db import models
-from django.db.models import Count, Q, Sum
+from django.db.models import Count, F, ProtectedError, Q, Sum
 from django.urls import reverse
 from mptt.models import MPTTModel, TreeForeignKey
 from taggit.managers import TaggableManager
@@ -2730,6 +2730,24 @@ class VirtualChassis(ChangeLoggedModel):
                 'master': "The selected master is not assigned to this virtual chassis."
             })
 
+    def delete(self, *args, **kwargs):
+
+        # Check for LAG interfaces split across member chassis
+        interfaces = Interface.objects.filter(
+            device__in=self.members.all(),
+            lag__isnull=False
+        ).exclude(
+            lag__device=F('device')
+        )
+        if interfaces:
+            raise ProtectedError(
+                "Unable to delete virtual chassis {}. There are member interfaces which form a cross-chassis "
+                "LAG".format(self),
+                interfaces
+            )
+
+        return super().delete(*args, **kwargs)
+
     def to_csv(self):
         return (
             self.master,