Cleanup & Reorg startup scripts (#691)
* Cleanup & Reorg startup scripts
This commit is contained in:
parent
b9dff0d22e
commit
8860d32f97
@ -1,42 +0,0 @@
|
||||
import sys
|
||||
|
||||
from dcim.models import Site
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
from tenancy.models import Tenant
|
||||
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
||||
|
||||
clusters = load_yaml("/opt/netbox/initializers/clusters.yml")
|
||||
|
||||
if clusters is None:
|
||||
sys.exit()
|
||||
|
||||
required_assocs = {"type": (ClusterType, "name")}
|
||||
|
||||
optional_assocs = {
|
||||
"site": (Site, "name"),
|
||||
"group": (ClusterGroup, "name"),
|
||||
"tenant": (Tenant, "name"),
|
||||
}
|
||||
|
||||
for params in clusters:
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
||||
for assoc, details in required_assocs.items():
|
||||
model, field = details
|
||||
query = {field: params.pop(assoc)}
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
for assoc, details in optional_assocs.items():
|
||||
if assoc in params:
|
||||
model, field = details
|
||||
query = {field: params.pop(assoc)}
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
cluster, created = Cluster.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
set_custom_fields_values(cluster, custom_field_data)
|
||||
|
||||
print("🗄️ Created cluster", cluster.name)
|
@ -1,15 +0,0 @@
|
||||
import sys
|
||||
|
||||
from startup_script_utils import load_yaml
|
||||
from virtualization.models import ClusterGroup
|
||||
|
||||
cluster_groups = load_yaml("/opt/netbox/initializers/cluster_groups.yml")
|
||||
|
||||
if cluster_groups is None:
|
||||
sys.exit()
|
||||
|
||||
for params in cluster_groups:
|
||||
cluster_group, created = ClusterGroup.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("🗄️ Created Cluster Group", cluster_group.name)
|
@ -52,6 +52,7 @@ for params in ip_addresses:
|
||||
params["assigned_object_id"] = Interface.objects.get(**query).id
|
||||
else:
|
||||
query = {field: params.pop(assoc)}
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
ip_address, created = IPAddress.objects.get_or_create(**params)
|
Loading…
Reference in New Issue
Block a user