Update Custom Field logic for Netbox v2.10.x
This commit is contained in:
parent
036f94a450
commit
5c9bea8b50
24 changed files with 168 additions and 268 deletions
|
@ -1,10 +1,10 @@
|
|||
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
||||
from virtualization.models import Cluster
|
||||
from tenancy.models import Tenant
|
||||
from extras.models import CustomField, CustomFieldValue
|
||||
from startup_script_utils import load_yaml
|
||||
import sys
|
||||
|
||||
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
||||
from startup_script_utils import *
|
||||
from tenancy.models import Tenant
|
||||
from virtualization.models import Cluster
|
||||
|
||||
devices = load_yaml('/opt/netbox/initializers/devices.yml')
|
||||
|
||||
if devices is None:
|
||||
|
@ -24,7 +24,8 @@ optional_assocs = {
|
|||
}
|
||||
|
||||
for params in devices:
|
||||
custom_fields = params.pop('custom_fields', None)
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
||||
# primary ips are handled later in `270_primary_ips.py`
|
||||
params.pop('primary_ip4', None)
|
||||
params.pop('primary_ip6', None)
|
||||
|
@ -45,15 +46,6 @@ for params in devices:
|
|||
device, created = Device.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
if custom_fields is not None:
|
||||
for cf_name, cf_value in custom_fields.items():
|
||||
custom_field = CustomField.objects.get(name=cf_name)
|
||||
custom_field_value = CustomFieldValue.objects.create(
|
||||
field=custom_field,
|
||||
obj=device,
|
||||
value=cf_value
|
||||
)
|
||||
|
||||
device.custom_field_values.add(custom_field_value)
|
||||
set_custom_fields_values(device, custom_field_data)
|
||||
|
||||
print("🖥️ Created device", device.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue