From 8860d32f976510a2f148c88b6da90cdf72ed4cd0 Mon Sep 17 00:00:00 2001 From: Ryan Merolle Date: Thu, 3 Feb 2022 11:10:39 -0500 Subject: [PATCH] Cleanup & Reorg startup scripts (#691) * Cleanup & Reorg startup scripts --- ...rmissions.py => 020_object_permissions.py} | 0 ..._custom_fields.py => 030_custom_fields.py} | 0 ...80_custom_links.py => 040_custom_links.py} | 0 startup_scripts/{020_tags.py => 050_tags.py} | 0 .../{290_webhooks.py => 060_webhooks.py} | 0 ..._tenant_groups.py => 070_tenant_groups.py} | 0 .../{030_tenants.py => 080_tenants.py} | 0 .../{030_regions.py => 090_regions.py} | 0 .../{040_sites.py => 110_sites.py} | 0 .../{075_locations.py => 120_locations.py} | 0 .../{070_rack_roles.py => 130_rack_roles.py} | 0 startup_scripts/140_clusters.py | 42 ------------------- .../{080_racks.py => 140_racks.py} | 0 ...30_power_panels.py => 150_power_panels.py} | 0 ...{340_power_feeds.py => 160_power_feeds.py} | 0 startup_scripts/165_cluster_groups.py | 15 ------- ..._manufacturers.py => 170_manufacturers.py} | 0 ...90_device_roles.py => 180_device_roles.py} | 0 ...60_device_types.py => 190_device_types.py} | 0 .../{140_devices.py => 200_devices.py} | 0 ...m_interfaces.py => 210_dcim_interfaces.py} | 0 .../{100_platforms.py => 220_platforms.py} | 0 ..._route_targets.py => 230_route_targets.py} | 0 startup_scripts/{180_vrfs.py => 240_vrfs.py} | 0 startup_scripts/{150_rirs.py => 250_rirs.py} | 0 startup_scripts/{155_asns.py => 260_asns.py} | 0 .../{160_aggregates.py => 270_aggregates.py} | 0 ...vlan_roles.py => 280_prefix_vlan_roles.py} | 0 ..._cluster_types.py => 290_cluster_types.py} | 0 ...luster_groups.py => 300_cluster_groups.py} | 0 .../{135_clusters.py => 310_clusters.py} | 0 ...{200_vlan_groups.py => 320_vlan_groups.py} | 0 .../{210_vlans.py => 330_vlans.py} | 0 ...al_machines.py => 340_virtual_machines.py} | 0 ...es.py => 350_virtualization_interfaces.py} | 0 .../{220_prefixes.py => 360_prefixes.py} | 0 ...60_ip_addresses.py => 370_ip_addresses.py} | 1 + ...{270_primary_ips.py => 380_primary_ips.py} | 0 .../{320_services.py => 400_services.py} | 0 .../{280_providers.py => 420_providers.py} | 0 ..._circuit_types.py => 440_circuit_types.py} | 0 .../{300_circuits.py => 450_circuits.py} | 0 42 files changed, 1 insertion(+), 57 deletions(-) rename startup_scripts/{015_object_permissions.py => 020_object_permissions.py} (100%) rename startup_scripts/{020_custom_fields.py => 030_custom_fields.py} (100%) rename startup_scripts/{280_custom_links.py => 040_custom_links.py} (100%) rename startup_scripts/{020_tags.py => 050_tags.py} (100%) rename startup_scripts/{290_webhooks.py => 060_webhooks.py} (100%) rename startup_scripts/{020_tenant_groups.py => 070_tenant_groups.py} (100%) rename startup_scripts/{030_tenants.py => 080_tenants.py} (100%) rename startup_scripts/{030_regions.py => 090_regions.py} (100%) rename startup_scripts/{040_sites.py => 110_sites.py} (100%) rename startup_scripts/{075_locations.py => 120_locations.py} (100%) rename startup_scripts/{070_rack_roles.py => 130_rack_roles.py} (100%) delete mode 100644 startup_scripts/140_clusters.py rename startup_scripts/{080_racks.py => 140_racks.py} (100%) rename startup_scripts/{330_power_panels.py => 150_power_panels.py} (100%) rename startup_scripts/{340_power_feeds.py => 160_power_feeds.py} (100%) delete mode 100644 startup_scripts/165_cluster_groups.py rename startup_scripts/{050_manufacturers.py => 170_manufacturers.py} (100%) rename startup_scripts/{090_device_roles.py => 180_device_roles.py} (100%) rename startup_scripts/{060_device_types.py => 190_device_types.py} (100%) rename startup_scripts/{140_devices.py => 200_devices.py} (100%) rename startup_scripts/{250_dcim_interfaces.py => 210_dcim_interfaces.py} (100%) rename startup_scripts/{100_platforms.py => 220_platforms.py} (100%) rename startup_scripts/{175_route_targets.py => 230_route_targets.py} (100%) rename startup_scripts/{180_vrfs.py => 240_vrfs.py} (100%) rename startup_scripts/{150_rirs.py => 250_rirs.py} (100%) rename startup_scripts/{155_asns.py => 260_asns.py} (100%) rename startup_scripts/{160_aggregates.py => 270_aggregates.py} (100%) rename startup_scripts/{190_prefix_vlan_roles.py => 280_prefix_vlan_roles.py} (100%) rename startup_scripts/{130_cluster_types.py => 290_cluster_types.py} (100%) rename startup_scripts/{135_cluster_groups.py => 300_cluster_groups.py} (100%) rename startup_scripts/{135_clusters.py => 310_clusters.py} (100%) rename startup_scripts/{200_vlan_groups.py => 320_vlan_groups.py} (100%) rename startup_scripts/{210_vlans.py => 330_vlans.py} (100%) rename startup_scripts/{230_virtual_machines.py => 340_virtual_machines.py} (100%) rename startup_scripts/{240_virtualization_interfaces.py => 350_virtualization_interfaces.py} (100%) rename startup_scripts/{220_prefixes.py => 360_prefixes.py} (100%) rename startup_scripts/{260_ip_addresses.py => 370_ip_addresses.py} (99%) rename startup_scripts/{270_primary_ips.py => 380_primary_ips.py} (100%) rename startup_scripts/{320_services.py => 400_services.py} (100%) rename startup_scripts/{280_providers.py => 420_providers.py} (100%) rename startup_scripts/{290_circuit_types.py => 440_circuit_types.py} (100%) rename startup_scripts/{300_circuits.py => 450_circuits.py} (100%) diff --git a/startup_scripts/015_object_permissions.py b/startup_scripts/020_object_permissions.py similarity index 100% rename from startup_scripts/015_object_permissions.py rename to startup_scripts/020_object_permissions.py diff --git a/startup_scripts/020_custom_fields.py b/startup_scripts/030_custom_fields.py similarity index 100% rename from startup_scripts/020_custom_fields.py rename to startup_scripts/030_custom_fields.py diff --git a/startup_scripts/280_custom_links.py b/startup_scripts/040_custom_links.py similarity index 100% rename from startup_scripts/280_custom_links.py rename to startup_scripts/040_custom_links.py diff --git a/startup_scripts/020_tags.py b/startup_scripts/050_tags.py similarity index 100% rename from startup_scripts/020_tags.py rename to startup_scripts/050_tags.py diff --git a/startup_scripts/290_webhooks.py b/startup_scripts/060_webhooks.py similarity index 100% rename from startup_scripts/290_webhooks.py rename to startup_scripts/060_webhooks.py diff --git a/startup_scripts/020_tenant_groups.py b/startup_scripts/070_tenant_groups.py similarity index 100% rename from startup_scripts/020_tenant_groups.py rename to startup_scripts/070_tenant_groups.py diff --git a/startup_scripts/030_tenants.py b/startup_scripts/080_tenants.py similarity index 100% rename from startup_scripts/030_tenants.py rename to startup_scripts/080_tenants.py diff --git a/startup_scripts/030_regions.py b/startup_scripts/090_regions.py similarity index 100% rename from startup_scripts/030_regions.py rename to startup_scripts/090_regions.py diff --git a/startup_scripts/040_sites.py b/startup_scripts/110_sites.py similarity index 100% rename from startup_scripts/040_sites.py rename to startup_scripts/110_sites.py diff --git a/startup_scripts/075_locations.py b/startup_scripts/120_locations.py similarity index 100% rename from startup_scripts/075_locations.py rename to startup_scripts/120_locations.py diff --git a/startup_scripts/070_rack_roles.py b/startup_scripts/130_rack_roles.py similarity index 100% rename from startup_scripts/070_rack_roles.py rename to startup_scripts/130_rack_roles.py diff --git a/startup_scripts/140_clusters.py b/startup_scripts/140_clusters.py deleted file mode 100644 index 2748f20..0000000 --- a/startup_scripts/140_clusters.py +++ /dev/null @@ -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) diff --git a/startup_scripts/080_racks.py b/startup_scripts/140_racks.py similarity index 100% rename from startup_scripts/080_racks.py rename to startup_scripts/140_racks.py diff --git a/startup_scripts/330_power_panels.py b/startup_scripts/150_power_panels.py similarity index 100% rename from startup_scripts/330_power_panels.py rename to startup_scripts/150_power_panels.py diff --git a/startup_scripts/340_power_feeds.py b/startup_scripts/160_power_feeds.py similarity index 100% rename from startup_scripts/340_power_feeds.py rename to startup_scripts/160_power_feeds.py diff --git a/startup_scripts/165_cluster_groups.py b/startup_scripts/165_cluster_groups.py deleted file mode 100644 index fedd292..0000000 --- a/startup_scripts/165_cluster_groups.py +++ /dev/null @@ -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) diff --git a/startup_scripts/050_manufacturers.py b/startup_scripts/170_manufacturers.py similarity index 100% rename from startup_scripts/050_manufacturers.py rename to startup_scripts/170_manufacturers.py diff --git a/startup_scripts/090_device_roles.py b/startup_scripts/180_device_roles.py similarity index 100% rename from startup_scripts/090_device_roles.py rename to startup_scripts/180_device_roles.py diff --git a/startup_scripts/060_device_types.py b/startup_scripts/190_device_types.py similarity index 100% rename from startup_scripts/060_device_types.py rename to startup_scripts/190_device_types.py diff --git a/startup_scripts/140_devices.py b/startup_scripts/200_devices.py similarity index 100% rename from startup_scripts/140_devices.py rename to startup_scripts/200_devices.py diff --git a/startup_scripts/250_dcim_interfaces.py b/startup_scripts/210_dcim_interfaces.py similarity index 100% rename from startup_scripts/250_dcim_interfaces.py rename to startup_scripts/210_dcim_interfaces.py diff --git a/startup_scripts/100_platforms.py b/startup_scripts/220_platforms.py similarity index 100% rename from startup_scripts/100_platforms.py rename to startup_scripts/220_platforms.py diff --git a/startup_scripts/175_route_targets.py b/startup_scripts/230_route_targets.py similarity index 100% rename from startup_scripts/175_route_targets.py rename to startup_scripts/230_route_targets.py diff --git a/startup_scripts/180_vrfs.py b/startup_scripts/240_vrfs.py similarity index 100% rename from startup_scripts/180_vrfs.py rename to startup_scripts/240_vrfs.py diff --git a/startup_scripts/150_rirs.py b/startup_scripts/250_rirs.py similarity index 100% rename from startup_scripts/150_rirs.py rename to startup_scripts/250_rirs.py diff --git a/startup_scripts/155_asns.py b/startup_scripts/260_asns.py similarity index 100% rename from startup_scripts/155_asns.py rename to startup_scripts/260_asns.py diff --git a/startup_scripts/160_aggregates.py b/startup_scripts/270_aggregates.py similarity index 100% rename from startup_scripts/160_aggregates.py rename to startup_scripts/270_aggregates.py diff --git a/startup_scripts/190_prefix_vlan_roles.py b/startup_scripts/280_prefix_vlan_roles.py similarity index 100% rename from startup_scripts/190_prefix_vlan_roles.py rename to startup_scripts/280_prefix_vlan_roles.py diff --git a/startup_scripts/130_cluster_types.py b/startup_scripts/290_cluster_types.py similarity index 100% rename from startup_scripts/130_cluster_types.py rename to startup_scripts/290_cluster_types.py diff --git a/startup_scripts/135_cluster_groups.py b/startup_scripts/300_cluster_groups.py similarity index 100% rename from startup_scripts/135_cluster_groups.py rename to startup_scripts/300_cluster_groups.py diff --git a/startup_scripts/135_clusters.py b/startup_scripts/310_clusters.py similarity index 100% rename from startup_scripts/135_clusters.py rename to startup_scripts/310_clusters.py diff --git a/startup_scripts/200_vlan_groups.py b/startup_scripts/320_vlan_groups.py similarity index 100% rename from startup_scripts/200_vlan_groups.py rename to startup_scripts/320_vlan_groups.py diff --git a/startup_scripts/210_vlans.py b/startup_scripts/330_vlans.py similarity index 100% rename from startup_scripts/210_vlans.py rename to startup_scripts/330_vlans.py diff --git a/startup_scripts/230_virtual_machines.py b/startup_scripts/340_virtual_machines.py similarity index 100% rename from startup_scripts/230_virtual_machines.py rename to startup_scripts/340_virtual_machines.py diff --git a/startup_scripts/240_virtualization_interfaces.py b/startup_scripts/350_virtualization_interfaces.py similarity index 100% rename from startup_scripts/240_virtualization_interfaces.py rename to startup_scripts/350_virtualization_interfaces.py diff --git a/startup_scripts/220_prefixes.py b/startup_scripts/360_prefixes.py similarity index 100% rename from startup_scripts/220_prefixes.py rename to startup_scripts/360_prefixes.py diff --git a/startup_scripts/260_ip_addresses.py b/startup_scripts/370_ip_addresses.py similarity index 99% rename from startup_scripts/260_ip_addresses.py rename to startup_scripts/370_ip_addresses.py index 3f0aed0..7f166f0 100644 --- a/startup_scripts/260_ip_addresses.py +++ b/startup_scripts/370_ip_addresses.py @@ -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) diff --git a/startup_scripts/270_primary_ips.py b/startup_scripts/380_primary_ips.py similarity index 100% rename from startup_scripts/270_primary_ips.py rename to startup_scripts/380_primary_ips.py diff --git a/startup_scripts/320_services.py b/startup_scripts/400_services.py similarity index 100% rename from startup_scripts/320_services.py rename to startup_scripts/400_services.py diff --git a/startup_scripts/280_providers.py b/startup_scripts/420_providers.py similarity index 100% rename from startup_scripts/280_providers.py rename to startup_scripts/420_providers.py diff --git a/startup_scripts/290_circuit_types.py b/startup_scripts/440_circuit_types.py similarity index 100% rename from startup_scripts/290_circuit_types.py rename to startup_scripts/440_circuit_types.py diff --git a/startup_scripts/300_circuits.py b/startup_scripts/450_circuits.py similarity index 100% rename from startup_scripts/300_circuits.py rename to startup_scripts/450_circuits.py