-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add Device Type Components - Module Bays and Console Ports #100
Comments
I just noticed this issue with PDUs and adding Power Outlets. Have you come across a solution? Script works great and does exactly what I've been needing but this is making it hard to move forward with all the changes I need to make. |
Same Issue here. Does someone have a solution? |
I upgraded to the latest version and that fixed my issue. |
This is also affecting me. v3.7.4 Same issue. Ran script and created missing components (Interfaces, Console Port, PSU Module bays). Only Interfaces are accessible directly via the device's page. To find Console or PSU Mod Bays, I have to search them up in components list. Not breaking, but certainly an annoyance. |
The next issue with this bug: Any devices that were created and affected by this bug, will still have an incorrect count of objects.
I threw together a script that just calcs the delta and feeds the inputs into This logic could easily be inserted into the main script as a way to fix the issue retroactively when ran on a device. """
This script runs a counter check on each device's components and updates discrepancies
"""
from dcim.models import Manufacturer, DeviceType, Device
from extras.scripts import Script, ObjectVar, MultiObjectVar
from utilities.counters import update_counter
class FixDeviceComponentCounts(Script):
class Meta:
name = "Fix Device Component Counts"
description = (
"run a counter check on each device's components and updates discrepancies"
)
manufacturer = ObjectVar(
model=Manufacturer,
required=False,
)
device_type = ObjectVar(
model=DeviceType,
query_params={
"manufacturer_id": "$manufacturer",
},
required=False,
)
devices = MultiObjectVar(
model=Device,
query_params={
"device_type_id": "$device_type",
},
)
def run(self, data, commit):
for device in data["devices"]:
device.full_clean()
for counter_name, count_attr_name in [
("console_port_count", "consoleports"),
("console_server_port_count", "consoleserverports"),
("power_port_count", "powerports"),
("power_outlet_count", "poweroutlets"),
("interfaces_count", "interfaces"),
("rear_port_count", "rearports"),
("front_port_count", "frontports"),
("device_bay_count", "devicebays"),
("module_bay_count", "modulebays"),
]:
actual_attr_count = getattr(device, count_attr_name).count()
expected_attr_count = getattr(device, counter_name)
# delta = device.consoleports.count() - device.console_port_count
delta = actual_attr_count - expected_attr_count
if delta != 0:
update_counter(device._meta.model, device.pk, counter_name, delta)
self.log_success(
"%s (%d): updated %s from %d to %d"
% (
device.name,
device.id,
counter_name,
expected_attr_count,
actual_attr_count,
)
) |
@ip-rx - there's a management command for that. |
That's the right answer, or more succinctly:
will fix the problem. |
Even better, thanks! |
When I run this script I get an error about the module bays. Anyone know what this might mean? If I comment out the line for module bays then it works. Obviously module bays don't get applied but everything else does. `An exception occurred: IntegrityError: null value in column "level" of relation "dcim_modulebay" violates not-null constraint DETAIL: Failing row contains (2024-09-20 18:40:03.531782+00, 2024-09-20 18:40:03.531805+00, {}, 261, PIM1, PIM00000001, Mini-PIM 1, PIM1, , 118, null, null, null, null, null, null). Traceback (most recent call last): The above exception was the direct cause of the following exception: Traceback (most recent call last): |
I guess it's because the module model changed in Netbox v4.1.0 to allow nested (hierarchical) modules. |
I'm running into the same error as @jburgon. I tried to piece together a fix don't seem to be able to. |
Dunno where if you found this, but you are legend. Thank you! Just for ref another issue: netbox-community/netbox#14446 |
Hi
When updating a device with the script add_device_type_components.py, both interfaces, module bays and console ports are populated. However, the tab menues for module bays and console ports does not get updated with the new data. In this screenshot, you may see how the device has got 17 module bays, but only showing 1 (which was there from before) in the menu:
If there are no module bays or console ports, the tab menu item is not displayed. Hence you will not have the oportunity to use them. As shown here:
Interfaces works as expected.
Any idea what could cause this?
Netbox v3.6.6
The text was updated successfully, but these errors were encountered: