mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 04:12:25 -06:00
Allow for creation of interfaces and tenants in startup / initializers
This commit is contained in:
20
docker/startup_scripts/001_tenants.py
Normal file
20
docker/startup_scripts/001_tenants.py
Normal 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)
|
||||
Reference in New Issue
Block a user