Merge pull request #485 from tobiasge/prepare-2.11
Initializer updates for Netbox 2.11
This commit is contained in:
commit
c7df608696
|
@ -14,6 +14,9 @@ jobs:
|
|||
name: Checks syntax of our code
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
# Full git history is needed to get a proper list of changed files within `super-linter`
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-python@v2
|
||||
- name: Lint Code Base
|
||||
uses: github/super-linter@v3
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
## Examples:
|
||||
|
||||
# - name: link_to_repo
|
||||
# text: 'Link to Netbox Docker'
|
||||
# url: 'https://github.com/netbox-community/netbox-docker'
|
||||
# link_text: 'Link to Netbox Docker'
|
||||
# link_url: 'https://github.com/netbox-community/netbox-docker'
|
||||
# new_window: False
|
||||
# content_type: device
|
||||
# - name: link_to_localhost
|
||||
# text: 'Link to localhost'
|
||||
# url: 'http://localhost'
|
||||
# link_text: 'Link to localhost'
|
||||
# link_url: 'http://localhost'
|
||||
# new_window: True
|
||||
# content_type: device
|
||||
|
|
|
@ -42,3 +42,12 @@
|
|||
# position: 3
|
||||
# custom_field_data:
|
||||
# text_field: Description
|
||||
# - name: server04
|
||||
# device_role: server
|
||||
# device_type: Other
|
||||
# site: SING 1
|
||||
# location: cage 101
|
||||
# face: front
|
||||
# position: 3
|
||||
# custom_field_data:
|
||||
# text_field: Description
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# site: AMS 1
|
||||
# - name: power panel SING 1
|
||||
# site: SING 1
|
||||
# rack_group: cage 101
|
||||
# location: cage 101
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
# text_field: Description
|
||||
# - site: SING 1
|
||||
# name: rack-03
|
||||
# group: cage 101
|
||||
# location: cage 101
|
||||
# role: Role 3
|
||||
# type: 4-post-cabinet
|
||||
# width: 19
|
||||
|
|
|
@ -1,6 +1,24 @@
|
|||
# - name: VLAN group 1
|
||||
# site: AMS 1
|
||||
# scope_type: dcim.region
|
||||
# scope: Amsterdam
|
||||
# slug: vlan-group-1
|
||||
# - name: VLAN group 2
|
||||
# site: AMS 1
|
||||
# scope_type: dcim.site
|
||||
# scope: AMS 1
|
||||
# slug: vlan-group-2
|
||||
# - name: VLAN group 3
|
||||
# scope_type: dcim.location
|
||||
# scope: cage 101
|
||||
# slug: vlan-group-3
|
||||
# - name: VLAN group 4
|
||||
# scope_type: dcim.rack
|
||||
# scope: rack-01
|
||||
# slug: vlan-group-4
|
||||
# - name: VLAN group 5
|
||||
# scope_type: virtualization.cluster
|
||||
# scope: cluster1
|
||||
# slug: vlan-group-5
|
||||
# - name: VLAN group 6
|
||||
# scope_type: virtualization.clustergroup
|
||||
# scope: Group 1
|
||||
# slug: vlan-group-6
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import RackGroup, Site
|
||||
from dcim.models import Location, Site
|
||||
from startup_script_utils import load_yaml
|
||||
|
||||
rack_groups = load_yaml("/opt/netbox/initializers/rack_groups.yml")
|
||||
rack_groups = load_yaml("/opt/netbox/initializers/locations.yml")
|
||||
|
||||
if rack_groups is None:
|
||||
sys.exit()
|
||||
|
@ -17,7 +17,7 @@ for params in rack_groups:
|
|||
query = {field: params.pop(assoc)}
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
rack_group, created = RackGroup.objects.get_or_create(**params)
|
||||
location, created = Location.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("🎨 Created rack group", rack_group.name)
|
||||
print("🎨 Created location", location.name)
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import Rack, RackGroup, RackRole, Site
|
||||
from dcim.models import Location, Rack, RackRole, Site
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
from tenancy.models import Tenant
|
||||
|
||||
|
@ -14,7 +14,7 @@ required_assocs = {"site": (Site, "name")}
|
|||
optional_assocs = {
|
||||
"role": (RackRole, "name"),
|
||||
"tenant": (Tenant, "name"),
|
||||
"group": (RackGroup, "name"),
|
||||
"location": (Location, "name"),
|
||||
}
|
||||
|
||||
for params in racks:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, Site
|
||||
from dcim.models import Device, DeviceRole, DeviceType, Location, Platform, Rack, 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
|
||||
|
@ -21,6 +21,7 @@ optional_assocs = {
|
|||
"platform": (Platform, "name"),
|
||||
"rack": (Rack, "name"),
|
||||
"cluster": (Cluster, "name"),
|
||||
"location": (Location, "name"),
|
||||
}
|
||||
|
||||
for params in devices:
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, 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
|
||||
|
||||
devices = load_yaml("/opt/netbox/initializers/devices.yml")
|
||||
|
||||
if devices is None:
|
||||
sys.exit()
|
||||
|
||||
required_assocs = {
|
||||
"device_role": (DeviceRole, "name"),
|
||||
"device_type": (DeviceType, "model"),
|
||||
"site": (Site, "name"),
|
||||
}
|
||||
|
||||
optional_assocs = {
|
||||
"tenant": (Tenant, "name"),
|
||||
"platform": (Platform, "name"),
|
||||
"rack": (Rack, "name"),
|
||||
"cluster": (Cluster, "name"),
|
||||
}
|
||||
|
||||
for params in devices:
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
||||
# primary ips are handled later in `270_primary_ips.py`
|
||||
params.pop("primary_ip4", None)
|
||||
params.pop("primary_ip6", None)
|
||||
|
||||
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)
|
||||
|
||||
device, created = Device.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
set_custom_fields_values(device, custom_field_data)
|
||||
|
||||
print("🖥️ Created device", device.name)
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import Site
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from ipam.models import VLANGroup
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
|
||||
|
@ -9,7 +9,7 @@ vlan_groups = load_yaml("/opt/netbox/initializers/vlan_groups.yml")
|
|||
if vlan_groups is None:
|
||||
sys.exit()
|
||||
|
||||
optional_assocs = {"site": (Site, "name")}
|
||||
optional_assocs = {"scope": (None, "name")}
|
||||
|
||||
for params in vlan_groups:
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
@ -18,9 +18,20 @@ for params in vlan_groups:
|
|||
if assoc in params:
|
||||
model, field = details
|
||||
query = {field: params.pop(assoc)}
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
# Get model from Contenttype
|
||||
scope_type = params.pop("scope_type", None)
|
||||
if not scope_type:
|
||||
print(f"VLAN Group '{params['name']}': scope_type is missing from VLAN Group")
|
||||
continue
|
||||
app_label, model = str(scope_type).split(".")
|
||||
ct = ContentType.objects.filter(app_label=app_label, model=model).first()
|
||||
if not ct:
|
||||
print(
|
||||
f"VLAN Group '{params['name']}': ContentType for "
|
||||
+ f"app_label = '{app_label}' and model = '{model}' not found"
|
||||
)
|
||||
continue
|
||||
params["scope_id"] = ct.model_class().objects.get(**query).id
|
||||
vlan_group, created = VLANGroup.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import PowerPanel, RackGroup, Site
|
||||
from dcim.models import Location, PowerPanel, Site
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
|
||||
power_panels = load_yaml("/opt/netbox/initializers/power_panels.yml")
|
||||
|
@ -10,7 +10,7 @@ if power_panels is None:
|
|||
|
||||
required_assocs = {"site": (Site, "name")}
|
||||
|
||||
optional_assocs = {"rack_group": (RackGroup, "name")}
|
||||
optional_assocs = {"location": (Location, "name")}
|
||||
|
||||
for params in power_panels:
|
||||
custom_field_data = pop_custom_fields(params)
|
||||
|
|
Loading…
Reference in New Issue