VLANs available not shown correct #4804

Closed
opened 2025-12-29 19:20:48 +01:00 by adam · 6 comments
Owner

Originally created by @PieterL75 on GitHub (Apr 22, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v2.10.5

Python version

3.7

Steps to Reproduce

Open a VLAN Group
Looks for the 'xxx Vlans Available'
image

Expected Behavior

The exact number of available vlans

Observed Behavior

The number of available vlans is not correct.
Between 1528 and 1528, there is 1 available shown
Between 1529 and 1530, there are 2566 available shown

I have the same issue on my DEV box that is running v2.11.0.

Unfortunately I don't know when or how it appeared, I just noticed it today.

Originally created by @PieterL75 on GitHub (Apr 22, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v2.10.5 ### Python version 3.7 ### Steps to Reproduce Open a VLAN Group Looks for the 'xxx Vlans Available' ![image](https://user-images.githubusercontent.com/74899468/115672294-b33e2080-a34b-11eb-9ccc-395dcef27519.png) ### Expected Behavior The exact number of available vlans ### Observed Behavior The number of available vlans is not correct. Between 1528 and 1528, there is 1 available shown Between 1529 and 1530, there are 2566 available shown I have the same issue on my DEV box that is running v2.11.0. Unfortunately I don't know when or how it appeared, I just noticed it today.
adam added the type: bugstatus: accepted labels 2025-12-29 19:20:48 +01:00
adam closed this issue 2025-12-29 19:20:48 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 22, 2021):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v2.11.1. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@jeremystretch commented on GitHub (Apr 22, 2021): Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v2.11.1. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
Author
Owner

@PieterL75 commented on GitHub (Apr 23, 2021):

Jeremy,

It looks that the issue occurs when creating a new vlan in a 'script' py.

image

      newvid=self.getnextfreevlan(vlangroup.id,51,100)
      if newvid == None:
         self.log_failure(f"Unable to select a free vlan in the 51-100 range")
      else:
         vlanname = f"CUST-{name}-{newvid}"
         newvlan = VLAN(
            vid = newvid,
            name = vlanname,
            group = vlangroup,
         )
         newvlan.save()
         for tag in data['env_tags']:
            newvlan.tags.add(tag.name)
         self.log_success(f"Vlan Selected : [{vlanname} ({newvid})](/ipam/vlans/{newvlan.id}/)")

   def getnextfreevlan(self, groupid, minvid, maxvid):
      vlan_ids = VLAN.objects.filter(group=groupid).values_list('vid', flat=True)
      for x in range(minvid, maxvid):
         if x not in vlan_ids:
            return x

After that, the free vlans are messed up
image

Is this because of the way the new vlan is created ? Am I missing some crucial step in the code ?

Pieter

@PieterL75 commented on GitHub (Apr 23, 2021): Jeremy, It looks that the issue occurs when creating a new vlan in a 'script' py. ![image](https://user-images.githubusercontent.com/74899468/115833565-7c800d00-a414-11eb-9c94-5294a1bb6d53.png) ``` newvid=self.getnextfreevlan(vlangroup.id,51,100) if newvid == None: self.log_failure(f"Unable to select a free vlan in the 51-100 range") else: vlanname = f"CUST-{name}-{newvid}" newvlan = VLAN( vid = newvid, name = vlanname, group = vlangroup, ) newvlan.save() for tag in data['env_tags']: newvlan.tags.add(tag.name) self.log_success(f"Vlan Selected : [{vlanname} ({newvid})](/ipam/vlans/{newvlan.id}/)") def getnextfreevlan(self, groupid, minvid, maxvid): vlan_ids = VLAN.objects.filter(group=groupid).values_list('vid', flat=True) for x in range(minvid, maxvid): if x not in vlan_ids: return x ``` After that, the free vlans are messed up ![image](https://user-images.githubusercontent.com/74899468/115833714-a89b8e00-a414-11eb-8d92-484ab5be56b7.png) Is this because of the way the new vlan is created ? Am I missing some crucial step in the code ? Pieter
Author
Owner

@PieterL75 commented on GitHub (Apr 23, 2021):

I flushed the database, and upgrade to v2.11.1.
Now the same actions don't do this behavior.

Next step, was to revert back to my database, upgrade to v2.11.1. but that does the same strange thing again.
Looks like something got corrupted in my database..

So I took an export of my VLANS to csv, and then I noticed, that the vlans where it goes wrong, had a Group, but no Site value:

image

After correcting the Site to a good value, the available vlans were correct again
image

I updated the script so that it will add the site id to the vlan

   def run(self, data, commit):
      name=data['env_name'].upper()
      snl=int(data['env_snl'])
      prefix=data['env_prefix'].prefix
      pfx=Prefix.objects.get(prefix=prefix)
      vlangroup=VLANGroup.objects.get(id=3)
      vlansite=Site.objects.get(id=vlangroup.scope_id)
      addtags=[]
      for tag in data['env_tags']:
        addtags.append(tag.id)

      newvid=self.getnextfreevlan(vlangroup.id,51,2500)
      if newvid == None:
         self.log_failure(f"Unable to select a free vlan in the 1500-2500 range")
      else:
         vlanname = f"CUST-{name}-{newvid}"
         newvlan = VLAN(
            vid = newvid,
            name = vlanname,
            group = vlangroup,
            site = vlansite
         )
         newvlan.save()
         for tag in data['env_tags']:
            newvlan.tags.add(tag.name)
         self.log_success(f"Vlan Selected : [{vlanname} ({newvid})](/ipam/vlans/{newvlan.id}/)")

But wondering if this is a 'bug' or not.. The fact that the site id is not present, causing the available vlans to become incorrect.

Pieter

@PieterL75 commented on GitHub (Apr 23, 2021): I flushed the database, and upgrade to v2.11.1. Now the same actions don't do this behavior. Next step, was to revert back to my database, upgrade to v2.11.1. but that does the same strange thing again. Looks like something got corrupted in my database.. So I took an export of my VLANS to csv, and then I noticed, that the vlans where it goes wrong, had a Group, but no Site value: ![image](https://user-images.githubusercontent.com/74899468/115844496-2ca74300-a420-11eb-9bd0-613fa2b0a574.png) After correcting the Site to a good value, the available vlans were correct again ![image](https://user-images.githubusercontent.com/74899468/115844636-506a8900-a420-11eb-972a-8ffb575760dc.png) I updated the script so that it will add the site id to the vlan ``` def run(self, data, commit): name=data['env_name'].upper() snl=int(data['env_snl']) prefix=data['env_prefix'].prefix pfx=Prefix.objects.get(prefix=prefix) vlangroup=VLANGroup.objects.get(id=3) vlansite=Site.objects.get(id=vlangroup.scope_id) addtags=[] for tag in data['env_tags']: addtags.append(tag.id) newvid=self.getnextfreevlan(vlangroup.id,51,2500) if newvid == None: self.log_failure(f"Unable to select a free vlan in the 1500-2500 range") else: vlanname = f"CUST-{name}-{newvid}" newvlan = VLAN( vid = newvid, name = vlanname, group = vlangroup, site = vlansite ) newvlan.save() for tag in data['env_tags']: newvlan.tags.add(tag.name) self.log_success(f"Vlan Selected : [{vlanname} ({newvid})](/ipam/vlans/{newvlan.id}/)") ``` But wondering if this is a 'bug' or not.. The fact that the site id is not present, causing the available vlans to become incorrect. Pieter
Author
Owner

@jeremystretch commented on GitHub (Apr 23, 2021):

In order for this to be triaged as a bug, you'll need to provide specific steps that someone can take to reproduce the reported behavior using the UI or REST API. If you need assistance with your script, please close this issue and open a discussion instead.

@jeremystretch commented on GitHub (Apr 23, 2021): In order for this to be triaged as a bug, you'll need to provide specific steps that someone can take to reproduce the reported behavior using the UI or REST API. If you need assistance with your script, please close this issue and open a discussion instead.
Author
Owner

@PieterL75 commented on GitHub (May 4, 2021):

Jeremy,

I was able to reproduce this in the https://demo.netbox.dev/ instance.
Steps

This happens when a VLAN is added without a 'Site' value.
When setting the 'Site' to "Virginia / JBB Branch 109", the numbers are calculated correct.
image

Another thing I noted, the 'xx VLANs Available' used to be a clickable button but is regular text now.

I hope this satisfies a valid bugreport

Thank you for the support

Pieter

@PieterL75 commented on GitHub (May 4, 2021): Jeremy, I was able to reproduce this in the https://demo.netbox.dev/ instance. Steps - Wait for a clean of https://demo.netbox.dev/ - Go to VLAN Group JBB109 (https://demo.netbox.dev/ipam/vlan-groups/3/) - Hit '+ Add Vlan' button (https://demo.netbox.dev/ipam/vlans/add/?group=3) ID: 190 Name: testing190 Leave other values default - Go to the Vlan Group details (https://demo.netbox.dev/ipam/vlan-groups/3/) - Now you will see that there are 200 Vlans available BEFORE vlanid 190; and 3904 VLANs available betweenvid 190 and 201 ![image](https://user-images.githubusercontent.com/74899468/116968502-e0c48b80-acb4-11eb-8b4d-db1c87acd3ac.png) This happens when a VLAN is added without a 'Site' value. When setting the 'Site' to "Virginia / JBB Branch 109", the numbers are calculated correct. ![image](https://user-images.githubusercontent.com/74899468/116968660-39942400-acb5-11eb-8229-704f4cf60f89.png) Another thing I noted, the 'xx VLANs Available' used to be a clickable button but is regular text now. I hope this satisfies a valid bugreport Thank you for the support Pieter
Author
Owner

@jeremystretch commented on GitHub (May 4, 2021):

Looks like this stems from a tweak to the VLAN ordering. Should be a simple fix.

Another thing I noted, the 'xx VLANs Available' used to be a clickable button but is regular text now.

This was addressed under #6308 and will be fixed in v2.11.3.

@jeremystretch commented on GitHub (May 4, 2021): Looks like this stems from a tweak to the VLAN ordering. Should be a simple fix. > Another thing I noted, the 'xx VLANs Available' used to be a clickable button but is regular text now. This was addressed under #6308 and will be fixed in v2.11.3.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4804