add functions to ignore serial number in case the serial didn't come from manafactures

This commit is contained in:
congnv1 2022-09-09 21:03:46 +07:00
commit ee3ebae6e4
2 changed files with 15 additions and 1 deletions

View file

@ -47,6 +47,8 @@ def get_config():
help="The Unit location of server on rack")
p.add_argument('--rack_face', default=None,
help="Front/Rear of server on rack")
p.add_argument('--device.ignore_serial_number', default=[],
help="Ignore serial number and use FRU instead serial number from dmidecode")
p.add_argument('--device.platform', default=None,
help='Override device platform. Here we use OS distribution.')
p.add_argument('--device.tags', default=r'',

View file

@ -1,6 +1,8 @@
from netbox_agent.location import Slot
from netbox_agent.server import ServerBase
from netbox_agent.misc import is_tool
from netbox_agent.config import config
import subprocess
class SupermicroHost(ServerBase):
"""
@ -48,6 +50,10 @@ class SupermicroHost(ServerBase):
def get_service_tag(self):
if self.is_blade():
return self.baseboard[0]['Serial Number'].strip()
# some servers model or seller set Hardware system serial as ["123456789", "0123456789"] instead default from manufacture
# in this case, we'll read from FRU instead
if self.system[0]['Serial Number'].strip() in config.device.ignore_serial_number:
return self.get_fru().strip()
return self.system[0]['Serial Number'].strip()
def get_product_name(self):
@ -77,3 +83,9 @@ class SupermicroHost(ServerBase):
I only know on model of slot GPU extension card that.
"""
raise NotImplementedError
def get_fru(self):
if not is_tool('IPMICFG'):
logging.error('IPMICFG does not seem to be present on your system. Add it your path or '
'check the compatibility of this project with your distro.')
sys.exit(1)
return subprocess.getoutput('IPMICFG -fru PS')