mirror of
https://opendev.org/x/pyghmi
synced 2025-01-15 04:07:48 +00:00
Add 'get_sensor_data' to Command class
Have Command class provide access to the sensor data as enabled by the SDR commit. Change-Id: I2eede764597cff74409370230cc5d3f120c4ed65
This commit is contained in:
parent
3a4338365b
commit
fe7539ab83
@ -57,6 +57,9 @@ def docommand(result, ipmisession):
|
||||
print ipmisession.set_bootdev(args[0])
|
||||
else:
|
||||
print ipmisession.get_bootdev()
|
||||
elif cmmand == 'sensors':
|
||||
for reading in ipmisession.get_sensor_data():
|
||||
print repr(reading)
|
||||
elif cmmand == 'raw':
|
||||
print ipmisession.raw_command(netfn=int(args[0]),
|
||||
command=int(args[1]),
|
||||
|
@ -18,6 +18,7 @@
|
||||
import pyghmi.exceptions as exc
|
||||
|
||||
from pyghmi.ipmi.private import session
|
||||
import pyghmi.ipmi.sdr as sdr
|
||||
|
||||
|
||||
boot_devices = {
|
||||
@ -289,3 +290,21 @@ class Command(object):
|
||||
assert(response['command'] == 1 and response['netfn'] == 1)
|
||||
self.powerstate = 'on' if (response['data'][0] & 1) else 'off'
|
||||
return {'powerstate': self.powerstate}
|
||||
|
||||
def get_sensor_data(self):
|
||||
"""Get sensor reading objects
|
||||
|
||||
Iterates sensor reading objects pertaining to the currently
|
||||
managed BMC.
|
||||
|
||||
:returns: Iterator of sdr.SensorReading objects
|
||||
"""
|
||||
if '_sdr' not in self.__dict__:
|
||||
self._sdr = sdr.SDR(self)
|
||||
for sensor in self._sdr.get_sensor_numbers():
|
||||
rsp = self.raw_command(command=0x2d, netfn=4, data=(sensor,))
|
||||
if 'error' in rsp:
|
||||
if rsp['code'] == 203: # Sensor does not exist, optional dev
|
||||
continue
|
||||
raise Exception(rsp['error'])
|
||||
yield self._sdr.sensors[sensor].decode_sensor_reading(rsp['data'])
|
||||
|
@ -31,7 +31,6 @@
|
||||
import math
|
||||
import pyghmi.constants as const
|
||||
import pyghmi.exceptions as exc
|
||||
import pyghmi.ipmi.command as ipmicmd
|
||||
import pyghmi.ipmi.private.constants as ipmiconstants
|
||||
import struct
|
||||
|
||||
@ -188,18 +187,20 @@ class SensorReading(object):
|
||||
def __init__(self, reading, suffix):
|
||||
self.health = const.Health.Ok
|
||||
self.type = reading['type']
|
||||
if 'health' in reading:
|
||||
self.value = None
|
||||
self.imprecision = None
|
||||
self.states = ()
|
||||
try:
|
||||
self.health = reading['health']
|
||||
if 'value' in reading:
|
||||
self.value = reading['value']
|
||||
else:
|
||||
self.value = None
|
||||
self.states = reading['states']
|
||||
self.states = reading['states']
|
||||
self.imprecision = reading['imprecision']
|
||||
except KeyError:
|
||||
pass
|
||||
if 'unavailable' in reading:
|
||||
self.unavailable = 1
|
||||
self.units = suffix
|
||||
self.name = reading['name']
|
||||
self.imprecision = reading['imprecision']
|
||||
|
||||
def __repr__(self):
|
||||
return repr({
|
||||
@ -410,7 +411,7 @@ class SDREntry(object):
|
||||
if reading[2] & 0b100000:
|
||||
output['health'] |= const.Health.Failed
|
||||
output['states'].append(upper + " non-recoverable threshold")
|
||||
return SensorReading(output, self.unit_suffix)
|
||||
return SensorReading(output, self.unit_suffix)
|
||||
|
||||
def decode_value(self, value):
|
||||
# Take the input value and return meaningful value
|
||||
@ -585,6 +586,7 @@ class SDR(object):
|
||||
|
||||
if __name__ == "__main__": # test code
|
||||
import os
|
||||
import pyghmi.ipmi.command as ipmicmd
|
||||
import sys
|
||||
password = os.environ['IPMIPASSWORD']
|
||||
bmc = sys.argv[1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user