mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -06:00
Update startup scripts to update or create records rather than get/create
This commit is contained in:
parent
8daeadf19e
commit
88f5430f05
@ -14,7 +14,7 @@ with file.open('r') as stream:
|
|||||||
if tenants is not None:
|
if tenants is not None:
|
||||||
for params in tenants:
|
for params in tenants:
|
||||||
|
|
||||||
tenant, created = Tenant.objects.get_or_create(**params)
|
tenant, created = Tenant.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
print("🏠 Created tenant", tenant.name)
|
print("🏠 Created tenant", tenant.name)
|
||||||
|
@ -25,7 +25,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
region, created = Region.objects.get_or_create(**params)
|
region, created = Region.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
print("🌐 Created region", region.name)
|
print("🌐 Created region", region.name)
|
||||||
|
@ -29,7 +29,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
site, created = Site.objects.get_or_create(**params)
|
site, created = Site.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
if custom_fields is not None:
|
||||||
|
@ -13,7 +13,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
if manufacturers is not None:
|
if manufacturers is not None:
|
||||||
for params in manufacturers:
|
for params in manufacturers:
|
||||||
manufacturer, created = Manufacturer.objects.get_or_create(**params)
|
manufacturer, created = Manufacturer.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
print("🏭 Created Manufacturer", manufacturer.name)
|
print("🏭 Created Manufacturer", manufacturer.name)
|
||||||
|
@ -39,7 +39,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
device_type, created = DeviceType.objects.get_or_create(**params)
|
device_type, created = DeviceType.objects.update_or_create(model=params['model'], manufacturer=params['manufacturer'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
if custom_fields is not None:
|
||||||
|
@ -22,7 +22,7 @@ with file.open('r') as stream:
|
|||||||
if color in color_tpl:
|
if color in color_tpl:
|
||||||
params['color'] = color_tpl[0]
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
rack_role, created = RackRole.objects.get_or_create(**params)
|
rack_role, created = RackRole.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
print("🎨 Created rack role", rack_role.name)
|
print("🎨 Created rack role", rack_role.name)
|
||||||
|
@ -40,7 +40,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
rack, created = Rack.objects.get_or_create(**params)
|
rack, created = Rack.objects.update_or_create(name=params['name'], site=params['site'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
if custom_fields is not None:
|
||||||
|
@ -23,7 +23,7 @@ with file.open('r') as stream:
|
|||||||
if color in color_tpl:
|
if color in color_tpl:
|
||||||
params['color'] = color_tpl[0]
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
device_role, created = DeviceRole.objects.get_or_create(**params)
|
device_role, created = DeviceRole.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
print("🎨 Created device role", device_role.name)
|
print("🎨 Created device role", device_role.name)
|
||||||
|
@ -55,7 +55,7 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
device, created = Device.objects.get_or_create(**params)
|
device, created = Device.objects.update_or_create(name=params['name'], defaults=params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
if custom_fields is not None:
|
||||||
|
@ -17,8 +17,13 @@ def template_customer_locker(devices, port_count):
|
|||||||
name = '{}-{}'.format(strand0, strand1)
|
name = '{}-{}'.format(strand0, strand1)
|
||||||
|
|
||||||
i += 2
|
i += 2
|
||||||
|
interface_data = {
|
||||||
|
'name': name,
|
||||||
|
'device': locker,
|
||||||
|
'type': 'keystone',
|
||||||
|
}
|
||||||
|
|
||||||
interface, created = Interface.objects.get_or_create(name=name, device=locker, type='keystone')
|
interface, created = Interface.objects.update_or_create(name=name, device=locker, defaults=interface_data)
|
||||||
if created:
|
if created:
|
||||||
print("🔗 Created interface {} for {}".format(interface.name, locker.name))
|
print("🔗 Created interface {} for {}".format(interface.name, locker.name))
|
||||||
|
|
||||||
@ -29,7 +34,7 @@ def template_efr(devices, port_count):
|
|||||||
for switch in devices:
|
for switch in devices:
|
||||||
i = 1
|
i = 1
|
||||||
while i <= port_count:
|
while i <= port_count:
|
||||||
interface, created = Interface.objects.get_or_create(name=f'xe-0/0/{i}', device=switch, type='10gbase-x-sfpp')
|
interface, created = Interface.objects.update_or_create(name=f'xe-0/0/{i}', device=switch, defaults={'device': switch, 'type': '10gbase-x-sfpp'})
|
||||||
i += 1
|
i += 1
|
||||||
if created:
|
if created:
|
||||||
print("🔗 Created interface {} for {}".format(interface.name, switch.name))
|
print("🔗 Created interface {} for {}".format(interface.name, switch.name))
|
||||||
|
Loading…
Reference in New Issue
Block a user