Skip to content

Commit 5d6dbf6

Browse files
gsnider2195mzbroch
andauthored
Implement component UI (#268)
Co-authored-by: mzb <marek@zbroch.com>
1 parent be61636 commit 5d6dbf6

33 files changed

Lines changed: 1340 additions & 1642 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
fail-fast: true
108108
matrix:
109109
python-version: ["3.11"]
110-
nautobot-version: ["2.4.2"]
110+
nautobot-version: ["2.4.19"]
111111
env:
112112
INVOKE_NAUTOBOT_BGP_MODELS_PYTHON_VER: "${{ matrix.python-version }}"
113113
INVOKE_NAUTOBOT_BGP_MODELS_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
@@ -153,13 +153,13 @@ jobs:
153153
strategy:
154154
fail-fast: true
155155
matrix:
156-
python-version: ["3.9"] # 3.12 stable is tested in unittest_report stage.
156+
python-version: ["3.10"] # 3.12 stable is tested in unittest_report stage.
157157
db-backend: ["postgresql"]
158158
nautobot-version: ["stable"]
159159
include:
160160
- python-version: "3.11"
161161
db-backend: "postgresql"
162-
nautobot-version: "2.4.2"
162+
nautobot-version: "2.4.19"
163163
- python-version: "3.12"
164164
db-backend: "mysql"
165165
nautobot-version: "stable"

changes/268.changed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed minimum Nautobot version to 2.4.19.

changes/268.housekeeping

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Migrated views to the UI Component Framework.

invoke.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
nautobot_bgp_models:
3-
nautobot_ver: "2.4.2"
3+
nautobot_ver: "2.4.19"
44
python_ver: "3.11"
55
# local: false
66
# compose_dir: "/full/path/to/nautobot-app-bgp-models/development"

invoke.mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
nautobot_bgp_models:
33
project_name: "nautobot-bgp-models"
4-
nautobot_ver: "2.4.2"
4+
nautobot_ver: "2.4.19"
55
local: false
66
python_ver: "3.11"
77
compose_dir: "development"

nautobot_bgp_models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NautobotBGPModelsConfig(NautobotAppConfig):
1919
description = "Nautobot BGP Models App."
2020
base_url = "bgp"
2121
required_settings = []
22-
min_version = "2.0.3"
22+
min_version = "2.4.15"
2323
max_version = "2.9999"
2424
default_settings = {
2525
"default_statuses": {

nautobot_bgp_models/api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class ExtraAttributesSerializerMixin(serializers.Serializer): # pylint: disable
6262
def to_representation(self, instance):
6363
"""Render the model instance to a Python dict.
6464
65-
If `include_inherited` is specified as a request parameter, include object's get_extra_attributes().
65+
If `include_inherited` is specified as a request parameter, include object's extra_attributes_inherited.
6666
"""
6767
req = self.context["request"]
6868
if hasattr(req, "query_params") and is_truthy(req.query_params.get("include_inherited", False)):
69-
setattr(instance, "extra_attributes", instance.get_extra_attributes())
69+
setattr(instance, "extra_attributes", instance.extra_attributes_inherited)
7070
return super().to_representation(instance)
7171

7272

nautobot_bgp_models/models.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def get_extra_attributes_paths(self):
9898

9999
return [rgetattr(self, f"{x}.extra_attributes", None) for x in paths]
100100

101-
def get_extra_attributes(self):
101+
@property
102+
def extra_attributes_inherited(self):
102103
"""Render extra attributes for an object."""
103104
# always manually query for extra attributes
104105
extra_attributes_data = [x for x in self.get_extra_attributes_paths if x]
@@ -163,8 +164,8 @@ class AutonomousSystemRange(PrimaryModel):
163164
"""Autonomous System Range information."""
164165

165166
name = models.CharField(max_length=255, unique=True, blank=False)
166-
asn_min = ASNField(verbose_name="Start", help_text="Min value for 32-bit autonomous system number")
167-
asn_max = ASNField(verbose_name="End", help_text="Max value for 32-bit autonomous system number")
167+
asn_min = ASNField(verbose_name="Start ASN", help_text="Min value for 32-bit autonomous system number")
168+
asn_max = ASNField(verbose_name="End ASN", help_text="Max value for 32-bit autonomous system number")
168169
description = models.CharField(max_length=255, blank=True)
169170
tenant = models.ForeignKey(to=Tenant, on_delete=models.PROTECT, blank=True, null=True)
170171

@@ -192,6 +193,13 @@ def get_next_available_asn(self):
192193

193194
return None
194195

196+
@property
197+
def asns(self):
198+
"""Return the first available ASN number in the range, or None if none are available."""
199+
asn_nums = AutonomousSystem.objects.filter(asn__gte=self.asn_min, asn__lte=self.asn_max)
200+
201+
return asn_nums
202+
195203

196204
@extras_features(
197205
"custom_fields",
@@ -496,7 +504,7 @@ class PeerEndpoint(PrimaryModel, InheritanceMixin, BGPExtraAttributesMixin):
496504
blank=True,
497505
null=True,
498506
related_name="bgp_peer_endpoints",
499-
verbose_name="BGP Peer IP",
507+
verbose_name="Source IP Address",
500508
)
501509

502510
source_interface = models.ForeignKey( # update source
@@ -689,6 +697,11 @@ def __str__(self):
689697

690698
return f"{self.afi_safi} AF - {self.routing_instance.device}"
691699

700+
@property
701+
def display(self):
702+
"""The string representation of the model as a model property."""
703+
return str(self)
704+
692705
def validate_unique(self, exclude=None):
693706
"""Validate uniqueness."""
694707
if (

nautobot_bgp_models/tables.py

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AutonomousSystemTable(StatusTableMixin, BaseTable):
3333

3434
pk = ToggleColumn()
3535
asn = tables.TemplateColumn(template_code=ASN_LINK, verbose_name="ASN")
36-
provider = tables.LinkColumn()
36+
provider = tables.Column(linkify=True)
3737
tags = TagColumn(url_name="plugins:nautobot_bgp_models:autonomoussystem_list")
3838
actions = ButtonsColumn(model=models.AutonomousSystem)
3939
asn_asdot = tables.Column(accessor=A("asn_asdot"), linkify=True, order_by=A("asn"), verbose_name="ASN ASDOT")
@@ -48,10 +48,10 @@ class AutonomousSystemRangeTable(StatusTableMixin, BaseTable):
4848
"""Table representation of AutonomousSystem records."""
4949

5050
pk = ToggleColumn()
51-
name = tables.LinkColumn()
52-
asn_min = tables.LinkColumn()
53-
asn_max = tables.LinkColumn()
54-
tenant = tables.LinkColumn()
51+
name = tables.Column(linkify=True)
52+
asn_min = tables.Column(linkify=True)
53+
asn_max = tables.Column(linkify=True)
54+
tenant = tables.Column(linkify=True)
5555
tags = TagColumn(url_name="plugins:nautobot_bgp_models:autonomoussystemrange_list")
5656
actions = ButtonsColumn(model=models.AutonomousSystemRange)
5757

@@ -69,9 +69,9 @@ class BGPRoutingInstanceTable(StatusTableMixin, BaseTable):
6969
args=[A("pk")],
7070
text=str,
7171
)
72-
device = tables.LinkColumn()
73-
autonomous_system = tables.LinkColumn()
74-
router_id = tables.LinkColumn()
72+
device = tables.Column(linkify=True)
73+
autonomous_system = tables.Column(linkify=True)
74+
router_id = tables.Column(linkify=True)
7575
tags = TagColumn(url_name="plugins:nautobot_bgp_models:bgproutinginstance_list")
7676
actions = ButtonsColumn(model=models.BGPRoutingInstance)
7777

@@ -93,16 +93,16 @@ class PeerGroupTable(BaseTable):
9393
"""Table representation of PeerGroup records."""
9494

9595
pk = ToggleColumn()
96-
name = tables.LinkColumn()
97-
peergroup_template = tables.LinkColumn()
98-
routing_instance = tables.LinkColumn()
99-
vrf = tables.LinkColumn()
96+
name = tables.Column(linkify=True)
97+
peergroup_template = tables.Column(linkify=True)
98+
routing_instance = tables.Column(linkify=True)
99+
vrf = tables.Column(linkify=True)
100100
enabled = BooleanColumn()
101101
role = ColoredLabelColumn()
102-
autonomous_system = tables.LinkColumn()
103-
secret = tables.LinkColumn()
104-
source_ip = tables.LinkColumn()
105-
source_interface = tables.LinkColumn()
102+
autonomous_system = tables.Column(linkify=True)
103+
secret = tables.Column(linkify=True)
104+
source_ip = tables.Column(linkify=True)
105+
source_interface = tables.Column(linkify=True)
106106
tags = TagColumn(url_name="plugins:nautobot_bgp_models:peergroup_list")
107107

108108
actions = ButtonsColumn(model=models.PeerGroup)
@@ -140,11 +140,11 @@ class PeerGroupTemplateTable(BaseTable):
140140
"""Table representation of PeerGroup records."""
141141

142142
pk = ToggleColumn()
143-
name = tables.LinkColumn()
143+
name = tables.Column(linkify=True)
144144
enabled = BooleanColumn()
145145
role = ColoredLabelColumn()
146-
autonomous_system = tables.LinkColumn()
147-
secret = tables.LinkColumn()
146+
autonomous_system = tables.Column(linkify=True)
147+
secret = tables.Column(linkify=True)
148148
actions = ButtonsColumn(model=models.PeerGroupTemplate)
149149

150150
class Meta(BaseTable.Meta):
@@ -172,46 +172,49 @@ class PeerEndpointTable(BaseTable):
172172
"""Table representation of PeerEndpoint records."""
173173

174174
pk = ToggleColumn()
175-
id = tables.LinkColumn()
176-
routing_instance = tables.LinkColumn()
175+
id = tables.Column(linkify=True)
176+
routing_instance = tables.Column(linkify=True)
177177
role = ColoredLabelColumn()
178-
source_ip = tables.LinkColumn()
179-
source_interface = tables.LinkColumn()
180-
autonomous_system = tables.LinkColumn()
181-
remote_autonomous_system = tables.LinkColumn()
182-
peer = tables.LinkColumn()
183-
peering = tables.LinkColumn()
184-
vrf = tables.LinkColumn()
185-
peer_group = tables.LinkColumn()
178+
source_ip = tables.Column(linkify=True)
179+
source_interface = tables.Column(linkify=True)
180+
local_ip = tables.Column(linkify=True)
181+
autonomous_system = tables.Column(linkify=True)
182+
# remote_autonomous_system = tables.Column(linkify=True)
183+
peer = tables.Column(linkify=True)
184+
peering = tables.Column(linkify=True)
185+
vrf = tables.Column(linkify=True)
186+
peer_group = tables.Column(linkify=True)
186187
tags = TagColumn(url_name="plugins:nautobot_bgp_models:peerendpoint_list")
187188
# actions = ButtonsColumn(model=models.PeerEndpoint)
188189

189190
class Meta(BaseTable.Meta):
190191
model = models.PeerEndpoint
191192
fields = (
192-
"pk",
193+
# "pk",
193194
"id",
194195
"routing_instance",
195196
"role",
196197
"source_ip",
197198
"source_interface",
199+
"local_ip",
198200
"autonomous_system",
199-
"remote_autonomous_system",
201+
# "remote_autonomous_system",
200202
"peer",
201203
"peering",
202204
"vrf",
203205
"peer_group",
204206
"tags",
205207
)
206208
default_columns = (
207-
"pk",
209+
# "pk",
208210
"id",
209211
"routing_instance",
210212
"role",
211213
"source_ip",
214+
"local_ip",
212215
"source_interface",
213216
"autonomous_system",
214-
"remote_autonomous_system",
217+
# "remote_autonomous_system",
215218
"peer",
216219
"peering",
217220
"vrf",
@@ -256,14 +259,10 @@ class AddressFamilyTable(BaseTable):
256259
"""Table representation of AddressFamily records."""
257260

258261
pk = ToggleColumn()
259-
address_family = tables.LinkColumn(
260-
viewname="plugins:nautobot_bgp_models:addressfamily",
261-
args=[A("pk")],
262-
text=str,
263-
)
264-
routing_instance = tables.LinkColumn()
262+
address_family = tables.Column(linkify=True, accessor="display")
263+
routing_instance = tables.Column(linkify=True)
265264
afi_safi = tables.Column()
266-
vrf = tables.LinkColumn()
265+
vrf = tables.Column(linkify=True)
267266
actions = ButtonsColumn(model=models.AddressFamily)
268267

269268
class Meta(BaseTable.Meta):
@@ -294,7 +293,7 @@ class PeerGroupAddressFamilyTable(BaseTable):
294293
args=[A("pk")],
295294
text=str,
296295
)
297-
peer_group = tables.LinkColumn()
296+
peer_group = tables.Column(linkify=True)
298297
afi_safi = tables.Column()
299298
actions = ButtonsColumn(model=models.PeerGroupAddressFamily)
300299

@@ -330,7 +329,7 @@ class PeerEndpointAddressFamilyTable(BaseTable):
330329
args=[A("pk")],
331330
text=str,
332331
)
333-
peer_endpoint = tables.LinkColumn()
332+
peer_endpoint = tables.Column(linkify=True)
334333
afi_safi = tables.Column()
335334
actions = ButtonsColumn(model=models.PeerEndpointAddressFamily)
336335

0 commit comments

Comments
 (0)