mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2025-08-13 17:57:41 +02:00
feat: Make startup scripts idempotent
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
|
||||
from ipam.models import ASN, RIR
|
||||
from startup_script_utils import load_yaml
|
||||
from startup_script_utils import load_yaml, split_params
|
||||
from tenancy.models import Tenant
|
||||
|
||||
asns = load_yaml("/opt/netbox/initializers/asns.yml")
|
||||
@ -9,8 +9,8 @@ asns = load_yaml("/opt/netbox/initializers/asns.yml")
|
||||
if asns is None:
|
||||
sys.exit()
|
||||
|
||||
match_params = ["asn", "rir"]
|
||||
required_assocs = {"rir": (RIR, "name")}
|
||||
|
||||
optional_assocs = {"tenant": (Tenant, "name")}
|
||||
|
||||
for params in asns:
|
||||
@ -27,7 +27,8 @@ for params in asns:
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
asn, created = ASN.objects.get_or_create(**params)
|
||||
matching_params, defaults = split_params(params, match_params)
|
||||
asn, created = ASN.objects.get_or_create(**matching_params, defaults=defaults)
|
||||
|
||||
if created:
|
||||
print(f"🔡 Created ASN {asn.asn}")
|
||||
|
Reference in New Issue
Block a user