From 735286d3b0c6fa772dd151c8935509a1f82a5f8e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 3 Aug 2021 11:49:22 -0400 Subject: [PATCH] Add vlan_groups to Region, SiteGroup, Site, Location, Rack, ClusterGroup, Cluster --- netbox/dcim/graphql/types.py | 12 ++++++------ netbox/dcim/models/racks.py | 6 ++++++ netbox/dcim/models/sites.py | 24 ++++++++++++++++++++++++ netbox/ipam/graphql/mixins.py | 8 ++++++++ netbox/virtualization/graphql/types.py | 6 +++--- netbox/virtualization/models.py | 12 ++++++++++++ 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index fb9a7cd47..1e19a1b36 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -1,6 +1,6 @@ from dcim import filtersets, models from extras.graphql.mixins import ImageAttachmentsMixin -from ipam.graphql.mixins import IPAddressesMixin +from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin from netbox.graphql.types import BaseObjectType, ObjectType, TaggedObjectType __all__ = ( @@ -187,7 +187,7 @@ class InventoryItemType(TaggedObjectType): filterset_class = filtersets.InventoryItemFilterSet -class LocationType(ImageAttachmentsMixin, ObjectType): +class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ObjectType): class Meta: model = models.Location @@ -277,7 +277,7 @@ class PowerPortTemplateType(BaseObjectType): return self.type or None -class RackType(ImageAttachmentsMixin, TaggedObjectType): +class RackType(VLANGroupsMixin, ImageAttachmentsMixin, TaggedObjectType): class Meta: model = models.Rack @@ -323,7 +323,7 @@ class RearPortTemplateType(BaseObjectType): filterset_class = filtersets.RearPortTemplateFilterSet -class RegionType(ObjectType): +class RegionType(VLANGroupsMixin, ObjectType): class Meta: model = models.Region @@ -331,7 +331,7 @@ class RegionType(ObjectType): filterset_class = filtersets.RegionFilterSet -class SiteType(ImageAttachmentsMixin, TaggedObjectType): +class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, TaggedObjectType): class Meta: model = models.Site @@ -339,7 +339,7 @@ class SiteType(ImageAttachmentsMixin, TaggedObjectType): filterset_class = filtersets.SiteFilterSet -class SiteGroupType(ObjectType): +class SiteGroupType(VLANGroupsMixin, ObjectType): class Meta: model = models.SiteGroup diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index 3b74a3d3d..c287d7d6c 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -175,6 +175,12 @@ class Rack(PrimaryModel): comments = models.TextField( blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='rack' + ) images = GenericRelation( to='extras.ImageAttachment' ) diff --git a/netbox/dcim/models/sites.py b/netbox/dcim/models/sites.py index 943e98106..56946642b 100644 --- a/netbox/dcim/models/sites.py +++ b/netbox/dcim/models/sites.py @@ -53,6 +53,12 @@ class Region(NestedGroupModel): max_length=200, blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='region' + ) def get_absolute_url(self): return reverse('dcim:region', args=[self.pk]) @@ -95,6 +101,12 @@ class SiteGroup(NestedGroupModel): max_length=200, blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='site_group' + ) def get_absolute_url(self): return reverse('dcim:sitegroup', args=[self.pk]) @@ -210,6 +222,12 @@ class Site(PrimaryModel): comments = models.TextField( blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='site' + ) images = GenericRelation( to='extras.ImageAttachment' ) @@ -267,6 +285,12 @@ class Location(NestedGroupModel): max_length=200, blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='location' + ) images = GenericRelation( to='extras.ImageAttachment' ) diff --git a/netbox/ipam/graphql/mixins.py b/netbox/ipam/graphql/mixins.py index ba1eaf463..283414df3 100644 --- a/netbox/ipam/graphql/mixins.py +++ b/netbox/ipam/graphql/mixins.py @@ -2,6 +2,7 @@ import graphene __all__ = ( 'IPAddressesMixin', + 'VLANGroupsMixin', ) @@ -10,3 +11,10 @@ class IPAddressesMixin: def resolve_ip_addresses(self, info): return self.ip_addresses.restrict(info.context.user, 'view') + + +class VLANGroupsMixin: + vlan_groups = graphene.List('ipam.graphql.types.VLANGroupType') + + def resolve_vlan_groups(self, info): + return self.vlan_groups.restrict(info.context.user, 'view') diff --git a/netbox/virtualization/graphql/types.py b/netbox/virtualization/graphql/types.py index d12775436..83e5fbc73 100644 --- a/netbox/virtualization/graphql/types.py +++ b/netbox/virtualization/graphql/types.py @@ -1,4 +1,4 @@ -from ipam.graphql.mixins import IPAddressesMixin +from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin from virtualization import filtersets, models from netbox.graphql.types import ObjectType, TaggedObjectType @@ -11,7 +11,7 @@ __all__ = ( ) -class ClusterType(TaggedObjectType): +class ClusterType(VLANGroupsMixin, TaggedObjectType): class Meta: model = models.Cluster @@ -19,7 +19,7 @@ class ClusterType(TaggedObjectType): filterset_class = filtersets.ClusterFilterSet -class ClusterGroupType(ObjectType): +class ClusterGroupType(VLANGroupsMixin, ObjectType): class Meta: model = models.ClusterGroup diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index 4f8683114..3408cedbc 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -81,6 +81,12 @@ class ClusterGroup(OrganizationalModel): max_length=200, blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='cluster_group' + ) objects = RestrictedQuerySet.as_manager() @@ -136,6 +142,12 @@ class Cluster(PrimaryModel): comments = models.TextField( blank=True ) + vlan_groups = GenericRelation( + to='ipam.VLANGroup', + content_type_field='scope_type', + object_id_field='scope_id', + related_query_name='cluster' + ) objects = RestrictedQuerySet.as_manager()