Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 31 additions & 38 deletions netbox_acls/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.translation import gettext_lazy as _
from netbox.tables import NetBoxTable, columns

from .models import AccessList, ACLExtendedRule, ACLAssignment, ACLStandardRule
from .models import AccessList, ACLAssignment, ACLExtendedRule, ACLStandardRule

__all__ = (
"AccessListTable",
Expand Down Expand Up @@ -58,7 +58,6 @@ class Meta(NetBoxTable.Meta):
"type",
"rule_count",
"default_action",
"tags",
)


Expand Down Expand Up @@ -114,13 +113,12 @@ class Meta(NetBoxTable.Meta):
"type",
"assigned_object",
"direction",
"tags",
)


class ACLStandardRuleTable(NetBoxTable):
class ACLRuleTable(NetBoxTable):
"""
Defines the table view for the ACLStandardRule model.
Abstract table for all ACL rules.
"""

access_list = tables.Column(
Expand All @@ -130,9 +128,6 @@ class ACLStandardRuleTable(NetBoxTable):
linkify=True,
)
action = columns.ChoiceFieldColumn()
tags = columns.TagColumn(
url_name="plugins:netbox_acls:aclstandardrule_list",
)

# Source
source_type = columns.ContentTypeColumn(
Expand All @@ -145,7 +140,6 @@ class ACLStandardRuleTable(NetBoxTable):
)

class Meta(NetBoxTable.Meta):
model = ACLStandardRule
fields = (
"pk",
"id",
Expand All @@ -156,42 +150,41 @@ class Meta(NetBoxTable.Meta):
"tags",
"description",
"source",
"source_type",
)
default_columns = (
"access_list",
"index",
"action",
"remark",
"source",
"tags",
)


class ACLExtendedRuleTable(NetBoxTable):
class ACLStandardRuleTable(ACLRuleTable):
"""
Defines the table view for the ACLExtendedRule model.
Defines the table view for the ACLStandardRule model.
"""

access_list = tables.Column(
linkify=True,
)
index = tables.Column(
linkify=True,
)
action = columns.ChoiceFieldColumn()
tags = columns.TagColumn(
url_name="plugins:netbox_acls:aclextendedrule_list",
url_name="plugins:netbox_acls:aclstandardrule_list",
)

class Meta(ACLRuleTable.Meta):
model = ACLStandardRule


class ACLExtendedRuleTable(ACLRuleTable):
"""
Defines the table view for the ACLExtendedRule model.
"""

protocol = columns.ChoiceFieldColumn()

# Source
source_type = columns.ContentTypeColumn(
verbose_name=_("Source Type"),
)
source = tables.Column(
verbose_name=_("Source"),
orderable=False,
linkify=True,
source_ports = columns.ArrayColumn(
verbose_name=_("Source Ports"),
empty_values=([],),
)

# Destination
Expand All @@ -203,21 +196,22 @@ class ACLExtendedRuleTable(NetBoxTable):
orderable=False,
linkify=True,
)
destination_ports = columns.ArrayColumn(
verbose_name=_("Destination Ports"),
empty_values=([],),
)

class Meta(NetBoxTable.Meta):
tags = columns.TagColumn(
url_name="plugins:netbox_acls:aclextendedrule_list",
)

class Meta(ACLRuleTable.Meta):
model = ACLExtendedRule
fields = (
"pk",
"id",
"access_list",
"index",
"action",
"remark",
"tags",
"description",
"source",
*(ACLRuleTable.Meta.fields),
"source_ports",
"destination",
"destination_type",
"destination_ports",
"protocol",
)
Expand All @@ -231,5 +225,4 @@ class Meta(NetBoxTable.Meta):
"source_ports",
"destination",
"destination_ports",
"tags",
)
Loading