IPMI driver improvements and bug fixes.

Change-Id: I3d6d27549198b95cc1b5f038ecdc1be8efe651c1
This commit is contained in:
Swann Croiset 2013-06-27 12:03:36 +02:00 committed by François Rossigneux
parent 5fab1557ef
commit fdb77c07e7
3 changed files with 38 additions and 39 deletions

View File

@ -33,9 +33,9 @@ driver = Dummy
[Wattmeter 4] [Wattmeter 4]
probes = ['E'] probes = ['E']
driver = Ipmi driver = Ipmi
parameters = {'cache_dir': '/tmp/kwapi-ipmi', 'interface':'lanplus', 'host':'192.168.0.70', 'password':'secret'} parameters = {'interface':'lanplus', 'host':'192.168.0.70', 'username':'user', 'password':'secret', 'sensor':'Power'}
[Wattmeter 5] [Wattmeter 5]
probes = ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24'] probes = ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24']
driver = Eaton driver = Eaton
parameters = {'ip': '140.77.13.119', 'user': 'SNMPv3 User 1'} parameters = {'ip': '192.168.0.71', 'user': 'SNMPv3 User 1'}

View File

@ -14,11 +14,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import errno
import os
import subprocess import subprocess
import time import time
import uuid
from kwapi.openstack.common import log from kwapi.openstack.common import log
from driver import Driver from driver import Driver
@ -35,7 +32,7 @@ class Ipmi(Driver):
Keyword arguments: Keyword arguments:
probe_ids -- list containing the probes IDs probe_ids -- list containing the probes IDs
(a wattmeter monitor sometimes several probes) (a wattmeter monitor sometimes several probes)
kwargs -- keywords (cache_directory, interface, host, username, kwargs -- keywords (interface, host, username,
password) defining the IPMI parameters password) defining the IPMI parameters
""" """
@ -43,33 +40,28 @@ class Ipmi(Driver):
def run(self): def run(self):
"""Starts the driver thread.""" """Starts the driver thread."""
measurements = {} if self.set_sensor_name():
while not self.stop_request_pending(): measurements = {}
watts = self.get_watts() while not self.stop_request_pending():
if watts is not None: watts = self.get_watts()
measurements['w'] = watts if watts is not None:
self.send_measurements(self.probe_ids[0], measurements) measurements['w'] = watts
time.sleep(1) self.send_measurements(self.probe_ids[0], measurements)
time.sleep(1)
def get_cache_filename(self): def set_sensor_name(self):
"""Returns the cache filename.""" """Deduces the sensors name from the IPMI listing, or loads it from
return self.kwargs.get('cache_dir') + '/' + \ the config file. Returns True if the sensor name is found.
str(uuid.uuid5(uuid.NAMESPACE_DNS, self.probe_ids[0]))
def create_cache(self): """
"""Creates the cache file.""" names = []
cache_file = self.get_cache_filename() # Listing
try:
os.makedirs(self.kwargs.get('cache_dir'))
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
command = 'ipmitool ' command = 'ipmitool '
command += '-I ' + self.kwargs.get('interface') + ' ' command += '-I ' + self.kwargs.get('interface') + ' '
command += '-H ' + self.kwargs.get('host') + ' ' command += '-H ' + self.kwargs.get('host') + ' '
command += '-U ' + self.kwargs.get('username', 'root') + ' ' command += '-U ' + self.kwargs.get('username') + ' '
command += '-P ' + self.kwargs.get('password') + ' ' command += '-P ' + self.kwargs.get('password') + ' '
command += 'sdr dump ' + cache_file command += 'sensor'
child = subprocess.Popen(command, child = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -77,26 +69,32 @@ class Ipmi(Driver):
) )
output, error = child.communicate() output, error = child.communicate()
if child.returncode == 0: if child.returncode == 0:
return cache_file for line in output.split('\n'):
if 'Watts' in line:
names.append(line.split('|')[0].strip())
if not names:
LOG.error('IPMI card does not support wattmeter features')
return False
elif not self.kwargs.get('sensor') and len(names) == 1:
self.kwargs['sensor'] = names[0]
return True
elif not self.kwargs.get('sensor') in names:
LOG.error('Sensor name not found')
return False
else:
return True
else: else:
LOG.error('Failed to download cache from probe %s: %s' LOG.error('Failed to list the sensors')
% (self.probe_ids[0], error))
return None return None
def get_watts(self): def get_watts(self):
"""Returns the power consumption."""
cache_file = self.get_cache_filename()
# Try to create cache (not a problem if this fails)
if not os.path.exists(cache_file):
self.create_cache()
# Get power consumption # Get power consumption
command = 'ipmitool ' command = 'ipmitool '
command += '-S ' + cache_file + ' '
command += '-I ' + self.kwargs.get('interface') + ' ' command += '-I ' + self.kwargs.get('interface') + ' '
command += '-H ' + self.kwargs.get('host') + ' ' command += '-H ' + self.kwargs.get('host') + ' '
command += '-U ' + self.kwargs.get('username', 'root') + ' ' command += '-U ' + self.kwargs.get('username') + ' '
command += '-P ' + self.kwargs.get('password') + ' ' command += '-P ' + self.kwargs.get('password') + ' '
command += 'sensor reading "System Level"' command += 'sensor reading "' + self.kwargs.get('sensor') + '"'
child = subprocess.Popen(command, child = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -105,7 +103,7 @@ class Ipmi(Driver):
output, error = child.communicate() output, error = child.communicate()
if child.returncode == 0: if child.returncode == 0:
try: try:
return int(output.split('|')[1]) return float(output.split('|')[1])
except ValueError: except ValueError:
LOG.error('Received data from probe %s are invalid: %s' LOG.error('Received data from probe %s are invalid: %s'
% (self.probe_ids[0], output)) % (self.probe_ids[0], output))

View File

@ -1,3 +1,4 @@
eventlet
flask flask
iso8601 iso8601
oslo.config oslo.config