-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
583 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added ASN Range model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""BGP helper functions.""" | ||
|
||
|
||
def add_available_asns(instance, asns): | ||
"""Create fake records for all gaps between used Autonomous Systems.""" | ||
new_list = [] | ||
last_asn = None | ||
for asn_val in asns: | ||
if asn_val.asn == instance.asn_min: | ||
new_list.append(asn_val) | ||
last_asn = asn_val.asn | ||
elif not last_asn: | ||
new_list.append({"asn": instance.asn_min, "available": asn_val.asn - instance.asn_min}) | ||
new_list.append(asn_val) | ||
last_asn = asn_val.asn | ||
elif instance.asn_min <= asn_val.asn <= instance.asn_max: | ||
if asn_val.asn - last_asn > 1: | ||
new_list.append({"asn": last_asn + 1, "available": asn_val.asn - last_asn - 1}) | ||
new_list.append(asn_val) | ||
last_asn = asn_val.asn | ||
elif asn_val.asn == instance.asn_max: | ||
new_list.append(asn_val) | ||
last_asn = asn_val.asn | ||
|
||
if not asns: | ||
new_list.append({"asn": instance.asn_min, "available": instance.asn_max - instance.asn_min + 1}) | ||
elif last_asn < instance.asn_max: | ||
new_list.append({"asn": last_asn + 1, "available": instance.asn_max - last_asn}) | ||
|
||
return new_list |
58 changes: 58 additions & 0 deletions
58
nautobot_bgp_models/migrations/0009_autonomoussystemrange.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# pylint: disable=missing-module-docstring,missing-function-docstring,missing-class-docstring,invalid-name | ||
|
||
import uuid | ||
import django.core.serializers.json | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import nautobot.core.models.fields | ||
import nautobot.dcim.fields | ||
import nautobot.extras.models.mixins | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tenancy", "0008_tagsfield"), | ||
("extras", "0098_rename_data_jobresult_result"), | ||
("nautobot_bgp_models", "0008_nautobotv2_updates"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="AutonomousSystemRange", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True, null=True)), | ||
("last_updated", models.DateTimeField(auto_now=True, null=True)), | ||
( | ||
"_custom_field_data", | ||
models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder), | ||
), | ||
("name", models.CharField(max_length=255, unique=True)), | ||
("asn_min", nautobot.dcim.fields.ASNField()), | ||
("asn_max", nautobot.dcim.fields.ASNField()), | ||
("description", models.CharField(blank=True, max_length=255)), | ||
("tags", nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag")), | ||
( | ||
"tenant", | ||
models.ForeignKey( | ||
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to="tenancy.tenant" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Autonomous System Range", | ||
"ordering": ["asn_min"], | ||
}, | ||
bases=( | ||
models.Model, | ||
nautobot.extras.models.mixins.DynamicGroupMixin, | ||
nautobot.extras.models.mixins.NotesMixin, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
nautobot_bgp_models/templates/nautobot_bgp_models/autonomoussystemrange_retrieve.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{% extends 'generic/object_detail.html' %} | ||
{% load helpers %} | ||
|
||
{% block content_left_page %} | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<strong>BGP Autonomous System Range</strong> | ||
</div> | ||
<table class="table table-hover panel-body attr-table"> | ||
<tr> | ||
<td>Start ASN</td> | ||
<td>{{ object.asn_min }}</td> | ||
</tr> | ||
<tr> | ||
<td>End ASN</td> | ||
<td>{{ object.asn_max }}</td> | ||
</tr> | ||
<tr> | ||
<td>Tenant</td> | ||
<td>{{ object.tenant | hyperlinked_object }}</td> | ||
</tr> | ||
<tr> | ||
<td>Description</td> | ||
<td>{{ object.description }}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
{% endblock content_left_page %} | ||
|
||
{% block content_right_page %} | ||
{% include 'utilities/obj_table.html' with table=asn_range_table table_template='panel_table.html' heading='ASNs' bulk_edit_url='plugins:nautobot_bgp_models:autonomoussystem_bulk_edit' bulk_delete_url='plugins:nautobot_bgp_models:autonomoussystem_bulk_delete' %} | ||
{% endblock content_right_page %} |
Oops, something went wrong.