Merge pull request #384 from ryanmerolle/develop
Expand Initialization Support
This commit is contained in:
commit
65023a7dd4
@ -1,5 +1,6 @@
|
|||||||
# - prefix: 10.0.0.0/16
|
# - prefix: 10.0.0.0/16
|
||||||
# rir: RFC1918
|
# rir: RFC1918
|
||||||
|
# tenant: tenant1
|
||||||
# - prefix: fd00:ccdd::/32
|
# - prefix: fd00:ccdd::/32
|
||||||
# rir: RFC4193 ULA
|
# rir: RFC4193 ULA
|
||||||
# - prefix: 2001:db8::/32
|
# - prefix: 2001:db8::/32
|
||||||
|
6
initializers/circuit_types.yml
Normal file
6
initializers/circuit_types.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# - name: VPLS
|
||||||
|
# slug: vpls
|
||||||
|
# - name: MPLS
|
||||||
|
# slug: mpls
|
||||||
|
# - name: Internet
|
||||||
|
# slug: internet
|
7
initializers/circuits.yml
Normal file
7
initializers/circuits.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# - cid: Circuit_ID-1
|
||||||
|
# provider: Provider1
|
||||||
|
# type: Internet
|
||||||
|
# tenant: tenant1
|
||||||
|
# - cid: Circuit_ID-2
|
||||||
|
# provider: Provider2
|
||||||
|
# type: MPLS
|
4
initializers/cluster_groups.yml
Normal file
4
initializers/cluster_groups.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# - name: Group 1
|
||||||
|
# slug: group-1
|
||||||
|
# - name: Group 2
|
||||||
|
# slug: group-2
|
@ -1,5 +1,7 @@
|
|||||||
# - name: cluster1
|
# - name: cluster1
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
|
# group: Group 1
|
||||||
|
# tenant: tenant1
|
||||||
# - name: cluster2
|
# - name: cluster2
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
# site: SING 1
|
# site: SING 1
|
||||||
|
14
initializers/power_feeds.yml
Normal file
14
initializers/power_feeds.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# - name: power feed 1
|
||||||
|
# power_panel: power panel AMS 1
|
||||||
|
# voltage: 208
|
||||||
|
# amperage: 50
|
||||||
|
# max_utilization: 80
|
||||||
|
# phase: Single phase
|
||||||
|
# rack: rack-01
|
||||||
|
# - name: power feed 2
|
||||||
|
# power_panel: power panel SING 1
|
||||||
|
# voltage: 208
|
||||||
|
# amperage: 50
|
||||||
|
# max_utilization: 80
|
||||||
|
# phase: Three-phase
|
||||||
|
# rack: rack-03
|
5
initializers/power_panels.yml
Normal file
5
initializers/power_panels.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# - name: power panel AMS 1
|
||||||
|
# site: AMS 1
|
||||||
|
# - name: power panel SING 1
|
||||||
|
# site: SING 1
|
||||||
|
# rack_group: cage 101
|
6
initializers/providers.yml
Normal file
6
initializers/providers.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# - name: Provider1
|
||||||
|
# slug: provider1
|
||||||
|
# asn: 121
|
||||||
|
# - name: Provider2
|
||||||
|
# slug: provider2
|
||||||
|
# asn: 122
|
3
initializers/route_targets.yml
Normal file
3
initializers/route_targets.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# - name: 65000:1001
|
||||||
|
# tenant: tenant1
|
||||||
|
# - name: 65000:1002
|
4
initializers/secret_roles.yml
Normal file
4
initializers/secret_roles.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# - name: Super Secret Passwords
|
||||||
|
# slug: super-secret
|
||||||
|
# - name: SNMP Communities
|
||||||
|
# slug: snmp
|
15
initializers/services.yml
Normal file
15
initializers/services.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# - name: DNS
|
||||||
|
# protocol: TCP
|
||||||
|
# ports:
|
||||||
|
# - 53
|
||||||
|
# virtual_machine: virtual machine 1
|
||||||
|
# - name: DNS
|
||||||
|
# protocol: UDP
|
||||||
|
# ports:
|
||||||
|
# - 53
|
||||||
|
# virtual_machine: virtual machine 1
|
||||||
|
# - name: MISC
|
||||||
|
# protocol: UDP
|
||||||
|
# ports:
|
||||||
|
# - 4000
|
||||||
|
# device: server01
|
12
initializers/tags.yml
Normal file
12
initializers/tags.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# - name: Tag 1
|
||||||
|
# slug: tag-1
|
||||||
|
# color: Pink
|
||||||
|
# - name: Tag 2
|
||||||
|
# slug: tag-2
|
||||||
|
# color: Cyan
|
||||||
|
# - name: Tag 3
|
||||||
|
# slug: tag-3
|
||||||
|
# color: Grey
|
||||||
|
# - name: Tag 4
|
||||||
|
# slug: tag-4
|
||||||
|
# color: Teal
|
23
startup_scripts/020_tags.py
Normal file
23
startup_scripts/020_tags.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from extras.models import Tag
|
||||||
|
from utilities.choices import ColorChoices
|
||||||
|
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
tags = load_yaml('/opt/netbox/initializers/tags.yml')
|
||||||
|
|
||||||
|
if tags is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in tags:
|
||||||
|
if 'color' in params:
|
||||||
|
color = params.pop('color')
|
||||||
|
|
||||||
|
for color_tpl in ColorChoices:
|
||||||
|
if color in color_tpl:
|
||||||
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
|
tag, created = Tag.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🎨 Created Tag", tag.name)
|
@ -3,6 +3,7 @@ import sys
|
|||||||
from ipam.models import Aggregate, RIR
|
from ipam.models import Aggregate, RIR
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
from startup_script_utils import *
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
||||||
|
|
||||||
@ -13,6 +14,10 @@ required_assocs = {
|
|||||||
'rir': (RIR, 'name')
|
'rir': (RIR, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name'),
|
||||||
|
}
|
||||||
|
|
||||||
for params in aggregates:
|
for params in aggregates:
|
||||||
custom_field_data = pop_custom_fields(params)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
@ -24,6 +29,13 @@ for params in aggregates:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
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)
|
||||||
|
|
||||||
aggregate, created = Aggregate.objects.get_or_create(**params)
|
aggregate, created = Aggregate.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
14
startup_scripts/165_cluster_groups.py
Normal file
14
startup_scripts/165_cluster_groups.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from virtualization.models import ClusterGroup
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
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)
|
@ -3,6 +3,7 @@ import sys
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from startup_script_utils import *
|
from startup_script_utils import *
|
||||||
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
||||||
|
|
||||||
@ -15,7 +16,8 @@ required_assocs = {
|
|||||||
|
|
||||||
optional_assocs = {
|
optional_assocs = {
|
||||||
'site': (Site, 'name'),
|
'site': (Site, 'name'),
|
||||||
'group': (ClusterGroup, 'name')
|
'group': (ClusterGroup, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
for params in clusters:
|
for params in clusters:
|
||||||
|
31
startup_scripts/175_route_targets.py
Normal file
31
startup_scripts/175_route_targets.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from ipam.models import RouteTarget
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
route_targets = load_yaml('/opt/netbox/initializers/route_targets.yml')
|
||||||
|
|
||||||
|
if route_targets is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in route_targets:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
route_target, created = RouteTarget.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(route_target, custom_field_data)
|
||||||
|
|
||||||
|
print("🎯 Created Route Target", route_target.name)
|
18
startup_scripts/280_providers.py
Normal file
18
startup_scripts/280_providers.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from circuits.models import Provider
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
providers = load_yaml('/opt/netbox/initializers/providers.yml')
|
||||||
|
|
||||||
|
if providers is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in providers:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
provider, created = Provider.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(provider, custom_field_data)
|
||||||
|
|
||||||
|
print("📡 Created provider", provider.name)
|
18
startup_scripts/290_circuit_types.py
Normal file
18
startup_scripts/290_circuit_types.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from circuits.models import CircuitType
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
circuit_types = load_yaml('/opt/netbox/initializers/circuit_types.yml')
|
||||||
|
|
||||||
|
if circuit_types is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in circuit_types:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
circuit_type, created = CircuitType.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(circuit_type, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Circuit Type", circuit_type.name)
|
41
startup_scripts/300_circuits.py
Normal file
41
startup_scripts/300_circuits.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from circuits.models import Circuit, Provider, CircuitType
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
circuits = load_yaml('/opt/netbox/initializers/circuits.yml')
|
||||||
|
|
||||||
|
if circuits is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'provider': (Provider, 'name'),
|
||||||
|
'type': (CircuitType, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in circuits:
|
||||||
|
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)
|
||||||
|
|
||||||
|
circuit, created = Circuit.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(circuit, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Circuit", circuit.cid)
|
14
startup_scripts/310_secret_roles.py
Normal file
14
startup_scripts/310_secret_roles.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from secrets.models import SecretRole
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
secret_roles = load_yaml('/opt/netbox/initializers/secret_roles.yml')
|
||||||
|
|
||||||
|
if secret_roles is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in secret_roles:
|
||||||
|
secret_role, created = SecretRole.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🔑 Created Secret Role", secret_role.name)
|
29
startup_scripts/320_services.py
Normal file
29
startup_scripts/320_services.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from ipam.models import Service
|
||||||
|
from dcim.models import Device
|
||||||
|
from virtualization.models import VirtualMachine
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
services = load_yaml('/opt/netbox/initializers/services.yml')
|
||||||
|
|
||||||
|
if services is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'device': (Device, 'name'),
|
||||||
|
'virtual_machine': (VirtualMachine, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in services:
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
service, created = Service.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🧰 Created Service", service.name)
|
41
startup_scripts/330_power_panels.py
Normal file
41
startup_scripts/330_power_panels.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site, RackGroup, PowerPanel
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
power_panels = load_yaml('/opt/netbox/initializers/power_panels.yml')
|
||||||
|
|
||||||
|
if power_panels is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'site': (Site, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'rack_group': (RackGroup, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in power_panels:
|
||||||
|
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)
|
||||||
|
|
||||||
|
power_panel, created = PowerPanel.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(power_panel, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Power Panel", power_panel.site, power_panel.name)
|
41
startup_scripts/340_power_feeds.py
Normal file
41
startup_scripts/340_power_feeds.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Rack, PowerPanel, PowerFeed
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
power_feeds = load_yaml('/opt/netbox/initializers/power_feeds.yml')
|
||||||
|
|
||||||
|
if power_feeds is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'power_panel': (PowerPanel, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'rack': (Rack, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in power_feeds:
|
||||||
|
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)
|
||||||
|
|
||||||
|
power_feed, created = PowerFeed.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(power_feed, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Power Feed", power_feed.name)
|
Loading…
Reference in New Issue
Block a user