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:
parent
2a4f24f00a
commit
cf2cc54da4
1 changed files with 12 additions and 7 deletions
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue