Add function to load YAML files
This commit starts to remove some code redundancy from the startup scripts for easier maintenance.
This commit is contained in:
parent
3717b7469a
commit
50ade7bce1
30 changed files with 669 additions and 811 deletions
|
@ -1,19 +1,14 @@
|
|||
from tenancy.models import TenantGroup
|
||||
from ruamel.yaml import YAML
|
||||
from pathlib import Path
|
||||
from startup_script_utils import load_yaml
|
||||
import sys
|
||||
|
||||
file = Path('/opt/netbox/initializers/tenant_groups.yml')
|
||||
if not file.is_file():
|
||||
tenant_groups = load_yaml('/opt/netbox/initializers/tenant_groups.yml')
|
||||
|
||||
if tenant_groups is None:
|
||||
sys.exit()
|
||||
|
||||
with file.open('r') as stream:
|
||||
yaml = YAML(typ='safe')
|
||||
tenant_groups = yaml.load(stream)
|
||||
for params in tenant_groups:
|
||||
tenant_group, created = TenantGroup.objects.get_or_create(**params)
|
||||
|
||||
if tenant_groups is not None:
|
||||
for params in tenant_groups:
|
||||
tenant_group, created = TenantGroup.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("🔳 Created Tenant Group", tenant_group.name)
|
||||
if created:
|
||||
print("🔳 Created Tenant Group", tenant_group.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue