From a3275a9b6b54d1b5d043386ee5f282779a4c71f8 Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Mon, 26 Jun 2023 23:07:20 +0100 Subject: [PATCH] make is_oob_ip and is_primary_ip generic for other models --- netbox/ipam/models/ip.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 615aa6965..2316882de 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -852,26 +852,28 @@ class IPAddress(PrimaryModel): @property def is_oob_ip(self): if self.assigned_object: + parent = getattr(self.assigned_object, 'parent_object', None) if self.family == 4: - if self.assigned_object.device.oob_ip4: - if self.assigned_object.device.oob_ip4.pk == self.pk: + if parent.oob_ip4: + if parent.oob_ip4.pk == self.pk: return True if self.family == 6: - if self.assigned_object.device.oob_ip6: - if self.assigned_object.device.oob_ip6.pk == self.pk: + if parent.oob_ip6: + if parent.oob_ip6.pk == self.pk: return True return False @property def is_primary_ip(self): if self.assigned_object: + parent = getattr(self.assigned_object, 'parent_object', None) if self.family == 4: - if self.assigned_object.device.primary_ip4: - if self.assigned_object.device.primary_ip4.pk == self.pk: + if parent.primary_ip4: + if parent.primary_ip4.pk == self.pk: return True if self.family == 6: - if self.assigned_object.device.primary_ip6: - if self.assigned_object.device.primary_ip6.pk == self.pk: + if parent.primary_ip6: + if parent.primary_ip6.pk == self.pk: return True return False