VirtualMachine created by the provided "create_vm.py" script does not show correct interface count #8764

Closed
opened 2025-12-29 20:40:56 +01:00 by adam · 7 comments
Owner

Originally created by @derdeagle on GitHub (Oct 20, 2023).

NetBox version

v.3.6.4

Python version

3.11

Steps to Reproduce

  1. Download the provided customizations script
  2. Add the script to Netbox
  3. Fill in the required fields to create a VM
  4. Open the created VM
  5. Observe the "Interfaces" tab of the VM

Expected Behavior

I expect to see a "1" in the "Interfaces" tab button as there is one interface for the VM.

Observed Behavior

There is no number shown in the "Interfaces" tab button.
When adding an interface manually via the frontend there is a "1" shown even though there are two interfaces then. Upon deleting this manually created interface there is again no number shown in the "Interfaces" tab button.

Originally created by @derdeagle on GitHub (Oct 20, 2023). ### NetBox version v.3.6.4 ### Python version 3.11 ### Steps to Reproduce 1. Download the [provided customizations script](https://github.com/netbox-community/customizations/blob/master/scripts/create_vm.py) 2. Add the script to Netbox 3. Fill in the required fields to create a VM 4. Open the created VM 5. Observe the "Interfaces" tab of the VM ### Expected Behavior I expect to see a "1" in the "Interfaces" tab button as there is one interface for the VM. ### Observed Behavior There is no number shown in the "Interfaces" tab button. When adding an interface manually via the frontend there is a "1" shown even though there are two interfaces then. Upon deleting this manually created interface there is again no number shown in the "Interfaces" tab button.
adam closed this issue 2025-12-29 20:40:57 +01:00
Author
Owner

@jsenecal commented on GitHub (Oct 20, 2023):

Wouldn't this be better suited for the netbox-community/customizations issue tracker?

@jsenecal commented on GitHub (Oct 20, 2023): Wouldn't this be better suited for [the `netbox-community/customizations` issue tracker](https://github.com/netbox-community/customizations/issues)?
Author
Owner

@derdeagle commented on GitHub (Oct 20, 2023):

I cannot tell if the script is doing something wrong or not. I can at least imagine it being more of an internal Netbox / Django problem. What else should I be supposed to do than creating the VM and assigning the interface to it? The interface itself is there, just the counting in the webui is misleading / wrong.

To be frank I found this script after I wrote my own one and noticing this bug - I thought I did something wrong so I searched for examples. Then I tried this provided script and it showed the same result.

@derdeagle commented on GitHub (Oct 20, 2023): I cannot tell if the script is doing something wrong or not. I can at least imagine it being more of an internal Netbox / Django problem. What else should I be supposed to do than creating the VM and assigning the interface to it? The interface itself is there, just the counting in the webui is misleading / wrong. To be frank I found this script after I wrote my own one and noticing this bug - I thought I did something wrong so I searched for examples. Then I tried this provided script and it showed the same result.
Author
Owner

@derdeagle commented on GitHub (Oct 25, 2023):

I thought some screenshots of examples could be of help.

How it should look like (VM with a manually created interface)

screenshot_2023-10-25_09-54-43

How it actually looks like (VM with the interface created via script)

screenshot_2023-10-25_09-43-23

@derdeagle commented on GitHub (Oct 25, 2023): I thought some screenshots of examples could be of help. **How it _should_ look like** (VM with a manually created interface) ![screenshot_2023-10-25_09-54-43](https://github.com/netbox-community/netbox/assets/11424540/6e27204e-fc94-43b2-ad8a-ef689ec9a1d1) **How it actually looks like** (VM with the interface created via script) ![screenshot_2023-10-25_09-43-23](https://github.com/netbox-community/netbox/assets/11424540/036574fd-b439-4619-b52a-3911876c709c)
Author
Owner

@kkthxbye-code commented on GitHub (Oct 25, 2023):

69882088da/scripts/create_vm.py (L100)

Insert before the above line:

vm.refresh_from_db()

Netbox 3.6 added cached counters: https://github.com/netbox-community/netbox/issues/6347

While the implementation of those are pretty half-baked imo (there's multiple issues currently breaking it), the reason it breaks here is that saving the vm again after the first save, overwrites whatever changes are done in signal handlers, which is where the cached counters are handled.

@kkthxbye-code commented on GitHub (Oct 25, 2023): https://github.com/netbox-community/customizations/blob/69882088da5214529328c04057e4aba1580bc25e/scripts/create_vm.py#L100 Insert before the above line: `vm.refresh_from_db()` Netbox 3.6 added cached counters: https://github.com/netbox-community/netbox/issues/6347 While the implementation of those are pretty half-baked imo (there's multiple issues currently breaking it), the reason it breaks here is that saving the vm again after the first save, overwrites whatever changes are done in signal handlers, which is where the cached counters are handled.
Author
Owner

@derdeagle commented on GitHub (Oct 25, 2023):

@kkthxbye-code Thanks, that actually does the trick. I am also glad to explained the reason for it. Do you know and can you tell why vm.snapthot() is called and what it does though it might not be related to this issue?

@derdeagle commented on GitHub (Oct 25, 2023): @kkthxbye-code Thanks, that actually does the trick. I am also glad to explained the reason for it. Do you know and can you tell why `vm.snapthot()` is called and what it does though it might not be related to this issue?
Author
Owner

@kkthxbye-code commented on GitHub (Oct 25, 2023):

@derdeagle - Calling snapshot on an object saves the pre-change snapshot used for changelogs. If it is not called, the Pre-Change Data will be empty when viewing an objectchange.

@kkthxbye-code commented on GitHub (Oct 25, 2023): @derdeagle - Calling snapshot on an object saves the pre-change snapshot used for changelogs. If it is not called, the `Pre-Change Data` will be empty when viewing an objectchange.
Author
Owner

@derdeagle commented on GitHub (Oct 25, 2023):

@kkthxbye-code Thanks a lot. As I don't see a bug in Netbox here I will just close this issue. Again, thanks all.

@derdeagle commented on GitHub (Oct 25, 2023): @kkthxbye-code Thanks a lot. As I don't see a bug in Netbox here I will just close this issue. Again, thanks all.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8764