2
0
mirror of https://opendev.org/x/pyghmi synced 2026-03-29 06:13:30 +00:00

Enhance IpmiException to carry IPMI codenumber

In some cases, an exception warrants a different handling
depending on the code of the error.  Have the exception
carry the code up for calling code to make a decision.

Change-Id: Ie7e134d3a7d99eaa1ec3a82c6f39e82dc4422ca7
This commit is contained in:
Jarrod Johnon
2015-01-15 14:03:12 -05:00
parent acd193ce6b
commit f93b90f2a5
2 changed files with 6 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corporation
# Copyright 2015 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,7 +24,9 @@ class PyghmiException(Exception):
class IpmiException(PyghmiException):
pass
def __init__(self, text='', code=0):
super(IpmiException, self).__init__(text)
self.ipmicode = code
class InvalidParameterValue(PyghmiException):

View File

@@ -1,6 +1,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corporation
# Copyright 2015 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -363,7 +364,7 @@ class Command(object):
if self._sdr.sensors[sensor].name == sensorname:
rsp = self.raw_command(command=0x2d, netfn=4, data=(sensor,))
if 'error' in rsp:
raise Exception(rsp['error'])
raise exc.IpmiException(rsp['error'], rsp['code'])
return self._sdr.sensors[sensor].decode_sensor_reading(
rsp['data'])
raise Exception('Sensor not found: ' + sensorname)