netbox-docker/startup_scripts/020_tags.py

24 lines
538 B
Python
Raw Normal View History

import sys
2020-12-30 01:36:58 +01:00
from extras.models import Tag
2020-12-30 01:36:58 +01:00
from startup_script_utils import load_yaml
from utilities.choices import ColorChoices
2020-12-30 01:36:58 +01:00
tags = load_yaml("/opt/netbox/initializers/tags.yml")
2020-12-30 01:36:58 +01:00
if tags is None:
sys.exit()
2020-12-30 01:36:58 +01:00
for params in tags:
if "color" in params:
color = params.pop("color")
2020-12-30 01:36:58 +01:00
for color_tpl in ColorChoices:
if color in color_tpl:
params["color"] = color_tpl[0]
2020-12-30 01:36:58 +01:00
tag, created = Tag.objects.get_or_create(**params)
2020-12-30 01:36:58 +01:00
if created:
print("🎨 Created Tag", tag.name)