Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Initialization Support #384

Merged
merged 18 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions initializers/aggregates.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# - prefix: 10.0.0.0/16
# rir: RFC1918
# tenant: tenant1
# - prefix: fd00:ccdd::/32
# rir: RFC4193 ULA
# - prefix: 2001:db8::/32
Expand Down
6 changes: 6 additions & 0 deletions initializers/circuit_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# - name: VPLS
# slug: vpls
# - name: MPLS
# slug: mpls
# - name: Internet
# slug: internet
7 changes: 7 additions & 0 deletions initializers/circuits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# - cid: Circuit_ID-1
# provider: Provider1
# type: Internet
# tenant: tenant1
# - cid: Circuit_ID-2
# provider: Provider2
# type: MPLS
4 changes: 4 additions & 0 deletions initializers/cluster_groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# - name: Group 1
# slug: group-1
# - name: Group 2
# slug: group-2
2 changes: 2 additions & 0 deletions initializers/clusters.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# - name: cluster1
# type: Hyper-V
# group: Group 1
# tenant: tenant1
# - name: cluster2
# type: Hyper-V
# site: SING 1
14 changes: 14 additions & 0 deletions initializers/power_feeds.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions initializers/power_panels.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions initializers/providers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# - name: Provider1
# slug: provider1
# asn: 121
# - name: Provider2
# slug: provider2
# asn: 122
3 changes: 3 additions & 0 deletions initializers/route_targets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# - name: 65000:1001
# tenant: tenant1
# - name: 65000:1002
4 changes: 4 additions & 0 deletions initializers/secret_roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# - name: Super Secret Passwords
# slug: super-secret
# - name: SNMP Communities
# slug: snmp
15 changes: 15 additions & 0 deletions initializers/services.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions initializers/tags.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions startup_scripts/020_tags.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions startup_scripts/160_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ipam.models import Aggregate, RIR
from netaddr import IPNetwork
from startup_script_utils import *
from tenancy.models import Tenant

aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')

Expand All @@ -13,6 +14,10 @@
'rir': (RIR, 'name')
}

optional_assocs = {
'tenant': (Tenant, 'name'),
}

for params in aggregates:
custom_field_data = pop_custom_fields(params)

Expand All @@ -24,6 +29,13 @@

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)

if created:
Expand Down
14 changes: 14 additions & 0 deletions startup_scripts/165_cluster_groups.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion startup_scripts/170_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dcim.models import Site
from startup_script_utils import *
from virtualization.models import Cluster, ClusterType, ClusterGroup
from tenancy.models import Tenant

clusters = load_yaml('/opt/netbox/initializers/clusters.yml')

Expand All @@ -15,7 +16,8 @@

optional_assocs = {
'site': (Site, 'name'),
'group': (ClusterGroup, 'name')
'group': (ClusterGroup, 'name'),
'tenant': (Tenant, 'name')
}

for params in clusters:
Expand Down
31 changes: 31 additions & 0 deletions startup_scripts/175_route_targets.py
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions startup_scripts/280_providers.py
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions startup_scripts/290_circuit_types.py
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions startup_scripts/300_circuits.py
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions startup_scripts/310_secret_roles.py
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions startup_scripts/320_services.py
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions startup_scripts/330_power_panels.py
Original file line number Diff line number Diff line change
@@ -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)
Loading