Skip to content
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

Handle os-release without version or codename #370

Merged
merged 1 commit into from
Mar 25, 2025
Merged
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
21 changes: 12 additions & 9 deletions netbox_agent/misc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import suppress
from netbox_agent.config import netbox_instance as nb
from slugify import slugify
from shutil import which
Expand Down Expand Up @@ -28,15 +29,17 @@ def get_device_type(type):

def get_device_platform(device_platform):
if device_platform is None:
try:
linux_distribution = "{name} {version_id} {release_codename}".format(
**distro.os_release_info()
)

if not linux_distribution:
return None
except (ModuleNotFoundError, NameError, AttributeError):
return None
os_release = distro.os_release_info()
# Only `name` is a required field in os-release
for template in (
"{name} {version_id} {release_codename}",
"{name} {version_id}",
):
with suppress(KeyError):
linux_distribution = template.format(**os_release)
break
else:
linux_distribution = os_release["name"]
else:
linux_distribution = device_platform

Expand Down