mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2025-03-02 00:51:20 +01:00
Cleanup & Reorg startup scripts (#691)
* Cleanup & Reorg startup scripts
This commit is contained in:
parent
b9dff0d22e
commit
8860d32f97
startup_scripts
020_object_permissions.py030_custom_fields.py040_custom_links.py050_tags.py060_webhooks.py070_tenant_groups.py080_tenants.py090_regions.py110_sites.py120_locations.py130_rack_roles.py140_clusters.py140_racks.py150_power_panels.py160_power_feeds.py165_cluster_groups.py170_manufacturers.py180_device_roles.py190_device_types.py200_devices.py210_dcim_interfaces.py220_platforms.py230_route_targets.py240_vrfs.py250_rirs.py260_asns.py270_aggregates.py280_prefix_vlan_roles.py290_cluster_types.py300_cluster_groups.py310_clusters.py320_vlan_groups.py330_vlans.py340_virtual_machines.py350_virtualization_interfaces.py360_prefixes.py370_ip_addresses.py380_primary_ips.py400_services.py420_providers.py440_circuit_types.py450_circuits.py
@ -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