From 8a4edcdb0b4a7d9663b607f089f499cca615c6ed Mon Sep 17 00:00:00 2001 From: Djothi Carpentier Date: Mon, 16 Dec 2024 18:08:47 +0400 Subject: [PATCH] feat: Add PortLayout model --- .../netbox_cmdb/migrations/0041_portlayout.py | 32 +++++++++++++++++++ netbox_cmdb/netbox_cmdb/models/interface.py | 17 ++++++++++ 2 files changed, 49 insertions(+) create mode 100644 netbox_cmdb/netbox_cmdb/migrations/0041_portlayout.py diff --git a/netbox_cmdb/netbox_cmdb/migrations/0041_portlayout.py b/netbox_cmdb/netbox_cmdb/migrations/0041_portlayout.py new file mode 100644 index 0000000..7032a2c --- /dev/null +++ b/netbox_cmdb/netbox_cmdb/migrations/0041_portlayout.py @@ -0,0 +1,32 @@ +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0161_cabling_cleanup'), + ('netbox_cmdb', '0040_snmpcommunity_snmp'), + ] + + operations = [ + migrations.CreateModel( + name='PortLayout', + 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=64)), + ('label_name', models.CharField(max_length=64)), + ('logical_name', models.CharField(max_length=64)), + ('vendor_name', models.CharField(max_length=64)), + ('vendor_short_name', models.CharField(max_length=64)), + ('vendor_long_name', models.CharField(max_length=64)), + ('device_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_device_type', to='dcim.devicetype')), + ('network_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_network_role', to='dcim.devicerole')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/netbox_cmdb/netbox_cmdb/models/interface.py b/netbox_cmdb/netbox_cmdb/models/interface.py index 10baa85..5612a74 100644 --- a/netbox_cmdb/netbox_cmdb/models/interface.py +++ b/netbox_cmdb/netbox_cmdb/models/interface.py @@ -160,3 +160,20 @@ def save(self, *args, **kwargs): class Meta: unique_together = ("index", "parent_interface") + + +class PortLayout(ChangeLoggedModel): + """A port layout configuration on a Network device.""" + + device_type = models.ForeignKey( + to="dcim.DeviceType", related_name="%(class)s_device_type", on_delete=models.CASCADE + ) + network_role = models.ForeignKey( + to="dcim.DeviceRole", related_name="%(class)s_network_role", on_delete=models.CASCADE + ) + name = models.CharField(max_length=64) + label_name = models.CharField(max_length=64) + logical_name = models.CharField(max_length=64) + vendor_name = models.CharField(max_length=64) + vendor_short_name = models.CharField(max_length=64) + vendor_long_name = models.CharField(max_length=64)