mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 10:28:37 -06:00
more child and parent fields for prefixes and addresses
This commit is contained in:
parent
006c22a54f
commit
052f1dbb7c
@ -138,7 +138,7 @@ 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')]]:
|
||||
"""
|
||||
@ -185,6 +185,43 @@ class PrefixType(NetBoxObjectType, ContactsMixin, BaseIPAddressFamilyType):
|
||||
], strawberry.union("PrefixScopeType")] | None:
|
||||
return self.scope
|
||||
|
||||
@strawberry_django.field
|
||||
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
||||
"""
|
||||
Return all parent prefixes containing this prefix.
|
||||
"""
|
||||
from ipam.models import Prefix
|
||||
return Prefix.objects.filter(
|
||||
vrf=self.vrf,
|
||||
prefix__net_contains=str(self.prefix)
|
||||
)
|
||||
|
||||
@strawberry_django.field
|
||||
def child_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
||||
"""
|
||||
Return all child prefixes contained within this prefix.
|
||||
"""
|
||||
from ipam.models import Prefix
|
||||
return Prefix.objects.filter(
|
||||
vrf=self.vrf,
|
||||
prefix__net_contained=str(self.prefix)
|
||||
)
|
||||
|
||||
@strawberry_django.field
|
||||
def child_ip_addresses(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
|
||||
"""
|
||||
Return all IP addresses within this prefix.
|
||||
"""
|
||||
if self.vrf is None and self.status == 'container':
|
||||
return models.IPAddress.objects.filter(
|
||||
address__net_host_contained=str(self.prefix)
|
||||
)
|
||||
else:
|
||||
return models.IPAddress.objects.filter(
|
||||
address__net_host_contained=str(self.prefix),
|
||||
vrf=self.vrf
|
||||
)
|
||||
|
||||
|
||||
@strawberry_django.type(
|
||||
models.RIR,
|
||||
|
Loading…
Reference in New Issue
Block a user