Refactor oemmap lookup
Previously, looking up an unknown OEM resulted in an exception being logged: exception while get_oem_handler, oemid:{'device_id': 32, 'device_revision': 1, 'manufacturer_id': 10876, 'product_id': 2414, 'firmware_version': '1.73'} Traceback (most recent call last): File "/omd/sites/plutex/local/lib/python3/pyghmi/ipmi/oem/lookup.py", line 43, in get_oem_handler return (oemmap[oemid['manufacturer_id']].OEMHandler(oemid, KeyError: 10876 So while I was at it, I also reduced duplicate code. Signed-off-by: Jan-Philipp Litza <jpl@plutex.de> Change-Id: Ib2483aeb3f92bcafbaa877eb1c0318a385f97474
This commit is contained in:
parent
3606780826
commit
e2b2f6806b
@ -33,18 +33,16 @@ oemmap = {
|
||||
|
||||
|
||||
def get_oem_handler(oemid, ipmicmd, *args):
|
||||
try:
|
||||
# first try to find with composite key manufacturer_id.product_id,
|
||||
# if found return directly
|
||||
# then try to find with manufacturer_id
|
||||
item = '{}.{}'.format(oemid['manufacturer_id'], oemid['product_id'])
|
||||
for item in (
|
||||
'{}.{}'.format(oemid['manufacturer_id'], oemid['product_id']),
|
||||
oemid['manufacturer_id'],
|
||||
):
|
||||
if item in oemmap:
|
||||
return (oemmap[item].OEMHandler(oemid, ipmicmd, *args), True)
|
||||
return (oemmap[oemid['manufacturer_id']].OEMHandler(oemid,
|
||||
ipmicmd, *args), True)
|
||||
except KeyError:
|
||||
logger.exception(
|
||||
'exception while get_oem_handler, oemid:{0}'.format(oemid))
|
||||
else:
|
||||
return generic.OEMHandler(oemid, ipmicmd, *args), False
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user