mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-30 04:16:24 -06:00
Add migrations
This commit is contained in:
parent
44b627064c
commit
e0b1c1a8ad
@ -0,0 +1,72 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-29 15:05
|
||||
|
||||
import dcim.fields
|
||||
import django.db.models.deletion
|
||||
import taggit.managers
|
||||
import utilities.json
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def populate_macaddress_objects(apps, schema_editor):
|
||||
Interface = apps.get_model('dcim', 'Interface')
|
||||
VMInterface = apps.get_model('virtualization', 'VMInterface')
|
||||
MACAddress = apps.get_model('dcim', 'MACAddress')
|
||||
mac_addresses = []
|
||||
print()
|
||||
print('Converting MAC addresses...')
|
||||
for interface in Interface.objects.filter(_mac_address__isnull=False):
|
||||
mac_addresses.append(
|
||||
MACAddress(
|
||||
mac_address=interface._mac_address,
|
||||
interface=interface,
|
||||
)
|
||||
)
|
||||
for vm_interface in VMInterface.objects.filter(_mac_address__isnull=False):
|
||||
mac_addresses.append(
|
||||
MACAddress(
|
||||
mac_address=vm_interface._mac_address,
|
||||
vm_interface=vm_interface,
|
||||
)
|
||||
)
|
||||
MACAddress.objects.bulk_create(mac_addresses)
|
||||
print(f'Created {len(mac_addresses)} MAC address objects.')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dcim', '0194_charfield_null_choices'),
|
||||
('extras', '0122_charfield_null_choices'),
|
||||
('virtualization', '0042_rename_mac_address_vminterface__mac_address'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='interface',
|
||||
old_name='mac_address',
|
||||
new_name='_mac_address',
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MACAddress',
|
||||
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)),
|
||||
('description', models.CharField(blank=True, max_length=200)),
|
||||
('comments', models.TextField(blank=True)),
|
||||
('mac_address', dcim.fields.MACAddressField(blank=True, null=True)),
|
||||
('is_primary', models.BooleanField(default=False)),
|
||||
('interface', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='dcim.interface')),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
('vm_interface', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='virtualization.vminterface')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=populate_macaddress_objects,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
)
|
||||
]
|
@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-29 15:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('virtualization', '0041_charfield_null_choices'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='vminterface',
|
||||
old_name='mac_address',
|
||||
new_name='_mac_address',
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user