Skip to content

Mix expandables fields #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/netbox_initializers/initializers/device_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ def expand_templates(params: List[dict], device_type: DeviceType) -> List[dict]:
for param in params:
param["device_type"] = device_type
expanded_fields = {}
has_plain_fields = False

for field in templateable_fields:
template_value = param.pop(f"{field}_template", None)

if field in param:
has_plain_fields = True
elif template_value:
if template_value:
expanded_fields[field] = list(expand_alphanumeric_pattern(template_value))

if expanded_fields and has_plain_fields:
raise ValueError(f"Mix of plain and template keys provided for {templateable_fields}")
elif not expanded_fields:
if not expanded_fields:
expanded.append(param)
continue

Expand Down