mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 04:12:25 -06:00
21 lines
494 B
Python
21 lines
494 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.update_or_create(name=params['name'], defaults=params)
|
|
|
|
if created:
|
|
print("🏠 Created tenant", tenant.name)
|