Skip to content

Commit

Permalink
netbox: pass software version from platform name (#50)
Browse files Browse the repository at this point in the history
Pass the platform name to hw.sw_version. The platform is a netbox enitity used to desribe software running on a network appliance and associate that with the device manufacturer:

https://demo.netbox.dev/static/docs/models/dcim/platform/
  • Loading branch information
azryve authored Jul 1, 2024
1 parent f119543 commit f1540e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 3 additions & 6 deletions annet/adapters/netbox/common/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
}


def _vendor_to_hw(vendor):
return HardwareView(_VENDORS.get(vendor.lower(), vendor), None)


def get_hw(manufacturer: str, model: str):
def get_hw(manufacturer: str, model: str, platform_name: str):
# by some reason Netbox calls Mellanox SN as MSN, so we fix them here
if manufacturer == "Mellanox" and model.startswith("MSN"):
model = model.replace("MSN", "SN", 1)
hw = _vendor_to_hw(manufacturer + " " + model)
vendor = manufacturer + " " + model
hw = HardwareView(_VENDORS.get(vendor.lower(), vendor), platform_name)
if not hw:
raise ValueError(f"unsupported manufacturer {manufacturer}")
return hw
Expand Down
5 changes: 4 additions & 1 deletion annet/adapters/netbox/v24/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def extend_device(
) -> models.NetboxDevice:
manufacturer = device.device_type.manufacturer.name
model = device.device_type.model
platform_name = ""
if device.platform:
platform_name = device.platform.name

return models.NetboxDevice(
url=device.url,
Expand Down Expand Up @@ -71,7 +74,7 @@ def extend_device(

fqdn=device.name,
hostname=device.name,
hw=get_hw(manufacturer, model),
hw=get_hw(manufacturer, model, platform_name),
breed=get_breed(manufacturer, model),
interfaces=[],
neighbours_ids=[],
Expand Down
4 changes: 4 additions & 0 deletions annet/adapters/netbox/v37/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def extend_device(
neighbours: Optional[List[models.NetboxDevice]],
storage: Storage,
) -> models.NetboxDevice:
platform_name: str = ""
if device.platform:
platform_name = device.platform.name
return extend_device_base(
device=device,
interfaces=interfaces,
Expand All @@ -52,6 +55,7 @@ def extend_device(
hw=get_hw(
device.device_type.manufacturer.name,
device.device_type.model,
platform_name,
),
neighbours=neighbours,
storage=storage,
Expand Down

0 comments on commit f1540e4

Please sign in to comment.