feat: auto-detect device platform

this platform module still works for python3.6 we use.

Signed-off-by: Cyril Levis <git@levis.name>
This commit is contained in:
Cyril Levis 2022-03-31 17:08:16 +02:00
parent 2a4f24f00a
commit cf2cc54da4
No known key found for this signature in database
GPG key ID: 6DB88737C11F5A48

View file

@ -31,19 +31,24 @@ def get_device_type(type):
def get_device_platform(config):
if config.device.platform is None:
return None
try:
import platform
device_platform = nb.dcim.platforms.get(
name=config.device.platform
)
linux_distribution = " ".join(platform.linux_distribution())
if not linux_distribution:
return None
except ModuleNotFoundError:
return None
else:
linux_distribution = config.device.platform
device_platform = nb.dcim.platforms.get(name=linux_distribution)
if device_platform is None:
device_platform = nb.dcim.platforms.create(
name=config.device.platform,
slug=slugify(config.device.platform)
name=linux_distribution, slug=slugify(linux_distribution)
)
return device_platform
def get_vendor(name):
vendors = {
'PERC': 'Dell',