Skip to content

Commit

Permalink
feat: add DeviceInterface model
Browse files Browse the repository at this point in the history
  • Loading branch information
djothi committed Dec 11, 2023
1 parent b1aa8fc commit 6f0d6e9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
33 changes: 33 additions & 0 deletions netbox_cmdb/netbox_cmdb/migrations/0036_deviceinterface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('dcim', '0161_cabling_cleanup'),
('netbox_cmdb', '0035_vlan'),
]

operations = [
migrations.CreateModel(
name='DeviceInterface',
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)),
('name', models.CharField(max_length=100)),
('enabled', models.BooleanField(default=True)),
('state', models.CharField(default='staging', max_length=50)),
('monitoring_state', models.CharField(default='disabled', max_length=50)),
('autonegotiation', models.BooleanField(default=True)),
('speed', models.PositiveIntegerField(blank=True, null=True)),
('fec', models.CharField(blank=True, max_length=5, null=True)),
('description', models.CharField(blank=True, max_length=100, null=True)),
('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)sdevice', to='dcim.device')),
],
options={
'unique_together': {('device', 'name')},
},
),
]
1 change: 1 addition & 0 deletions netbox_cmdb/netbox_cmdb/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from netbox_cmdb.models.bgp import *
from netbox_cmdb.models.bgp_community_list import *
from netbox_cmdb.models.circuit import *
from netbox_cmdb.models.interface import *
from netbox_cmdb.models.prefix_list import *
from netbox_cmdb.models.route_policy import *
from netbox_cmdb.models.vlan import *
Expand Down
54 changes: 54 additions & 0 deletions netbox_cmdb/netbox_cmdb/models/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.db import models
from netbox_cmdb.choices import AssetStateChoices, AssetMonitoringStateChoices
from netbox.models import ChangeLoggedModel

FEC_CHOICES = [
(None, "None"),
("rs", "Reed Solomon"),
("fc", "FireCode"),
]


class DeviceInterface(ChangeLoggedModel):
"""A device interface configuration."""

name = models.CharField(max_length=100)
enabled = models.BooleanField(default=True)
state = models.CharField(
max_length=50,
choices=AssetStateChoices,
default=AssetStateChoices.STATE_STAGING,
help_text="State of this DeviceInterface",
)
monitoring_state = models.CharField(
max_length=50,
choices=AssetMonitoringStateChoices,
default=AssetMonitoringStateChoices.DISABLED,
help_text="Monitoring state of this DeviceInterface",
)
device = models.ForeignKey(
to="dcim.Device",
on_delete=models.CASCADE,
related_name="%(class)sdevice",
null=False,
blank=False,
)
autonegotiation = models.BooleanField(default=True)
speed = models.PositiveIntegerField(
blank=True,
null=True,
help_text="Interface speed in kb/s",
)
fec = models.CharField(
choices=FEC_CHOICES,
max_length=5,
blank=True,
null=True,
)
description = models.CharField(max_length=100, blank=True, null=True)

def __str__(self):
return f"{self.device.name}--{self.name}"

class Meta:
unique_together = ("device", "name")

0 comments on commit 6f0d6e9

Please sign in to comment.