mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Initial work on #2179: Allow a service to have multiple ports
This commit is contained in:
43
netbox/ipam/migrations/0039_service_ports_array.py
Normal file
43
netbox/ipam/migrations/0039_service_ports_array.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import django.contrib.postgres.fields
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def replicate_ports(apps, schema_editor):
|
||||
Service = apps.get_model('ipam', 'Service')
|
||||
# TODO: Figure out how to cast IntegerField to an array so we can use .update()
|
||||
for service in Service.objects.all():
|
||||
Service.objects.filter(pk=service.pk).update(ports=[service.port])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipam', '0038_custom_field_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='service',
|
||||
name='ports',
|
||||
field=django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.PositiveIntegerField(
|
||||
validators=[
|
||||
django.core.validators.MinValueValidator(1),
|
||||
django.core.validators.MaxValueValidator(65535)
|
||||
]
|
||||
),
|
||||
default=[],
|
||||
size=None
|
||||
),
|
||||
preserve_default=False,
|
||||
),
|
||||
|
||||
migrations.AlterModelOptions(
|
||||
name='service',
|
||||
options={'ordering': ('protocol', 'ports', 'pk')},
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=replicate_ports
|
||||
),
|
||||
]
|
15
netbox/ipam/migrations/0040_service_drop_port.py
Normal file
15
netbox/ipam/migrations/0040_service_drop_port.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipam', '0039_service_ports_array'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='service',
|
||||
name='port',
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user