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