|
2 | 2 | Define the object types and queries availble via the graphql api.
|
3 | 3 | """
|
4 | 4 |
|
5 |
| -from netbox.graphql.types import NetBoxObjectType |
| 5 | +import strawberry |
| 6 | +import strawberry_django |
6 | 7 |
|
7 |
| -from .. import filtersets, models |
8 | 8 |
|
9 |
| -__all__ = ( |
10 |
| - "AccessListType", |
11 |
| - "ACLInterfaceAssignmentType", |
12 |
| - "ACLExtendedRuleType", |
13 |
| - "ACLStandardRuleType", |
14 |
| -) |
| 9 | +from typing import Annotated, List, Union |
| 10 | +from .filters import * |
| 11 | +from .. import models |
| 12 | +from netbox.graphql.types import OrganizationalObjectType |
15 | 13 |
|
| 14 | +@strawberry_django.type( |
| 15 | + models.AccessList, |
| 16 | + fields='__all__', |
| 17 | + filters=AccessListFilter, |
| 18 | + exclude=('assigned_object_type', 'assigned_object_id') |
| 19 | +) |
16 | 20 |
|
17 |
| -class AccessListType(NetBoxObjectType): |
| 21 | +class AccessListType(OrganizationalObjectType): |
18 | 22 | """
|
19 | 23 | Defines the object type for the django model AccessList.
|
20 | 24 | """
|
| 25 | + assigned_object_type: Annotated["ContentTypeType", strawberry.lazy("netbox.graphql.types")] |
| 26 | + assigned_object: Annotated[Union[ |
| 27 | + Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')], |
| 28 | + Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')], |
| 29 | + ], strawberry.union("ACLAssignmentType")] |
| 30 | + |
21 | 31 |
|
22 | 32 | class Meta:
|
23 | 33 | """
|
24 | 34 | Associates the filterset, fields, and model for the django model AccessList.
|
25 | 35 | """
|
26 |
| - |
27 |
| - model = models.AccessList |
28 |
| - fields = "__all__" |
29 |
| - filterset_class = filtersets.AccessListFilterSet |
30 |
| - |
31 |
| - |
32 |
| -class ACLInterfaceAssignmentType(NetBoxObjectType): |
| 36 | + @strawberry_django.field |
| 37 | + def accesslists(self) -> List[Annotated["AccessList", strawberry.lazy('accesslists.graphql.types')]]: |
| 38 | + return self.accesslists.all() |
| 39 | + |
| 40 | +@strawberry_django.type( |
| 41 | + models.ACLInterfaceAssignment, |
| 42 | + fields='__all__', |
| 43 | + exclude=('assigned_object_type', 'assigned_object_id'), |
| 44 | + filters=ACLInterfaceAssignmentFilter |
| 45 | +) |
| 46 | +class ACLInterfaceAssignmentType(OrganizationalObjectType): |
33 | 47 | """
|
34 | 48 | Defines the object type for the django model AccessList.
|
35 | 49 | """
|
| 50 | + access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")] |
| 51 | + assigned_object_type: Annotated["ContentTypeType", strawberry.lazy("netbox.graphql.types")] |
| 52 | + assigned_object: Annotated[Union[ |
| 53 | + Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')], |
| 54 | + Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')], |
| 55 | + ], strawberry.union("ACLInterfaceAssignmentType")] |
| 56 | + |
| 57 | + |
| 58 | + |
36 | 59 |
|
37 | 60 | class Meta:
|
38 | 61 | """
|
39 | 62 | Associates the filterset, fields, and model for the django model ACLInterfaceAssignment.
|
40 | 63 | """
|
| 64 | + @strawberry_django.field |
| 65 | + def aclinterfaceassignments(self) -> List[Annotated["ACLInterfaceAssignment", strawberry.lazy('aclinterfaceassignments.graphql.types')]]: |
| 66 | + return self.aclinterfaceassignments.all() |
| 67 | + |
| 68 | +@strawberry_django.type( |
| 69 | + models.ACLExtendedRule, |
| 70 | + fields='__all__', |
| 71 | + filters=ACLExtendedRuleFilter |
| 72 | +) |
41 | 73 |
|
42 |
| - model = models.ACLInterfaceAssignment |
43 |
| - fields = "__all__" |
44 |
| - filterset_class = filtersets.ACLInterfaceAssignmentFilterSet |
45 |
| - |
46 |
| - |
47 |
| -class ACLExtendedRuleType(NetBoxObjectType): |
| 74 | +class ACLExtendedRuleType(OrganizationalObjectType): |
48 | 75 | """
|
49 | 76 | Defines the object type for the django model ACLExtendedRule.
|
50 | 77 | """
|
| 78 | + source_ports: List[int] |
| 79 | + destination_ports: List[int] |
| 80 | + access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")] |
| 81 | + destination_prefix: Annotated["PrefixType", strawberry.lazy("ipam.graphql.types")] |
| 82 | + source_prefix: Annotated["PrefixType", strawberry.lazy("ipam.graphql.types")] |
51 | 83 |
|
52 | 84 | class Meta:
|
53 | 85 | """
|
54 | 86 | Associates the filterset, fields, and model for the django model ACLExtendedRule.
|
55 | 87 | """
|
| 88 | + @strawberry_django.field |
| 89 | + def aclextendedrules(self) -> List[Annotated["ACLExtendedRule", strawberry.lazy('aclextendedrule.graphql.types')]]: |
| 90 | + return self.aclextendedrules.all() |
56 | 91 |
|
57 |
| - model = models.ACLExtendedRule |
58 |
| - fields = "__all__" |
59 |
| - filterset_class = filtersets.ACLExtendedRuleFilterSet |
60 | 92 |
|
| 93 | +@strawberry_django.type( |
| 94 | + models.ACLStandardRule, |
| 95 | + fields='__all__', |
| 96 | + filters=ACLStandardRuleFilter |
| 97 | +) |
61 | 98 |
|
62 |
| -class ACLStandardRuleType(NetBoxObjectType): |
| 99 | +class ACLStandardRuleType(OrganizationalObjectType): |
63 | 100 | """
|
64 | 101 | Defines the object type for the django model ACLStandardRule.
|
65 | 102 | """
|
| 103 | + access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")] |
| 104 | + source_prefix: Annotated["PrefixType", strawberry.lazy("ipam.graphql.types")] |
66 | 105 |
|
67 | 106 | class Meta:
|
68 | 107 | """
|
69 |
| - Associates the filterset, fields, and model for the django model ACLStandardRule. |
| 108 | + Associates the filterset, fields, and model for the django model ACLExtendedRule. |
70 | 109 | """
|
| 110 | + @strawberry_django.field |
| 111 | + def aclstandardrules(self) -> List[Annotated["ACLStandardRule", strawberry.lazy('aclstandardrule.graphql.types')]]: |
| 112 | + return self.aclstandardrules.all() |
71 | 113 |
|
72 |
| - model = models.ACLStandardRule |
73 |
| - fields = "__all__" |
74 |
| - filterset_class = filtersets.ACLStandardRuleFilterSet |
|
0 commit comments