Allow for creation of interfaces and tenants in startup / initializers

This commit is contained in:
Marco Ceppi
2019-11-25 11:27:24 -05:00
parent fff05b3154
commit 64de66e2d5
4 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
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)