2
0
mirror of https://opendev.org/x/pyghmi synced 2025-02-22 13:30:24 +00:00

Add node status checks to FPC sensors

In nextscale, the FPC has some potentially useful data
about node state with explanation.  Model those as
sensors that may appear in nodehealth

Change-Id: I9dd64740c4934d53d577defe9f3cc7b7a61dc499
This commit is contained in:
Jarrod Johnson 2016-05-12 15:10:49 -04:00
parent 941486e6f8
commit 66f50082c2

View File

@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pyghmi.constants as pygconst
import pyghmi.ipmi.sdr as sdr
import struct
@ -43,6 +44,20 @@ def fpc_read_psu_fan(ipmicmd, number):
return struct.unpack_from('<H', rsp[:2])[0]
def fpc_get_nodeperm(ipmicmd, number):
rsp = ipmicmd.xraw_command(netfn=0x32, command=0xa7, data=(number,))
perminfo = ord(rsp['data'][1])
health = pygconst.Health.Ok
states = []
if rsp['data'][4] in ('\x02', '\x03'):
states.append('Insufficient Power')
health = pygconst.Health.Failed
if perminfo & 0x40:
states.append('Node Fault')
health = pygconst.Health.Failed
return (health, states)
def fpc_read_powerbank(ipmicmd):
rsp = ipmicmd.xraw_command(netfn=0x32, command=0xa2)
return struct.unpack_from('<H', rsp['data'][3:])[0]
@ -75,6 +90,13 @@ fpc_sensors = {
'units': 'W',
'provider': fpc_read_powerbank,
},
'Node Power Permission': {
'type': 'Management Subsystem Health',
'returns': 'dict',
'units': None,
'provider': fpc_get_nodeperm,
'elements': 12,
},
}
@ -106,6 +128,8 @@ def get_sensor_descriptions():
def get_sensor_reading(name, ipmicmd):
value = None
sensor = None
health = pygconst.Health.Ok
states = []
if name in fpc_sensors and 'elements' not in fpc_sensors[name]:
sensor = fpc_sensors[name]
value = sensor['provider'](ipmicmd)
@ -114,11 +138,14 @@ def get_sensor_reading(name, ipmicmd):
idx = int(idx)
if bname in fpc_sensors and idx <= fpc_sensors[bname]['elements']:
sensor = fpc_sensors[bname]
value = sensor['provider'](ipmicmd, idx)
if 'returns' in sensor:
health, states = sensor['provider'](ipmicmd, idx)
else:
value = sensor['provider'](ipmicmd, idx)
if sensor is not None:
return sdr.SensorReading({'name': name, 'imprecision': None,
'value': value, 'states': [],
'state_ids': [], 'health': 0,
'value': value, 'states': states,
'state_ids': [], 'health': health,
'type': sensor['type']},
sensor['units'])
raise Exception('Sensor not found: ' + name)