-
-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from ninech/add-more-seeds
Add seed/initialization scripts for additional resources
- Loading branch information
Showing
23 changed files
with
495 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# - name: switch | ||
# slug: switch | ||
# color: Grey | ||
# - name: router | ||
# slug: router | ||
# color: Cyan | ||
# - name: load-balancer | ||
# slug: load-balancer | ||
# color: Red | ||
# - name: server | ||
# slug: server | ||
# color: Blue | ||
# - name: patchpanel | ||
# slug: patchpanel | ||
# color: Black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# - model: Model 1 | ||
# manufacturer: Manufacturer 1 | ||
# slug: model-1 | ||
# u_height: 2 | ||
# custom_fields: | ||
# text_field: Description | ||
# - model: Model 2 | ||
# manufacturer: Manufacturer 1 | ||
# slug: model-2 | ||
# custom_fields: | ||
# text_field: Description | ||
# - model: Model 3 | ||
# manufacturer: Manufacturer 1 | ||
# slug: model-3 | ||
# is_full_depth: false | ||
# u_height: 0 | ||
# custom_fields: | ||
# text_field: Description | ||
# - model: Other | ||
# manufacturer: NoName | ||
# slug: other | ||
# custom_fields: | ||
# text_field: Description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# - name: server01 | ||
# device_role: server | ||
# device_type: Other | ||
# site: AMS 1 | ||
# rack: rack-01 | ||
# face: Front | ||
# position: 1 | ||
# custom_fields: | ||
# text_field: Description | ||
# - name: server02 | ||
# device_role: server | ||
# device_type: Other | ||
# site: AMS 2 | ||
# rack: rack-02 | ||
# face: Front | ||
# position: 2 | ||
# custom_fields: | ||
# text_field: Description | ||
# - name: server03 | ||
# device_role: server | ||
# device_type: Other | ||
# site: SING 1 | ||
# rack: rack-03 | ||
# face: Front | ||
# position: 3 | ||
# custom_fields: | ||
# text_field: Description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# - name: Manufacturer 1 | ||
# slug: manufacturer-1 | ||
# - name: Manufacturer 2 | ||
# slug: manufacturer-2 | ||
# - name: NoName | ||
# slug: noname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# # Allowed rpc clients are: juniper-junos, cisco-ios, opengear | ||
# - name: Platform 1 | ||
# slug: platform-1 | ||
# manufacturer: Manufacturer 1 | ||
# napalm_driver: driver1 | ||
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}" | ||
# rpc_client: juniper-junos | ||
# - name: Platform 2 | ||
# slug: platform-2 | ||
# manufacturer: Manufacturer 2 | ||
# napalm_driver: driver2 | ||
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}" | ||
# rpc_client: opengear | ||
# - name: Platform 3 | ||
# slug: platform-3 | ||
# manufacturer: NoName | ||
# napalm_driver: driver3 | ||
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}" | ||
# rpc_client: juniper-junos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# - name: Role 1 | ||
# slug: role-1 | ||
# color: Pink | ||
# - name: Role 2 | ||
# slug: role-2 | ||
# color: Cyan | ||
# - name: Role 3 | ||
# slug: role-3 | ||
# color: Grey | ||
# - name: Role 4 | ||
# slug: role-4 | ||
# color: Teal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# - site: AMS 1 | ||
# name: rack-01 | ||
# role: Role 1 | ||
# type: 4-post cabinet | ||
# width: 19 inches | ||
# u_height: 47 | ||
# custom_fields: | ||
# text_field: Description | ||
# - site: AMS 2 | ||
# name: rack-02 | ||
# role: Role 2 | ||
# type: 4-post cabinet | ||
# width: 19 inches | ||
# u_height: 47 | ||
# custom_fields: | ||
# text_field: Description | ||
# - site: SING 1 | ||
# name: rack-03 | ||
# role: Role 3 | ||
# type: 4-post cabinet | ||
# width: 19 inches | ||
# u_height: 47 | ||
# custom_fields: | ||
# text_field: Description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# - name: Singapore | ||
# slug: singapore | ||
# - name: Amsterdam | ||
# slug: amsterdam | ||
# - name: Downtown | ||
# slug: downtown | ||
# parent: Amsterdam | ||
# - name: Suburbs | ||
# slug: suburbs | ||
# parent: Amsterdam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# - name: AMS 1 | ||
# slug: ams1 | ||
# region: Downtown | ||
# status: 1 | ||
# facility: Amsterdam 1 | ||
# asn: 12345 | ||
# custom_fields: | ||
# text_field: Description | ||
# - name: AMS 2 | ||
# slug: ams2 | ||
# region: Downtown | ||
# status: 1 | ||
# facility: Amsterdam 2 | ||
# asn: 54321 | ||
# custom_fields: | ||
# text_field: Description | ||
# - name: AMS 3 | ||
# slug: ams3 | ||
# region: Suburbs | ||
# status: 1 | ||
# facility: Amsterdam 3 | ||
# asn: 67890 | ||
# custom_fields: | ||
# text_field: Description | ||
# - name: SING 1 | ||
# slug: sing1 | ||
# region: Singapore | ||
# status: 1 | ||
# facility: Singapore 1 | ||
# asn: 09876 | ||
# custom_fields: | ||
# text_field: Description |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dcim.models import Region | ||
from ruamel.yaml import YAML | ||
|
||
with open('/opt/netbox/initializers/regions.yml', 'r') as stream: | ||
yaml=YAML(typ='safe') | ||
regions = yaml.load(stream) | ||
|
||
optional_assocs = { | ||
'parent': (Region, 'name') | ||
} | ||
|
||
if regions is not None: | ||
for params in regions: | ||
|
||
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) | ||
|
||
region, created = Region.objects.get_or_create(**params) | ||
|
||
if created: | ||
print("🌐 Created region", region.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from dcim.models import Region, Site | ||
from extras.models import CustomField, CustomFieldValue | ||
from tenancy.models import Tenant | ||
from ruamel.yaml import YAML | ||
|
||
with open('/opt/netbox/initializers/sites.yml', 'r') as stream: | ||
yaml = YAML(typ='safe') | ||
sites = yaml.load(stream) | ||
|
||
optional_assocs = { | ||
'region': (Region, 'name'), | ||
'tenant': (Tenant, 'name') | ||
} | ||
|
||
if sites is not None: | ||
for params in sites: | ||
custom_fields = params.pop('custom_fields', None) | ||
|
||
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) | ||
|
||
site, created = Site.objects.get_or_create(**params) | ||
|
||
if created: | ||
if custom_fields is not None: | ||
for cf_name, cf_value in custom_fields.items(): | ||
custom_field = CustomField.objects.get(name=cf_name) | ||
custom_field_value = CustomFieldValue.objects.create( | ||
field=custom_field, | ||
obj=site, | ||
value=cf_value | ||
) | ||
|
||
site.custom_field_values.add(custom_field_value) | ||
|
||
print("📍 Created site", site.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dcim.models import Manufacturer | ||
from ruamel.yaml import YAML | ||
|
||
with open('/opt/netbox/initializers/manufacturers.yml', 'r') as stream: | ||
yaml = YAML(typ='safe') | ||
manufacturers = yaml.load(stream) | ||
|
||
if manufacturers is not None: | ||
for params in manufacturers: | ||
manufacturer, created = Manufacturer.objects.get_or_create(**params) | ||
|
||
if created: | ||
print("🏭 Created Manufacturer", manufacturer.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from dcim.models import DeviceType, Manufacturer, Region | ||
from tenancy.models import Tenant | ||
from extras.models import CustomField, CustomFieldValue | ||
from ruamel.yaml import YAML | ||
|
||
with open('/opt/netbox/initializers/device_types.yml', 'r') as stream: | ||
yaml = YAML(typ='safe') | ||
device_types = yaml.load(stream) | ||
|
||
required_assocs = { | ||
'manufacturer': (Manufacturer, 'name') | ||
} | ||
|
||
optional_assocs = { | ||
'region': (Region, 'name'), | ||
'tenant': (Tenant, 'name') | ||
} | ||
|
||
if device_types is not None: | ||
for params in device_types: | ||
custom_fields = params.pop('custom_fields', 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_type, created = DeviceType.objects.get_or_create(**params) | ||
|
||
if created: | ||
if custom_fields is not None: | ||
for cf_name, cf_value in custom_fields.items(): | ||
custom_field = CustomField.objects.get(name=cf_name) | ||
custom_field_value = CustomFieldValue.objects.create( | ||
field=custom_field, | ||
obj=device_type, | ||
value=cf_value | ||
) | ||
|
||
device_type.custom_field_values.add(custom_field_value) | ||
|
||
print("🔡 Created device type", device_type.manufacturer, device_type.model) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dcim.models import RackRole | ||
from ruamel.yaml import YAML | ||
from utilities.forms import COLOR_CHOICES | ||
|
||
with open('/opt/netbox/initializers/rack_roles.yml', 'r') as stream: | ||
yaml=YAML(typ='safe') | ||
rack_roles = yaml.load(stream) | ||
|
||
if rack_roles is not None: | ||
for params in rack_roles: | ||
if 'color' in params: | ||
color = params.pop('color') | ||
|
||
for color_tpl in COLOR_CHOICES: | ||
if color in color_tpl: | ||
params['color'] = color_tpl[0] | ||
|
||
rack_role, created = RackRole.objects.get_or_create(**params) | ||
|
||
if created: | ||
print("🎨 Created rack role", rack_role.name) |
Oops, something went wrong.