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):
|
def get_device_platform(config):
|
||||||
if config.device.platform is None:
|
if config.device.platform is None:
|
||||||
return None
|
try:
|
||||||
|
import platform
|
||||||
|
|
||||||
device_platform = nb.dcim.platforms.get(
|
linux_distribution = " ".join(platform.linux_distribution())
|
||||||
name=config.device.platform
|
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:
|
if device_platform is None:
|
||||||
device_platform = nb.dcim.platforms.create(
|
device_platform = nb.dcim.platforms.create(
|
||||||
name=config.device.platform,
|
name=linux_distribution, slug=slugify(linux_distribution)
|
||||||
slug=slugify(config.device.platform)
|
|
||||||
)
|
)
|
||||||
return device_platform
|
return device_platform
|
||||||
|
|
||||||
|
|
||||||
def get_vendor(name):
|
def get_vendor(name):
|
||||||
vendors = {
|
vendors = {
|
||||||
'PERC': 'Dell',
|
'PERC': 'Dell',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue