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 ipam.models import VRF
|
||||
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,
|
||||
)
|
||||
from tenancy.models import Tenant
|
||||
|
||||
vrfs = load_yaml("/opt/netbox/initializers/vrfs.yml")
|
||||
|
@ -9,6 +14,7 @@ vrfs = load_yaml("/opt/netbox/initializers/vrfs.yml")
|
|||
if vrfs is None:
|
||||
sys.exit()
|
||||
|
||||
match_params = ["name", "rd"]
|
||||
optional_assocs = {"tenant": (Tenant, "name")}
|
||||
|
||||
for params in vrfs:
|
||||
|
@ -21,7 +27,8 @@ for params in vrfs:
|
|||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
vrf, created = VRF.objects.get_or_create(**params)
|
||||
matching_params, defaults = split_params(params)
|
||||
vrf, created = VRF.objects.get_or_create(**matching_params, defaults=defaults)
|
||||
|
||||
if created:
|
||||
print("📦 Created VRF", vrf.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue