mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add GraphQL for IPAM
This commit is contained in:
11
netbox/ipam/graphql/__init__.py
Normal file
11
netbox/ipam/graphql/__init__.py
Normal file
@ -0,0 +1,11 @@
|
||||
import graphene
|
||||
from graphene_django.converter import convert_django_field
|
||||
|
||||
from ipam.fields import IPAddressField, IPNetworkField
|
||||
|
||||
|
||||
@convert_django_field.register(IPAddressField)
|
||||
@convert_django_field.register(IPNetworkField)
|
||||
def convert_field_to_string(field, registry=None):
|
||||
# TODO: Update to use get_django_field_description under django_graphene v3.0
|
||||
return graphene.String(description=field.help_text, required=not field.null)
|
36
netbox/ipam/graphql/schema.py
Normal file
36
netbox/ipam/graphql/schema.py
Normal file
@ -0,0 +1,36 @@
|
||||
import graphene
|
||||
|
||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
||||
from .types import *
|
||||
|
||||
|
||||
class IPAMQuery(graphene.ObjectType):
|
||||
aggregate = ObjectField(AggregateType)
|
||||
aggregates = ObjectListField(AggregateType)
|
||||
|
||||
ip_address = ObjectField(IPAddressType)
|
||||
ip_addresses = ObjectListField(IPAddressType)
|
||||
|
||||
prefix = ObjectField(PrefixType)
|
||||
prefixes = ObjectListField(PrefixType)
|
||||
|
||||
rir = ObjectField(RIRType)
|
||||
rirs = ObjectListField(RIRType)
|
||||
|
||||
role = ObjectField(RoleType)
|
||||
roles = ObjectListField(RoleType)
|
||||
|
||||
route_target = ObjectField(RouteTargetType)
|
||||
route_targets = ObjectListField(RouteTargetType)
|
||||
|
||||
service = ObjectField(ServiceType)
|
||||
services = ObjectListField(ServiceType)
|
||||
|
||||
vlan = ObjectField(VLANType)
|
||||
vlans = ObjectListField(VLANType)
|
||||
|
||||
vlan_group = ObjectField(VLANGroupType)
|
||||
vlan_groups = ObjectListField(VLANGroupType)
|
||||
|
||||
vrf = ObjectField(VRFType)
|
||||
vrfs = ObjectListField(VRFType)
|
95
netbox/ipam/graphql/types.py
Normal file
95
netbox/ipam/graphql/types.py
Normal file
@ -0,0 +1,95 @@
|
||||
from ipam import filtersets, models
|
||||
from netbox.graphql.types import ObjectType, TaggedObjectType
|
||||
|
||||
__all__ = (
|
||||
'AggregateType',
|
||||
'IPAddressType',
|
||||
'PrefixType',
|
||||
'RIRType',
|
||||
'RoleType',
|
||||
'RouteTargetType',
|
||||
'ServiceType',
|
||||
'VLANType',
|
||||
'VLANGroupType',
|
||||
'VRFType',
|
||||
)
|
||||
|
||||
|
||||
class AggregateType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Aggregate
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.AggregateFilterSet
|
||||
|
||||
|
||||
class IPAddressType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.IPAddress
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.IPAddressFilterSet
|
||||
|
||||
|
||||
class PrefixType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Prefix
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.PrefixFilterSet
|
||||
|
||||
|
||||
class RIRType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.RIR
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.RIRFilterSet
|
||||
|
||||
|
||||
class RoleType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Role
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.RoleFilterSet
|
||||
|
||||
|
||||
class RouteTargetType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.RouteTarget
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.RouteTargetFilterSet
|
||||
|
||||
|
||||
class ServiceType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Service
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ServiceFilterSet
|
||||
|
||||
|
||||
class VLANType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.VLAN
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.VLANFilterSet
|
||||
|
||||
|
||||
class VLANGroupType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.VLANGroup
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.VLANGroupFilterSet
|
||||
|
||||
|
||||
class VRFType(TaggedObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.VRF
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.VRFFilterSet
|
@ -20,7 +20,7 @@ class AppTest(APITestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class VRFTest(APIViewTestCases.APIViewTestCase):
|
||||
class VRFTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = VRF
|
||||
brief_fields = ['display', 'id', 'name', 'prefix_count', 'rd', 'url']
|
||||
create_data = [
|
||||
@ -52,7 +52,7 @@ class VRFTest(APIViewTestCases.APIViewTestCase):
|
||||
VRF.objects.bulk_create(vrfs)
|
||||
|
||||
|
||||
class RouteTargetTest(APIViewTestCases.APIViewTestCase):
|
||||
class RouteTargetTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = RouteTarget
|
||||
brief_fields = ['display', 'id', 'name', 'url']
|
||||
create_data = [
|
||||
@ -81,7 +81,7 @@ class RouteTargetTest(APIViewTestCases.APIViewTestCase):
|
||||
RouteTarget.objects.bulk_create(route_targets)
|
||||
|
||||
|
||||
class RIRTest(APIViewTestCases.APIViewTestCase):
|
||||
class RIRTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = RIR
|
||||
brief_fields = ['aggregate_count', 'display', 'id', 'name', 'slug', 'url']
|
||||
create_data = [
|
||||
@ -113,7 +113,7 @@ class RIRTest(APIViewTestCases.APIViewTestCase):
|
||||
RIR.objects.bulk_create(rirs)
|
||||
|
||||
|
||||
class AggregateTest(APIViewTestCases.APIViewTestCase):
|
||||
class AggregateTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = Aggregate
|
||||
brief_fields = ['display', 'family', 'id', 'prefix', 'url']
|
||||
bulk_update_data = {
|
||||
@ -152,7 +152,7 @@ class AggregateTest(APIViewTestCases.APIViewTestCase):
|
||||
]
|
||||
|
||||
|
||||
class RoleTest(APIViewTestCases.APIViewTestCase):
|
||||
class RoleTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = Role
|
||||
brief_fields = ['display', 'id', 'name', 'prefix_count', 'slug', 'url', 'vlan_count']
|
||||
create_data = [
|
||||
@ -184,7 +184,7 @@ class RoleTest(APIViewTestCases.APIViewTestCase):
|
||||
Role.objects.bulk_create(roles)
|
||||
|
||||
|
||||
class PrefixTest(APIViewTestCases.APIViewTestCase):
|
||||
class PrefixTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = Prefix
|
||||
brief_fields = ['_depth', 'display', 'family', 'id', 'prefix', 'url']
|
||||
create_data = [
|
||||
@ -358,7 +358,7 @@ class PrefixTest(APIViewTestCases.APIViewTestCase):
|
||||
self.assertEqual(len(response.data), 8)
|
||||
|
||||
|
||||
class IPAddressTest(APIViewTestCases.APIViewTestCase):
|
||||
class IPAddressTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = IPAddress
|
||||
brief_fields = ['address', 'display', 'family', 'id', 'url']
|
||||
create_data = [
|
||||
@ -387,7 +387,7 @@ class IPAddressTest(APIViewTestCases.APIViewTestCase):
|
||||
IPAddress.objects.bulk_create(ip_addresses)
|
||||
|
||||
|
||||
class VLANGroupTest(APIViewTestCases.APIViewTestCase):
|
||||
class VLANGroupTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = VLANGroup
|
||||
brief_fields = ['display', 'id', 'name', 'slug', 'url', 'vlan_count']
|
||||
create_data = [
|
||||
@ -419,7 +419,7 @@ class VLANGroupTest(APIViewTestCases.APIViewTestCase):
|
||||
VLANGroup.objects.bulk_create(vlan_groups)
|
||||
|
||||
|
||||
class VLANTest(APIViewTestCases.APIViewTestCase):
|
||||
class VLANTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = VLAN
|
||||
brief_fields = ['display', 'id', 'name', 'url', 'vid']
|
||||
bulk_update_data = {
|
||||
@ -479,7 +479,7 @@ class VLANTest(APIViewTestCases.APIViewTestCase):
|
||||
self.assertTrue(content['detail'].startswith('Unable to delete object.'))
|
||||
|
||||
|
||||
class ServiceTest(APIViewTestCases.APIViewTestCase):
|
||||
class ServiceTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = Service
|
||||
brief_fields = ['display', 'id', 'name', 'ports', 'protocol', 'url']
|
||||
bulk_update_data = {
|
||||
|
Reference in New Issue
Block a user