pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pheus/netbox-aci-plugin/commit/ceedd7c98e62ceb365943797bebca1b3416f83bc

s" /> feat(filtersets): Add ACINodeFilterSet for ACI Nodes · pheus/netbox-aci-plugin@ceedd7c · GitHub
Skip to content

Commit ceedd7c

Browse files
committed
feat(filtersets): Add ACINodeFilterSet for ACI Nodes
Introduces a filter set for the ACINode model, enabling advanced filtering of ACI Nodes by attributes such as fabric, pod, device, virtual machine, and TEP IP address. Enhances user control over data queries and analysis within NetBox.
1 parent 73ae806 commit ceedd7c

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

netbox_aci_plugin/filtersets/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .fabric.fabrics import ACIFabricFilterSet
2+
from .fabric.nodes import ACINodeFilterSet
23
from .fabric.pods import ACIPodFilterSet
34
from .tenant.app_profiles import ACIAppProfileFilterSet
45
from .tenant.bridge_domains import (
@@ -31,6 +32,7 @@
3132
__all__ = (
3233
# Fabric
3334
"ACIFabricFilterSet",
35+
"ACINodeFilterSet",
3436
"ACIPodFilterSet",
3537
# Tenant
3638
"ACIAppProfileFilterSet",
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# SPDX-FileCopyrightText: 2025 Martin Hauser
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import django_filters
6+
from dcim.models import Device
7+
from django.db.models import Q
8+
from django.utils.translation import gettext_lazy as _
9+
from ipam.models import IPAddress
10+
from netbox.filtersets import NetBoxModelFilterSet
11+
from utilities.filters import ContentTypeFilter
12+
from virtualization.models import VirtualMachine
13+
14+
from ...models.fabric.fabrics import ACIFabric
15+
from ...models.fabric.nodes import ACINode
16+
from ...models.fabric.pods import ACIPod
17+
from ..mixins import ACIFabricFilterSetMixin, NBTenantFilterSetMixin
18+
19+
20+
class ACINodeFilterSet(
21+
ACIFabricFilterSetMixin, NBTenantFilterSetMixin, NetBoxModelFilterSet
22+
):
23+
"""Filter set for the ACI Node model."""
24+
25+
aci_fabric = django_filters.ModelMultipleChoiceFilter(
26+
field_name="aci_pod__aci_fabric__name",
27+
queryset=ACIFabric.objects.all(),
28+
to_field_name="name",
29+
label=_("ACI Fabric (name)"),
30+
)
31+
aci_fabric_id = django_filters.ModelMultipleChoiceFilter(
32+
field_name="aci_pod__aci_fabric",
33+
queryset=ACIFabric.objects.all(),
34+
to_field_name="id",
35+
label=_("ACI Fabric (ID)"),
36+
)
37+
aci_pod = django_filters.ModelMultipleChoiceFilter(
38+
field_name="aci_pod__name",
39+
queryset=ACIPod.objects.all(),
40+
to_field_name="name",
41+
label=_("ACI Pod (name)"),
42+
)
43+
aci_pod_id = django_filters.ModelMultipleChoiceFilter(
44+
field_name="aci_pod",
45+
queryset=ACIPod.objects.all(),
46+
to_field_name="id",
47+
label=_("ACI Pod (ID)"),
48+
)
49+
node_object_type = ContentTypeFilter(
50+
label=_("Node Object Type"),
51+
)
52+
tep_ip_address = django_filters.ModelMultipleChoiceFilter(
53+
field_name="tep_ip_address__address",
54+
queryset=IPAddress.objects.all(),
55+
to_field_name="address",
56+
label=_("TEP IP Address (address)"),
57+
)
58+
tep_ip_address_id = django_filters.ModelMultipleChoiceFilter(
59+
queryset=IPAddress.objects.all(),
60+
to_field_name="id",
61+
label=_("TEP IP Address (ID)"),
62+
)
63+
64+
# Cached related objects filters
65+
device = django_filters.ModelMultipleChoiceFilter(
66+
field_name="_device__name",
67+
queryset=Device.objects.all(),
68+
to_field_name="name",
69+
label=_("Device (name)"),
70+
)
71+
device_id = django_filters.ModelMultipleChoiceFilter(
72+
field_name="_device",
73+
queryset=Device.objects.all(),
74+
to_field_name="id",
75+
label=_("Device (ID)"),
76+
)
77+
virtual_machine = django_filters.ModelMultipleChoiceFilter(
78+
field_name="_virtual_machine__name",
79+
queryset=VirtualMachine.objects.all(),
80+
to_field_name="name",
81+
label=_("Virtual Machine (name)"),
82+
)
83+
virtual_machine_id = django_filters.ModelMultipleChoiceFilter(
84+
field_name="_virtual_machine",
85+
queryset=VirtualMachine.objects.all(),
86+
to_field_name="id",
87+
label=_("Virtual Machine (ID)"),
88+
)
89+
90+
class Meta:
91+
model = ACINode
92+
fields: tuple = (
93+
"id",
94+
"name",
95+
"name_alias",
96+
"description",
97+
"node_id",
98+
"node_object_type",
99+
"node_object_id",
100+
"role",
101+
"node_type",
102+
"tep_ip_address",
103+
"nb_tenant",
104+
)
105+
106+
def search(self, queryset, name, value):
107+
"""Return a QuerySet filtered by the model's description."""
108+
if not value.strip():
109+
return queryset
110+
queryset_filter: Q = (
111+
Q(name__icontains=value)
112+
| Q(name_alias__icontains=value)
113+
| Q(description__icontains=value)
114+
)
115+
return queryset.filter(queryset_filter)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy