mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add ip_addresses relation on InterfaceType, VMInterfaceType
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from dcim import filtersets, models
|
||||
from ipam.graphql.mixins import IPAddressesMixin
|
||||
from netbox.graphql.types import BaseObjectType, ObjectType, TaggedObjectType
|
||||
|
||||
__all__ = (
|
||||
@ -158,7 +159,7 @@ class FrontPortTemplateType(BaseObjectType):
|
||||
filterset_class = filtersets.FrontPortTemplateFilterSet
|
||||
|
||||
|
||||
class InterfaceType(TaggedObjectType):
|
||||
class InterfaceType(IPAddressesMixin, TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Interface
|
||||
|
12
netbox/ipam/graphql/mixins.py
Normal file
12
netbox/ipam/graphql/mixins.py
Normal file
@ -0,0 +1,12 @@
|
||||
import graphene
|
||||
|
||||
__all__ = (
|
||||
'IPAddressesMixin',
|
||||
)
|
||||
|
||||
|
||||
class IPAddressesMixin:
|
||||
ip_addresses = graphene.List('ipam.graphql.types.IPAddressType')
|
||||
|
||||
def resolve_ip_addresses(self, info):
|
||||
return self.ip_addresses.restrict(info.context.user, 'view')
|
@ -5,7 +5,7 @@ from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
from django.test import override_settings
|
||||
from graphene.types.dynamic import Dynamic
|
||||
from graphene.types import Dynamic as GQLDynamic, List as GQLList
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
@ -446,9 +446,13 @@ class APIViewTestCases:
|
||||
# Compile list of fields to include
|
||||
fields_string = ''
|
||||
for field_name, field in type_class._meta.fields.items():
|
||||
if type(field) is Dynamic:
|
||||
if type(field) is GQLDynamic:
|
||||
# Dynamic fields must specify a subselection
|
||||
fields_string += f'{field_name} {{ id }}\n'
|
||||
elif type(field.type) is GQLList and field_name not in ('tags', 'choices'):
|
||||
# TODO: Come up with something more elegant
|
||||
# Temporary hack to support automated testing of reverse generic relations
|
||||
fields_string += f'{field_name} {{ id }}\n'
|
||||
else:
|
||||
fields_string += f'{field_name}\n'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from ipam.graphql.mixins import IPAddressesMixin
|
||||
from virtualization import filtersets, models
|
||||
from netbox.graphql.types import ObjectType, TaggedObjectType
|
||||
|
||||
@ -42,7 +43,7 @@ class VirtualMachineType(TaggedObjectType):
|
||||
filterset_class = filtersets.VirtualMachineFilterSet
|
||||
|
||||
|
||||
class VMInterfaceType(TaggedObjectType):
|
||||
class VMInterfaceType(IPAddressesMixin, TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.VMInterface
|
||||
|
Reference in New Issue
Block a user