Files
netbox/docker/startup_scripts/001_tenants.py

21 lines
463 B
Python

from tenancy.models import Tenant
from ruamel.yaml import YAML
from pathlib import Path
import sys
file = Path('/opt/netbox/initializers/tenants.yml')
if not file.is_file():
sys.exit()
with file.open('r') as stream:
yaml = YAML(typ='safe')
tenants = yaml.load(stream)
if tenants is not None:
for params in tenants:
tenant, created = Tenant.objects.get_or_create(**params)
if created:
print("🏠 Created tenant", tenant.name)