Update startup scripts to update or create records rather than get/create

This commit is contained in:
Marco Ceppi 2020-07-09 14:49:23 -04:00
parent 8daeadf19e
commit 88f5430f05
10 changed files with 16 additions and 11 deletions

View File

@ -14,7 +14,7 @@ with file.open('r') as stream:
if tenants is not None:
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:
print("🏠 Created tenant", tenant.name)

View File

@ -25,7 +25,7 @@ with file.open('r') as stream:
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:
print("🌐 Created region", region.name)

View File

@ -29,7 +29,7 @@ with file.open('r') as stream:
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 custom_fields is not None:

View File

@ -13,7 +13,7 @@ with file.open('r') as stream:
if manufacturers is not None:
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:
print("🏭 Created Manufacturer", manufacturer.name)

View File

@ -39,7 +39,7 @@ with file.open('r') as stream:
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 custom_fields is not None:

View File

@ -22,7 +22,7 @@ with file.open('r') as stream:
if color in color_tpl:
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:
print("🎨 Created rack role", rack_role.name)

View File

@ -40,7 +40,7 @@ with file.open('r') as stream:
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 custom_fields is not None:

View File

@ -23,7 +23,7 @@ with file.open('r') as stream:
if color in color_tpl:
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:
print("🎨 Created device role", device_role.name)

View File

@ -55,7 +55,7 @@ with file.open('r') as stream:
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 custom_fields is not None:

View File

@ -17,8 +17,13 @@ def template_customer_locker(devices, port_count):
name = '{}-{}'.format(strand0, strand1)
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:
print("🔗 Created interface {} for {}".format(interface.name, locker.name))
@ -29,7 +34,7 @@ def template_efr(devices, port_count):
for switch in devices:
i = 1
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
if created:
print("🔗 Created interface {} for {}".format(interface.name, switch.name))