mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2025-08-09 00:04:46 +02:00
add custom link initializers
This commit is contained in:
committed by
Christian Mäder
parent
3a0b3fe133
commit
187ae4b2a1
24
startup_scripts/280_custom_links.py
Normal file
24
startup_scripts/280_custom_links.py
Normal file
@ -0,0 +1,24 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from extras.models import CustomLink
|
||||
from startup_script_utils import load_yaml
|
||||
import sys
|
||||
|
||||
|
||||
custom_links = load_yaml('/opt/netbox/initializers/custom_links.yml')
|
||||
|
||||
if custom_links is None:
|
||||
sys.exit()
|
||||
|
||||
def get_content_type_id(content_type_str):
|
||||
for type in ContentType.objects.all():
|
||||
if type.name == content_type_str:
|
||||
return type.id
|
||||
|
||||
for link in custom_links:
|
||||
content_type = link.pop('content_type')
|
||||
link['content_type_id'] = get_content_type_id(content_type)
|
||||
if link['content_type_id'] is None:
|
||||
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type))
|
||||
else:
|
||||
CustomLink(**link).save()
|
||||
|
Reference in New Issue
Block a user