Skip to content

Commit

Permalink
Merge pull request #205 from nautobot/mzbroch/asndot
Browse files Browse the repository at this point in the history
Add ASNs ASDOT notation
  • Loading branch information
mzbroch authored May 22, 2024
2 parents 40cf78c + 0e5cc7f commit 223296e
Show file tree
Hide file tree
Showing 8 changed files with 711 additions and 800 deletions.
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[flake8]
ignore =
E501, # Line length is enforced by Black, so flake8 doesn't need to check it
W503 # Black disagrees with this rule, as does PEP 8; Black wins
# Line length is enforced by Black, so flake8 doesn't need to check it
E501,
# Black disagrees with this rule, as does PEP 8; Black wins
W503
exclude =
migrations,
__pycache__,
Expand Down
1 change: 1 addition & 0 deletions changes/29.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for ASNs ASDOT notation (RFC 5396).
7 changes: 7 additions & 0 deletions nautobot_bgp_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from nautobot.core.utils.data import deepmerge
from nautobot.tenancy.models import Tenant

from netutils.asn import int_to_asdot

from nautobot_bgp_models.choices import AFISAFIChoices


Expand Down Expand Up @@ -143,6 +145,11 @@ def __str__(self):
"""String representation of an AutonomousSystem."""
return f"AS {self.asn}"

@property
def asn_asdot(self):
"""ASDOT (RFC 5396) representation of an AutonomousSystem."""
return int_to_asdot(self.asn)


@extras_features(
"custom_fields",
Expand Down
4 changes: 3 additions & 1 deletion nautobot_bgp_models/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class AutonomousSystemTable(StatusTableMixin, BaseTable):
provider = tables.LinkColumn()
tags = TagColumn(url_name="plugins:nautobot_bgp_models:autonomoussystem_list")
actions = ButtonsColumn(model=models.AutonomousSystem)
asn_asdot = tables.Column(accessor=A("asn_asdot"), linkify=True, order_by=A("asn"), verbose_name="ASN ASDOT")

class Meta(BaseTable.Meta):
model = models.AutonomousSystem
fields = ("pk", "asn", "status", "provider", "description", "tags")
fields = ("pk", "asn", "asn_asdot", "status", "provider", "description", "tags")
default_columns = ("pk", "asn", "status", "provider", "description", "tags")


class AutonomousSystemRangeTable(StatusTableMixin, BaseTable):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<td>ASN</td>
<td>{{ object.asn }}</td>
</tr>
<tr>
<td>ASN - ASDOT</td>
<td>{{ object.asn_asdot }}</td>
</tr>
<tr>
<td>Description</td>
<td>{{ object.description }}</td>
Expand Down
8 changes: 8 additions & 0 deletions nautobot_bgp_models/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ def setUpTestData(cls):
asn=15521, status=status_active, description="Hi ex Premium Internet AS!"
)

cls.autonomous_system_32_bit = models.AutonomousSystem.objects.create(
asn=655460, status=status_active, description="Test Description"
)

def test_str(self):
"""Test string representation of an AutonomousSystem."""
self.assertEqual(str(self.autonomous_system), "AS 15521")

def test_asdot(self):
"""Test representation of an AutonomousSystem using asdot notation."""
self.assertEqual(self.autonomous_system_32_bit.asn_asdot, "10.100")


class AutonomousSystemRangeTestCase(TestCase):
"""Test the AutonomousSystemRange model."""
Expand Down
1,480 changes: 683 additions & 797 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ include = [
[tool.poetry.dependencies]
python = ">=3.8,<3.12"
nautobot = "^2.0.3"
netutils = "^1.6.0"
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 223296e

Please sign in to comment.