2021-02-08 11:59:33 +01:00
|
|
|
import sys
|
2020-12-30 01:36:58 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
from extras.models import Tag
|
2020-12-30 01:36:58 +01:00
|
|
|
from startup_script_utils import load_yaml
|
2021-02-08 11:59:33 +01:00
|
|
|
from utilities.choices import ColorChoices
|
2020-12-30 01:36:58 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
tags = load_yaml("/opt/netbox/initializers/tags.yml")
|
2020-12-30 01:36:58 +01:00
|
|
|
|
|
|
|
if tags is None:
|
2021-02-08 11:59:33 +01:00
|
|
|
sys.exit()
|
2020-12-30 01:36:58 +01:00
|
|
|
|
|
|
|
for params in tags:
|
2021-02-08 11:59:33 +01:00
|
|
|
if "color" in params:
|
|
|
|
color = params.pop("color")
|
2020-12-30 01:36:58 +01:00
|
|
|
|
2021-02-08 11:59:33 +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
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
tag, created = Tag.objects.get_or_create(**params)
|
2020-12-30 01:36:58 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
if created:
|
|
|
|
print("🎨 Created Tag", tag.name)
|