first commit
This commit is contained in:
23
netbox_librenms_plugin/migrations/0001_initial.py
Normal file
23
netbox_librenms_plugin/migrations/0001_initial.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0.9 on 2024-09-19 10:17
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="InterfaceTypeMapping",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(auto_created=True, primary_key=True, serialize=False),
|
||||
),
|
||||
("librenms_type", models.CharField(max_length=100, unique=True)),
|
||||
("netbox_type", models.CharField(default="other", max_length=50)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 5.0.9 on 2024-09-19 11:14
|
||||
|
||||
import taggit.managers
|
||||
import utilities.json
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("extras", "0121_customfield_related_object_filter"),
|
||||
("netbox_librenms_plugin", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="created",
|
||||
field=models.DateTimeField(auto_now_add=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="custom_field_data",
|
||||
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="last_updated",
|
||||
field=models.DateTimeField(auto_now=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="tags",
|
||||
field=taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag"),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 5.0.9 on 2024-10-17 10:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("netbox_librenms_plugin", "0002_interfacetypemapping_created_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="librenms_speed",
|
||||
field=models.BigIntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="interfacetypemapping",
|
||||
name="librenms_type",
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="interfacetypemapping",
|
||||
unique_together={("librenms_type", "librenms_speed")},
|
||||
),
|
||||
]
|
||||
46
netbox_librenms_plugin/migrations/0004_librenmssettings.py
Normal file
46
netbox_librenms_plugin/migrations/0004_librenmssettings.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 5.1.4 on 2025-08-07 12:50
|
||||
|
||||
import taggit.managers
|
||||
import utilities.json
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("extras", "0122_charfield_null_choices"),
|
||||
("netbox_librenms_plugin", "0003_interfacetypemapping_librenms_speed_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="LibreNMSSettings",
|
||||
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)),
|
||||
(
|
||||
"custom_field_data",
|
||||
models.JSONField(
|
||||
blank=True,
|
||||
default=dict,
|
||||
encoder=utilities.json.CustomFieldJSONEncoder,
|
||||
),
|
||||
),
|
||||
(
|
||||
"selected_server",
|
||||
models.CharField(default="default", max_length=100),
|
||||
),
|
||||
(
|
||||
"tags",
|
||||
taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag"),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "LibreNMS Settings",
|
||||
"verbose_name_plural": "LibreNMS Settings",
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.1.4 on 2025-08-07 13:07
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("netbox_librenms_plugin", "0004_librenmssettings"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="librenmssettings",
|
||||
name="created",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="librenmssettings",
|
||||
name="custom_field_data",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="librenmssettings",
|
||||
name="last_updated",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="librenmssettings",
|
||||
name="tags",
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated migration for adding description field to InterfaceTypeMapping
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("netbox_librenms_plugin", "0005_remove_librenmssettings_created_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="interfacetypemapping",
|
||||
name="description",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text="Optional description or notes about this interface type mapping",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
# Generated migration for adding vc_member_name_pattern field to LibreNMSSettings
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("netbox_librenms_plugin", "0006_interfacetypemapping_description"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="librenmssettings",
|
||||
name="vc_member_name_pattern",
|
||||
field=models.CharField(
|
||||
default="-M{position}",
|
||||
help_text="Pattern for naming virtual chassis member devices. Available placeholders: {master_name}, {position}, {serial}. Example: '-M{position}' results in 'switch01-M2'",
|
||||
max_length=100,
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated migration for adding import default settings
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("netbox_librenms_plugin", "0007_librenmssettings_vc_member_name_pattern"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="librenmssettings",
|
||||
name="use_sysname_default",
|
||||
field=models.BooleanField(
|
||||
default=True,
|
||||
help_text="Use SNMP sysName instead of LibreNMS hostname when importing devices",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="librenmssettings",
|
||||
name="strip_domain_default",
|
||||
field=models.BooleanField(
|
||||
default=False,
|
||||
help_text="Remove domain suffix from device names during import",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Convert the ``librenms_id`` custom field type to JSON.
|
||||
|
||||
Multi-server support stores ``librenms_id`` as a JSON dict
|
||||
(``{"server_key": device_id, …}``). Installations created before this
|
||||
change will have the custom field defined as type *integer* (documented)
|
||||
or *text* (some users created it with the wrong type). This migration
|
||||
converts any non-JSON type to JSON so that NetBox validation accepts the
|
||||
new dict format.
|
||||
|
||||
Existing bare-integer **values** on devices/VMs/interfaces are left
|
||||
untouched — they are migrated to the dict format on a per-object basis
|
||||
through the admin UI / API (see ``migrate_legacy_librenms_id`` in utils).
|
||||
"""
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def _convert_librenms_id_to_json(apps, schema_editor):
|
||||
db_alias = schema_editor.connection.alias
|
||||
CustomField = apps.get_model("extras", "CustomField")
|
||||
try:
|
||||
cf = CustomField.objects.using(db_alias).get(name="librenms_id")
|
||||
except CustomField.DoesNotExist:
|
||||
# Custom field hasn't been created yet — nothing to convert.
|
||||
return
|
||||
if cf.type != "json":
|
||||
cf.type = "json"
|
||||
cf.save(using=db_alias, update_fields=["type"])
|
||||
|
||||
|
||||
def _revert_librenms_id_to_integer(apps, schema_editor):
|
||||
db_alias = schema_editor.connection.alias
|
||||
CustomField = apps.get_model("extras", "CustomField")
|
||||
try:
|
||||
cf = CustomField.objects.using(db_alias).get(name="librenms_id")
|
||||
except CustomField.DoesNotExist:
|
||||
return
|
||||
|
||||
# Prevent unsafe downgrade if JSON-scoped values already exist.
|
||||
models_to_check = [
|
||||
("dcim", "Device"),
|
||||
("virtualization", "VirtualMachine"),
|
||||
("dcim", "Interface"),
|
||||
("virtualization", "VMInterface"),
|
||||
]
|
||||
for app_label, model_name in models_to_check:
|
||||
Model = apps.get_model(app_label, model_name)
|
||||
for value in (
|
||||
Model.objects.using(db_alias)
|
||||
.exclude(custom_field_data__librenms_id=None)
|
||||
.values_list("custom_field_data__librenms_id", flat=True)
|
||||
.iterator()
|
||||
):
|
||||
if isinstance(value, dict):
|
||||
raise RuntimeError(
|
||||
"Cannot reverse librenms_id CustomField to integer: "
|
||||
"JSON-scoped values already exist. Migrate them back to "
|
||||
"bare integers first."
|
||||
)
|
||||
|
||||
if cf.type == "json":
|
||||
cf.type = "integer"
|
||||
cf.save(using=db_alias, update_fields=["type"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("extras", "0001_initial"),
|
||||
("netbox_librenms_plugin", "0008_librenmssettings_import_defaults"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=_convert_librenms_id_to_json,
|
||||
reverse_code=_revert_librenms_id_to_integer,
|
||||
),
|
||||
]
|
||||
0
netbox_librenms_plugin/migrations/__init__.py
Normal file
0
netbox_librenms_plugin/migrations/__init__.py
Normal file
Reference in New Issue
Block a user