Incorrect Interface Count Reported in VM Change Event #9831

Closed
opened 2025-12-29 21:23:20 +01:00 by adam · 1 comment
Owner

Originally created by @sapergus on GitHub (Jun 12, 2024).

Deployment Type

Self-hosted

NetBox Version

v3.7.8

Python Version

3.10

Steps to Reproduce

When deleting an interface on a virtual machine, the generated VM change event reports an incorrect interface count. Both data.interface_count and snapshots.postchange.interface_count retain the old number of interfaces (1), instead of updating to the expected count of 0. However, snapshots.prechange.interface_count correctly reflects the interface count before deletion.

  1. Enable webhook events for "create", "update" and "delete" for VM objects for the "virtualization | interface" and "virtualization | virtual machine" types.
  2. Trigger a deletion of an interface on a VM.
  3. Monitor the generated VM change event.
  4. Note the values of data.interface_count, snapshots.postchange.interface_count, and snapshots.prechange.interface_count.

The VM updated event:

{
    "data": {
        ...
        "interface_count": 1,
        ...
    },
    "event": "updated",
    "model": "virtualmachine",
    "request_id": "5b7ba682-d37c-4ced-b14a-a2ae5cf20c18",
    "snapshots": {
        "postchange": {
            ...
            "interface_count": 1,
            ...
        },
        "prechange": {
            ...
            "interface_count": 1,
            ...
        }
    },
    ...
}

The vminterface deleted event:

{
    "data": {
        ...
        "name": "vnic1",
        ...
    },
    "event": "deleted",
    "model": "vminterface",
    "snapshots": {
        "postchange": null,
        "prechange": {
            ...
            "name": "vnic1",
            ...
        }
    },
    ...
}

Expected Behavior

After deleting an interface on a VM, the interface count variables (data.interface_count and snapshots.postchange.interface_count) should be updated to reflect the correct count of interfaces (0).

Observed Behavior

The interface count variables (data.interface_count and snapshots.postchange.interface_count) retain the old number of interfaces (1), failing to update after interface deletion. Only snapshots.prechange.interface_count reflects the correct count of interfaces before deletion.

Originally created by @sapergus on GitHub (Jun 12, 2024). ### Deployment Type Self-hosted ### NetBox Version v3.7.8 ### Python Version 3.10 ### Steps to Reproduce When deleting an interface on a virtual machine, the generated VM change event reports an incorrect interface count. Both data.interface_count and snapshots.postchange.interface_count retain the old number of interfaces (1), instead of updating to the expected count of 0. However, snapshots.prechange.interface_count correctly reflects the interface count before deletion. 1. Enable webhook events for "create", "update" and "delete" for VM objects for the "virtualization | interface" and "virtualization | virtual machine" types. 2. Trigger a deletion of an interface on a VM. 3. Monitor the generated VM change event. 4. Note the values of data.interface_count, snapshots.postchange.interface_count, and snapshots.prechange.interface_count. The VM updated event: ``` { "data": { ... "interface_count": 1, ... }, "event": "updated", "model": "virtualmachine", "request_id": "5b7ba682-d37c-4ced-b14a-a2ae5cf20c18", "snapshots": { "postchange": { ... "interface_count": 1, ... }, "prechange": { ... "interface_count": 1, ... } }, ... } ``` The vminterface deleted event: ``` { "data": { ... "name": "vnic1", ... }, "event": "deleted", "model": "vminterface", "snapshots": { "postchange": null, "prechange": { ... "name": "vnic1", ... } }, ... } ``` ### Expected Behavior After deleting an interface on a VM, the interface count variables (data.interface_count and snapshots.postchange.interface_count) should be updated to reflect the correct count of interfaces (0). ### Observed Behavior The interface count variables (data.interface_count and snapshots.postchange.interface_count) retain the old number of interfaces (1), failing to update after interface deletion. Only snapshots.prechange.interface_count reflects the correct count of interfaces before deletion.
adam closed this issue 2025-12-29 21:23:20 +01:00
Author
Owner

@arthanson commented on GitHub (Jun 14, 2024):

@sapergus There actually isn't a change event put out on the VM when you add / remove an interface so I'm not sure what the update record you are seeing for the VM. The eventing is driven off the changelog so you can look at the changelog records when you add the VM you get one record (the VM creation). When you add the interface to it you will get one more record (vm interface creation) and finally when you delete the interface you will get one more record (vm interface deleted).

If you feel there should be a separate update delete generated for the VM itself then you can open a feature request and it can be discussed as there may be some technical issues with cascading the events. Closing for now.

@arthanson commented on GitHub (Jun 14, 2024): @sapergus There actually isn't a change event put out on the VM when you add / remove an interface so I'm not sure what the update record you are seeing for the VM. The eventing is driven off the changelog so you can look at the changelog records when you add the VM you get one record (the VM creation). When you add the interface to it you will get one more record (vm interface creation) and finally when you delete the interface you will get one more record (vm interface deleted). If you feel there should be a separate update delete generated for the VM itself then you can open a feature request and it can be discussed as there may be some technical issues with cascading the events. Closing for now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9831