IPMI driver (bug fixes).
Change-Id: Iceb368e6882cc34029e9488bc3425f1321e62903
This commit is contained in:
parent
5e8395e7ec
commit
ecdbb27662
|
@ -14,6 +14,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import errno
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import uuid
|
||||
|
@ -35,32 +37,47 @@ class Ipmi(Driver):
|
|||
|
||||
"""
|
||||
Driver.__init__(self, probe_ids, kwargs)
|
||||
self.cache_file = kwargs.get('cache_directory') + '/' +
|
||||
str(uuid.uuid5(uuid.NAMESPACE_DNS, probe_ids[0]))
|
||||
command = 'ipmitool '
|
||||
command += '-I ' + kwargs.get('interface') + ' '
|
||||
command += '-H ' + kwargs.get('host') + ' '
|
||||
command += '-U ' + kwargs.get('username', 'root') + ' '
|
||||
command += '-P ' + kwargs.get('password') + ' '
|
||||
command += 'sdr dump ' + cache_file
|
||||
output, error = subprocess.Popen(command,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
).communicate()
|
||||
|
||||
def run(self):
|
||||
"""Starts the driver thread."""
|
||||
self.create_cache()
|
||||
while not self.stop_request_pending():
|
||||
measurements = {}
|
||||
measurements['w'] = self.get_watts()
|
||||
self.send_measurements(self.probe_ids[0], measurements)
|
||||
time.sleep(1)
|
||||
|
||||
def get_cache_filename(self):
|
||||
"""Returns the cache filename."""
|
||||
return self.kwargs.get('cache_dir') + '/' + \
|
||||
str(uuid.uuid5(uuid.NAMESPACE_DNS, self.probe_ids[0]))
|
||||
|
||||
def create_cache(self):
|
||||
"""Creates the cache file."""
|
||||
try:
|
||||
os.makedirs(self.kwargs.get('cache_dir'))
|
||||
except OSError as exception:
|
||||
if exception.errno != errno.EEXIST:
|
||||
raise
|
||||
command = 'ipmitool '
|
||||
command += '-I ' + self.kwargs.get('interface') + ' '
|
||||
command += '-H ' + self.kwargs.get('host') + ' '
|
||||
command += '-U ' + self.kwargs.get('username', 'root') + ' '
|
||||
command += '-P ' + self.kwargs.get('password') + ' '
|
||||
command += 'sdr dump ' + self.get_cache_filename()
|
||||
output, error = subprocess.Popen(command,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
).communicate()
|
||||
|
||||
def get_watts(self):
|
||||
"""Returns the power consumption."""
|
||||
cache_file = self.get_cache_filename()
|
||||
if not os.path.exists(cache_file):
|
||||
self.create_cache()
|
||||
command = 'ipmitool '
|
||||
command += '-S ' + self.cache_file + ' '
|
||||
command += '-S ' + cache_file + ' '
|
||||
command += '-I ' + self.kwargs.get('interface') + ' '
|
||||
command += '-H ' + self.kwargs.get('host') + ' '
|
||||
command += '-U ' + self.kwargs.get('username', 'root') + ' '
|
||||
|
|
Loading…
Reference in New Issue