From 006c22a54f210280a7e4e67bb1aa2868d1c46a03 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Wed, 9 Apr 2025 09:23:26 -0400 Subject: [PATCH] Add parent_prefixes to graphql IPAddressType --- netbox/ipam/graphql/types.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/netbox/ipam/graphql/types.py b/netbox/ipam/graphql/types.py index 54ce2fc74..a63032463 100644 --- a/netbox/ipam/graphql/types.py +++ b/netbox/ipam/graphql/types.py @@ -138,6 +138,17 @@ class IPAddressType(NetBoxObjectType, ContactsMixin, BaseIPAddressFamilyType): Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')], ], strawberry.union("IPAddressAssignmentType")] | None: return self.assigned_object + + @strawberry_django.field + def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]: + """ + Return all prefixes containing this IP address. + """ + from ipam.models import Prefix + return Prefix.objects.filter( + vrf=self.vrf, + prefix__net_contains_or_equals=str(self.address.ip) + ) @strawberry_django.type(