[PR #12784] [MERGED] Closes #12622: Fix assigning VLAN without site to Prefix #14048

Closed
opened 2025-12-29 23:22:13 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/12784
Author: @dhenschen
Created: 6/1/2023
Status: Merged
Merged: 6/14/2023
Merged by: @jeremystretch

Base: developHead: 12622-fix-assigning-vlan-without-site-to-prefix


📝 Commits (4)

  • 23de277 Issue #12622: Fix creating Prefix using VLAN without site
  • 7c0fade Issue #12622: Fix importing Prefix using VLAN without site
  • 76eaf20 Issue #12622: Cleanup code to filter allowed VLANs on a prefix import
  • dc059a6 Closes #12622: Switch to VLAN selector dialog when creating Prefix

📊 Changes

3 files changed (+85 additions, -12 deletions)

View changed files

📝 netbox/ipam/forms/bulk_import.py (+25 -9)
📝 netbox/ipam/forms/model_forms.py (+1 -3)
📝 netbox/ipam/tests/test_views.py (+59 -0)

📄 Description

Summary

This Pull Request enables users to be to select VLANs without a site assignment during creation and bulk import of Prefixes.

This Pull Request addresses issues #12622 and #12619.

Background

Previously, only VLANs assigned to the same site as the prefix were available for selection. However, as it is possible to create VLANs without a site assignment, a subset of selectable VLANs was excluded from the VLAN filter dropdown. Additionally, the import logic did not allow the assignment of a VLAN without a site when a site was specified for the prefix.

Changes

This Pull Request introduces a selector dialog to facilitate filtering and searching for VLANs during assignment. Furthermore, the prefix import code is enhanced to include VLANs without a site assignment in the filtering logic.

Benefits

This change enhances the usability of NetBox by allowing users to assign VLANs with a null site to Prefixes through the UI. Without this modification, Prefixes could only be assigned VLANs from the same site when a site was selected for a Prefix.

Creation Test

  1. Import the demo data into NetBox
  2. Login into NetBox
  3. Import the following VLAN from with the YAML format under IPAM > VLANS > VLANs > Import
vid: 1000
name: management
status: active
  1. Create a new Prefix from IPAM > PREFIXES > Prefixes > Add.
  2. Set the Prefix field to 10.1.0.0/24
  3. Set the Site field to DM-Akron
  4. Look for the new management VLAN in the selector dialog. The user can search for a site set to None to easily find the new managment VLAN without a site.

image

  1. Click Create and Verify the new prefix is successfully created

Import Test

Steps for reproducing importing a new Prefix:

  1. Import the demo data into NetBox
  2. Login to NetBox
  3. Import the following VLAN from with the YAML format under IPAM > VLANS > VLANs > Import
vid: 1000
name: management
status: active
  1. Import a new Prefix from IPAM > PREFIXES > Prefixes > Import with the following YAML
prefix: 10.1.1.0/24
status: active
site: DM-Akron
vlan: 1000
  1. With the changes from this Pull Request, the import successfully assigns a VLAN without a site to a Prefix with a site.

Import Query Tests

I manually tested importing different variations of prefixes to verify the new query in PrefixImportForm. The query results were collected by temporarily adding a print statement to PrefixImportForm.__init__

Import Test 1

prefix: 10.1.1.0/24
status: active
site: DM-Akron
vlan: 1002
vlan_group: JBB-Global

This resulted in the following query:

(AND: (OR: ('site__name', 'DM-Akron'), ('site__name__isnull', True)), ('group__name', 'JBB-Global'))

Import Test 2

prefix: 10.1.1.0/24
status: active
site: DM-Akron
vlan: 1000

This resulted in the following query:

(OR: ('site__name', 'DM-Akron'), ('site__name__isnull', True))

Import Test 3

prefix: 10.1.1.0/24
status: active
vlan: 1000

This resulted in the following query:

(AND: )

Import Test 4

prefix: 10.1.1.0/24
status: active
vlan: 1002
vlan_group: JBB-Global

This resulted in the following query:

(AND: ('group__name', 'JBB-Global'))

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/12784 **Author:** [@dhenschen](https://github.com/dhenschen) **Created:** 6/1/2023 **Status:** ✅ Merged **Merged:** 6/14/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `12622-fix-assigning-vlan-without-site-to-prefix` --- ### 📝 Commits (4) - [`23de277`](https://github.com/netbox-community/netbox/commit/23de277386c39e297fac37da6ed0083af54f5e31) Issue #12622: Fix creating Prefix using VLAN without site - [`7c0fade`](https://github.com/netbox-community/netbox/commit/7c0fadeb17edd2054b32cfb4f5829dbde6103379) Issue #12622: Fix importing Prefix using VLAN without site - [`76eaf20`](https://github.com/netbox-community/netbox/commit/76eaf20b8fc66a903e00dad79c43b39cc2dff0e0) Issue #12622: Cleanup code to filter allowed VLANs on a prefix import - [`dc059a6`](https://github.com/netbox-community/netbox/commit/dc059a64c51ab7f4e7d04b1d6629017f006d0e96) Closes #12622: Switch to VLAN selector dialog when creating Prefix ### 📊 Changes **3 files changed** (+85 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/forms/bulk_import.py` (+25 -9) 📝 `netbox/ipam/forms/model_forms.py` (+1 -3) 📝 `netbox/ipam/tests/test_views.py` (+59 -0) </details> ### 📄 Description ### Summary This Pull Request enables users to be to select VLANs without a site assignment during creation and bulk import of Prefixes. This Pull Request addresses issues #12622 and #12619. ### Background Previously, only VLANs assigned to the same site as the prefix were available for selection. However, as it is possible to create VLANs without a site assignment, a subset of selectable VLANs was excluded from the VLAN filter dropdown. Additionally, the import logic did not allow the assignment of a VLAN without a site when a site was specified for the prefix. ### Changes This Pull Request introduces a selector dialog to facilitate filtering and searching for VLANs during assignment. Furthermore, the prefix import code is enhanced to include VLANs without a site assignment in the filtering logic. ### Benefits This change enhances the usability of NetBox by allowing users to assign VLANs with a null site to Prefixes through the UI. Without this modification, Prefixes could only be assigned VLANs from the same site when a site was selected for a Prefix. # Creation Test 1. Import the demo data into NetBox 2. Login into NetBox 3. Import the following VLAN from with the YAML format under IPAM > VLANS > VLANs > Import ```yaml vid: 1000 name: management status: active ``` 4. Create a new Prefix from IPAM > PREFIXES > Prefixes > Add. 5. Set the Prefix field to `10.1.0.0/24` 6. Set the Site field to `DM-Akron` 7. Look for the new management VLAN in the selector dialog. The user can search for a site set to None to easily find the new managment VLAN without a site. ![image](https://github.com/netbox-community/netbox/assets/11417982/e859cc3d-5eff-43a8-b697-9d3812cb3eb6) 8. Click Create and Verify the new prefix is successfully created # Import Test Steps for reproducing importing a new Prefix: 1. Import the demo data into NetBox 2. Login to NetBox 3. Import the following VLAN from with the YAML format under IPAM > VLANS > VLANs > Import ```yaml vid: 1000 name: management status: active ``` 4. Import a new Prefix from IPAM > PREFIXES > Prefixes > Import with the following YAML ```yaml prefix: 10.1.1.0/24 status: active site: DM-Akron vlan: 1000 ``` 5. With the changes from this Pull Request, the import successfully assigns a VLAN without a site to a Prefix with a site. ### Import Query Tests I manually tested importing different variations of prefixes to verify the new query in `PrefixImportForm`. The query results were collected by temporarily adding a print statement to `PrefixImportForm.__init__` #### Import Test 1 ```yaml prefix: 10.1.1.0/24 status: active site: DM-Akron vlan: 1002 vlan_group: JBB-Global ``` This resulted in the following query: ``` (AND: (OR: ('site__name', 'DM-Akron'), ('site__name__isnull', True)), ('group__name', 'JBB-Global')) ``` #### Import Test 2 ```yaml prefix: 10.1.1.0/24 status: active site: DM-Akron vlan: 1000 ``` This resulted in the following query: ``` (OR: ('site__name', 'DM-Akron'), ('site__name__isnull', True)) ``` #### Import Test 3 ```yaml prefix: 10.1.1.0/24 status: active vlan: 1000 ``` This resulted in the following query: ``` (AND: ) ``` #### Import Test 4 ```yaml prefix: 10.1.1.0/24 status: active vlan: 1002 vlan_group: JBB-Global ``` This resulted in the following query: ``` (AND: ('group__name', 'JBB-Global')) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:22:13 +01:00
adam closed this issue 2025-12-29 23:22:13 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14048