Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion module/netbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
NBMACAddress,
NBFHRPGroupItem,
NBInventoryItem,
NBPowerPort
NBPowerPort,
NBModuleType,
NBModuleBay,
NBModule
)

primary_tag_name = "NetBox-synced"
97 changes: 94 additions & 3 deletions module/netbox/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,8 @@ def __init__(self, *args, **kwargs):
NBPowerPort.object_type,
NBClusterGroup.object_type,
NBVMInterface.object_type,
NBVM.object_type
NBVM.object_type,
NBModule.object_type
]

self.data_model = {
Expand Down Expand Up @@ -2076,7 +2077,9 @@ def __init__(self, *args, **kwargs):
"description": 200,
"mark_connected": bool,
"tags": NBTagList,
"parent": object
"parent": object,
# NetBox cascade-deletes module components, so the module owns its interfaces
"module": NBModule
}
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -2412,7 +2415,9 @@ def __init__(self, *args, **kwargs):
"allocated_draw": int,
"mark_connected": bool,
"tags": NBTagList,
"custom_fields": NBCustomField
"custom_fields": NBCustomField,
# the PSU module owns its power port, NetBox cascade-deletes it with the module
"module": NBModule
}
super().__init__(*args, **kwargs)

Expand All @@ -2431,4 +2436,90 @@ def update(self, data=None, read_from_netbox=False, source=None):

super().update(data=data, read_from_netbox=read_from_netbox, source=source)


class NBModuleType(NetBoxObject):
name = "module type"
api_path = "dcim/module-types"
object_type = "dcim.moduletype"
# matched by model only, like NBDeviceType (server part models are effectively unique)
primary_key = "model"
prune = False
# modules replace the deprecated inventory items starting with NetBox 4.3
min_netbox_version = "4.3"

def __init__(self, *args, **kwargs):
self.data_model = {
"model": 100,
"manufacturer": NBManufacturer,
"part_number": 50,
"description": 200,
"comments": str,
"tags": NBTagList,
"custom_fields": NBCustomField
}
super().__init__(*args, **kwargs)


class NBModuleBay(NetBoxObject):
name = "module bay"
api_path = "dcim/module-bays"
object_type = "dcim.modulebay"
primary_key = "name"
secondary_key = "device"
prune = True
min_netbox_version = "4.3"

def __init__(self, *args, **kwargs):
self.data_model = {
"device": NBDevice,
"name": 64,
"label": 64,
"position": 30,
"description": 200,
"tags": NBTagList,
"custom_fields": NBCustomField
}
super().__init__(*args, **kwargs)


class NBModule(NetBoxObject):
name = "module"
api_path = "dcim/modules"
object_type = "dcim.module"
# a module has no name of its own, it is identified by the bay it is installed in
primary_key = "module_bay"
secondary_key = "device"
prune = True
min_netbox_version = "4.3"

def __init__(self, *args, **kwargs):
self.data_model = {
"device": NBDevice,
"module_bay": NBModuleBay,
"module_type": NBModuleType,
"status": ["offline", "active", "planned", "staged", "failed", "inventory", "decommissioning"],
"serial": 50,
"asset_tag": 50,
"description": 200,
"tags": NBTagList,
"custom_fields": NBCustomField
}
super().__init__(*args, **kwargs)

def get_display_name(self, data=None, including_second_key=False):

# a module has no name on its own, derive its display name from the module bay it lives in
this_data_set = data if data is not None else self.data

if this_data_set is not None:
module_bay = this_data_set.get("module_bay")
if isinstance(module_bay, NetBoxObject):
return module_bay.get_display_name(including_second_key=including_second_key)
if isinstance(module_bay, dict):
bay_name = module_bay.get("name") or module_bay.get("display")
if bay_name is not None:
return bay_name

return super().get_display_name(data=data, including_second_key=including_second_key)

# EOF
7 changes: 7 additions & 0 deletions module/sources/check_redfish/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def __init__(self):
is then stored in the 'system_serial' custom field""",
default_value=False),

ConfigOption("model_components_as_modules",
bool,
description="""model discovered hardware components (CPUs, memory, drives,
controllers, NICs, ...) as NetBox modules instead of the deprecated inventory
items. Requires NetBox >= 4.3, on older versions inventory items are used""",
default_value=False),

ConfigOption("overwrite_power_supply_name",
bool,
description="""define if the name of the power supply discovered via check_redfish
Expand Down
Loading