Arthur 2 лет назад
Родитель
Сommit
ff03abf23e
1 измененных файлов с 53 добавлено и 53 удалено
  1. 53 53
      netbox/dcim/graphql/types.py

+ 53 - 53
netbox/dcim/graphql/types.py

@@ -13,6 +13,7 @@ from extras.graphql.mixins import (
 )
 from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
 
+from netbox.graphql.scalars import BigInt
 from netbox.graphql.types import (
     BaseObjectType,
     NetBoxObjectType,
@@ -72,6 +73,7 @@ __all__ = (
 #
 
 
+@strawberry.type
 class ComponentObjectType(
     ChangelogMixin,
     CustomFieldsMixin,
@@ -81,8 +83,7 @@ class ComponentObjectType(
     """
     Base type for device/VM components
     """
-    class Meta:
-        abstract = True
+    _name: str
 
 
 class ComponentTemplateObjectType(
@@ -92,8 +93,7 @@ class ComponentTemplateObjectType(
     """
     Base type for device/VM components
     """
-    class Meta:
-        abstract = True
+    _name: str
 
 
 #
@@ -147,7 +147,7 @@ class CableType(NetBoxObjectType):
 @strawberry_django.type(
     models.ConsolePort,
     # exclude=('_path',),
-    exclude=('_path', '_name',),  # bug - temp
+    exclude=('_path',),  # bug - temp
     filters=ConsolePortFilter
 )
 class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -158,8 +158,7 @@ class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
 
 @strawberry_django.type(
     models.ConsolePortTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=ConsolePortTemplateFilter
 )
 class ConsolePortTemplateType(ComponentTemplateObjectType):
@@ -171,7 +170,7 @@ class ConsolePortTemplateType(ComponentTemplateObjectType):
 @strawberry_django.type(
     models.ConsoleServerPort,
     # exclude=('_path',),
-    exclude=('_path', '_name',),  # bug - temp
+    exclude=('_path',),  # bug - temp
     filters=ConsoleServerPortFilter
 )
 class ConsoleServerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -182,8 +181,7 @@ class ConsoleServerPortType(ComponentObjectType, CabledObjectMixin, PathEndpoint
 
 @strawberry_django.type(
     models.ConsoleServerPortTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=ConsoleServerPortTemplateFilter
 )
 class ConsoleServerPortTemplateType(ComponentTemplateObjectType):
@@ -194,15 +192,21 @@ class ConsoleServerPortTemplateType(ComponentTemplateObjectType):
 
 @strawberry_django.type(
     models.Device,
-    # fields='__all__',
-    exclude=(
-        '_name', 'console_port_count', 'console_server_port_count', 'power_port_count', 'power_outlet_count',
-        'interface_count', 'front_port_count', 'rear_port_count', 'device_bay_count', 'module_bay_count',
-        'inventory_item_count'
-    ),  # bug - temp
+    fields='__all__',
     filters=DeviceFilter
 )
 class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
+    _name: str
+    console_port_count: BigInt
+    console_server_port_count: BigInt
+    power_port_count: BigInt
+    power_outlet_count: BigInt
+    interface_count: BigInt
+    front_port_count: BigInt
+    rear_port_count: BigInt
+    device_bay_count: BigInt
+    module_bay_count: BigInt
+    inventory_item_count: BigInt
 
     def resolve_face(self, info):
         return self.face or None
@@ -213,8 +217,7 @@ class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, NetBo
 
 @strawberry_django.type(
     models.DeviceBay,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=DeviceBayFilter
 )
 class DeviceBayType(ComponentObjectType):
@@ -223,8 +226,7 @@ class DeviceBayType(ComponentObjectType):
 
 @strawberry_django.type(
     models.DeviceBayTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=DeviceBayTemplateFilter
 )
 class DeviceBayTemplateType(ComponentTemplateObjectType):
@@ -233,7 +235,7 @@ class DeviceBayTemplateType(ComponentTemplateObjectType):
 
 @strawberry_django.type(
     models.InventoryItemTemplate,
-    exclude=('component_type', 'component_id', '_name', 'parent'),
+    exclude=('component_type', 'component_id', 'parent'),
     filters=InventoryItemTemplateFilter
 )
 class InventoryItemTemplateType(ComponentTemplateObjectType):
@@ -253,16 +255,20 @@ class DeviceRoleType(OrganizationalObjectType):
 
 @strawberry_django.type(
     models.DeviceType,
-    # fields='__all__',
-    exclude=(
-        'console_port_template_count', 'console_server_port_template_count', 'power_port_template_count',
-        'power_outlet_template_count', 'interface_template_count', 'front_port_template_count',
-        'rear_port_template_count', 'device_bay_template_count', 'module_bay_template_count',
-        'inventory_item_template_count',
-    ),  # bug - temp
+    fields='__all__',
     filters=DeviceTypeFilter
 )
 class DeviceTypeType(NetBoxObjectType):
+    console_port_template_count: BigInt
+    console_server_port_template_count: BigInt
+    power_port_template_count: BigInt
+    power_outlet_template_count: BigInt
+    interface_template_count: BigInt
+    front_port_template_count: BigInt
+    rear_port_template_count: BigInt
+    device_bay_template_count: BigInt
+    module_bay_template_count: BigInt
+    inventory_item_template_count: BigInt
 
     def resolve_subdevice_role(self, info):
         return self.subdevice_role or None
@@ -277,7 +283,7 @@ class DeviceTypeType(NetBoxObjectType):
 @strawberry_django.type(
     models.FrontPort,
     # fields='__all__',
-    exclude=('_name', 'color'),  # bug - temp
+    exclude=('color',),  # bug - temp
     filters=FrontPortFilter
 )
 class FrontPortType(ComponentObjectType, CabledObjectMixin):
@@ -287,7 +293,7 @@ class FrontPortType(ComponentObjectType, CabledObjectMixin):
 @strawberry_django.type(
     models.FrontPortTemplate,
     # fields='__all__',
-    exclude=('_name', 'color'),  # bug - temp
+    exclude=('color',),  # bug - temp
     filters=FrontPortTemplateFilter
 )
 class FrontPortTemplateType(ComponentTemplateObjectType):
@@ -297,7 +303,7 @@ class FrontPortTemplateType(ComponentTemplateObjectType):
 @strawberry_django.type(
     models.Interface,
     # fields='__all__',
-    exclude=('mac_address', '_name', 'wwn'),  # bug - temp
+    exclude=('mac_address', 'wwn'),  # bug - temp
     filters=InterfaceFilter
 )
 class InterfaceType(IPAddressesMixin, ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -320,8 +326,7 @@ class InterfaceType(IPAddressesMixin, ComponentObjectType, CabledObjectMixin, Pa
 
 @strawberry_django.type(
     models.InterfaceTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=InterfaceTemplateFilter
 )
 class InterfaceTemplateType(ComponentTemplateObjectType):
@@ -338,7 +343,7 @@ class InterfaceTemplateType(ComponentTemplateObjectType):
 
 @strawberry_django.type(
     models.InventoryItem,
-    exclude=('component_type', 'component_id', '_name', 'parent'),
+    exclude=('component_type', 'component_id', 'parent'),
     filters=InventoryItemFilter
 )
 class InventoryItemType(ComponentObjectType):
@@ -349,7 +354,7 @@ class InventoryItemType(ComponentObjectType):
 @strawberry_django.type(
     models.InventoryItemRole,
     # fields='__all__',
-    exclude=('color', '_name'),  # bug - temp
+    exclude=('color',),  # bug - temp
     filters=InventoryItemRoleFilter
 )
 class InventoryItemRoleType(OrganizationalObjectType):
@@ -386,8 +391,7 @@ class ModuleType(ComponentObjectType):
 
 @strawberry_django.type(
     models.ModuleBay,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=ModuleBayFilter
 )
 class ModuleBayType(ComponentObjectType):
@@ -396,8 +400,7 @@ class ModuleBayType(ComponentObjectType):
 
 @strawberry_django.type(
     models.ModuleBayTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=ModuleBayTemplateFilter
 )
 class ModuleBayTemplateType(ComponentTemplateObjectType):
@@ -435,8 +438,7 @@ class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
 
 @strawberry_django.type(
     models.PowerOutlet,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=PowerOutletFilter
 )
 class PowerOutletType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -450,8 +452,7 @@ class PowerOutletType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
 
 @strawberry_django.type(
     models.PowerOutletTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=PowerOutletTemplateFilter
 )
 class PowerOutletTemplateType(ComponentTemplateObjectType):
@@ -474,7 +475,7 @@ class PowerPanelType(NetBoxObjectType, ContactsMixin):
 
 @strawberry_django.type(
     models.PowerPort,
-    exclude=('_path', '_name'),
+    exclude=('_path',),
     filters=PowerPortFilter
 )
 class PowerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -485,8 +486,7 @@ class PowerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
 
 @strawberry_django.type(
     models.PowerPortTemplate,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=PowerPortTemplateFilter
 )
 class PowerPortTemplateType(ComponentTemplateObjectType):
@@ -497,11 +497,11 @@ class PowerPortTemplateType(ComponentTemplateObjectType):
 
 @strawberry_django.type(
     models.Rack,
-    # fields='__all__',
-    exclude=('_name',),  # bug - temp
+    fields='__all__',
     filters=RackFilter
 )
 class RackType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
+    _name: str
 
     def resolve_type(self, info):
         return self.type or None
@@ -536,7 +536,7 @@ class RackRoleType(OrganizationalObjectType):
 @strawberry_django.type(
     models.RearPort,
     # fields='__all__',
-    exclude=('_name', 'color'),  # bug - temp
+    exclude=('color', ),  # bug - temp
     filters=RearPortFilter
 )
 class RearPortType(ComponentObjectType, CabledObjectMixin):
@@ -546,7 +546,7 @@ class RearPortType(ComponentObjectType, CabledObjectMixin):
 @strawberry_django.type(
     models.RearPortTemplate,
     # fields='__all__',
-    exclude=('_name', 'color'),  # bug - temp
+    exclude=('color', ),  # bug - temp
     filters=RearPortTemplateFilter
 )
 class RearPortTemplateType(ComponentTemplateObjectType):
@@ -566,12 +566,12 @@ class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
 @strawberry_django.type(
     models.Site,
     # fields='__all__',
-    exclude=('_name', 'time_zone'),  # bug - temp
+    exclude=('time_zone',),  # bug - temp
     filters=SiteFilter
 )
 class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
-    # asn = graphene.Field(BigInt)
-    pass
+    _name: str
+    asn: BigInt
 
 
 @strawberry_django.type(