Added power startup_scripts

This commit is contained in:
ryanmerolle 2020-12-30 19:10:30 -05:00
parent e3946af27c
commit dfb0327340
4 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,16 @@
# - name: power feed 1
# #site: AMS 1
# power_panel: power panel AMS 1
# voltage: 208
# amperage: 50
# max_utilization: 80
# phase: Single phase
# rack: rack-01
# - name: power feed 2
# #site: SING 1
# power_panel: power panel SING 1
# voltage: 208
# amperage: 50
# max_utilization: 80
# phase: Three-phase
# rack: rack-03

View 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

View 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)

View 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)