Skip to content

Commit

Permalink
feat: Add Link model
Browse files Browse the repository at this point in the history
  • Loading branch information
djothi committed Sep 5, 2023
1 parent aef5675 commit 7feb144
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions netbox_cmdb/netbox_cmdb/migrations/0039_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('netbox_cmdb', '0038_portlayout'),
]

operations = [
migrations.CreateModel(
name='Link',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('state', models.CharField(default='staging', max_length=50)),
('monitoring_state', models.CharField(default='disabled', max_length=50)),
('interface_a', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_interface_a', to='netbox_cmdb.deviceinterface')),
('interface_b', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_interface_b', to='netbox_cmdb.deviceinterface')),
],
options={
'abstract': False,
},
),
]
32 changes: 32 additions & 0 deletions netbox_cmdb/netbox_cmdb/models/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.db import models
from netbox.models import ChangeLoggedModel

from netbox_cmdb.choices import AssetMonitoringStateChoices, AssetStateChoices

FEC_CHOICES = [
(None, "None"),
("rs", "Reed Solomon"),
Expand Down Expand Up @@ -123,6 +125,36 @@ class Meta:
unique_together = ("index", "parent_interface")


class Link(ChangeLoggedModel):
"""A link between two DeviceInterface."""

interface_a = models.ForeignKey(
to="DeviceInterface",
related_name="%(class)s_interface_a",
on_delete=models.CASCADE,
)
interface_b = models.ForeignKey(
to="DeviceInterface",
related_name="%(class)s_interface_b",
on_delete=models.CASCADE,
)
state = models.CharField(
max_length=50,
choices=AssetStateChoices,
default=AssetStateChoices.STATE_STAGING,
help_text="State of this Link",
)
monitoring_state = models.CharField(
max_length=50,
choices=AssetMonitoringStateChoices,
default=AssetMonitoringStateChoices.DISABLED,
help_text="Monitoring state of this Link",
)

def __str__(self):
return str(f"{self.interface_a} <--> {self.interface_b}")


class PortLayout(ChangeLoggedModel):
"""A port layout configuration on a Network device."""

Expand Down

0 comments on commit 7feb144

Please sign in to comment.