diff --git a/netbox_cmdb/netbox_cmdb/migrations/0036_deviceinterface.py b/netbox_cmdb/netbox_cmdb/migrations/0036_deviceinterface.py new file mode 100644 index 0000000..eea6f64 --- /dev/null +++ b/netbox_cmdb/netbox_cmdb/migrations/0036_deviceinterface.py @@ -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')}, + }, + ), + ] diff --git a/netbox_cmdb/netbox_cmdb/models/__init__.py b/netbox_cmdb/netbox_cmdb/models/__init__.py index 26872ce..7bf185b 100644 --- a/netbox_cmdb/netbox_cmdb/models/__init__.py +++ b/netbox_cmdb/netbox_cmdb/models/__init__.py @@ -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 * diff --git a/netbox_cmdb/netbox_cmdb/models/interface.py b/netbox_cmdb/netbox_cmdb/models/interface.py new file mode 100644 index 0000000..ae06b45 --- /dev/null +++ b/netbox_cmdb/netbox_cmdb/models/interface.py @@ -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")