Browse Source

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

Jeremy Stretch 6 năm trước cách đây
mục cha
commit
462cede863

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

@@ -7,6 +7,7 @@
 
 
 ## Bug Fixes
 ## 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
 * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users
 
 
 # v2.6.8 (2019-12-10)
 # 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.exceptions import ObjectDoesNotExist, ValidationError
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.db import models
 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 django.urls import reverse
 from mptt.models import MPTTModel, TreeForeignKey
 from mptt.models import MPTTModel, TreeForeignKey
 from taggit.managers import TaggableManager
 from taggit.managers import TaggableManager
@@ -2730,6 +2730,24 @@ class VirtualChassis(ChangeLoggedModel):
                 'master': "The selected master is not assigned to this virtual chassis."
                 '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):
     def to_csv(self):
         return (
         return (
             self.master,
             self.master,