feat: Make startup scripts idempotent
This commit is contained in:
parent
a6eb4fef00
commit
9be7b0e109
42 changed files with 275 additions and 95 deletions
|
@ -1,7 +1,12 @@
|
|||
import sys
|
||||
|
||||
from circuits.models import Provider
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
from startup_script_utils import (
|
||||
load_yaml,
|
||||
pop_custom_fields,
|
||||
set_custom_fields_values,
|
||||
split_params,
|
||||
)
|
||||
|
||||
providers = load_yaml("/opt/netbox/initializers/providers.yml")
|
||||
|
||||
|
@ -11,7 +16,8 @@ if providers is None:
|
|||
for params in providers:
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
||||
provider, created = Provider.objects.get_or_create(**params)
|
||||
matching_params, defaults = split_params(params)
|
||||
provider, created = Provider.objects.get_or_create(**matching_params, defaults=defaults)
|
||||
|
||||
if created:
|
||||
print("📡 Created provider", provider.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue