diff options
author | Chris Krelle <nobodycam@gmail.com> | 2014-05-29 14:22:06 -0500 |
---|---|---|
committer | Chris Krelle <nobodycam@gmail.com> | 2014-06-16 07:09:51 -0700 |
commit | 53640a873000a12eebd627df555e7b2b0a27f659 (patch) | |
tree | 2c246e956a8c07b35caa147b96cb49680e8685eb /ironic/drivers/modules/ipmitool.py | |
parent | 12ef2bc621f6c713524d54a157bc3fe216b04977 (diff) | |
download | ironic-53640a873000a12eebd627df555e7b2b0a27f659.tar.gz |
Enforce a minimum time between all IPMI commands
This patch enforces the min_command_interval option, which was added in
the previous patch, to ensure that any given BMC is never "poked" more
frequently than this interval, regardless of the calling method.
Closes-Bug: #1320513
Change-Id: Id3849aadf3908133a92157b3e96dd752610533e9
Diffstat (limited to 'ironic/drivers/modules/ipmitool.py')
-rw-r--r-- | ironic/drivers/modules/ipmitool.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ironic/drivers/modules/ipmitool.py b/ironic/drivers/modules/ipmitool.py index 818e855ac..29f1242e4 100644 --- a/ironic/drivers/modules/ipmitool.py +++ b/ironic/drivers/modules/ipmitool.py @@ -33,6 +33,7 @@ import contextlib import os import stat import tempfile +import time from oslo.config import cfg @@ -60,7 +61,7 @@ LOG = logging.getLogger(__name__) VALID_BOOT_DEVICES = ['pxe', 'disk', 'safe', 'cdrom', 'bios'] VALID_PRIV_LEVELS = ['ADMINISTRATOR', 'CALLBACK', 'OPERATOR', 'USER'] - +LAST_CMD_TIME = {} TIMING_SUPPORT = None @@ -210,14 +211,20 @@ def _exec_ipmitool(driver_info, command): # 'ipmitool' command will prompt password if there is no '-f' option, # we set it to '\0' to write a password file to support empty password - with _make_password_file(driver_info['password'] or '\0') as pw_file: args.append('-f') args.append(pw_file) args.extend(command.split(" ")) - out, err = utils.execute(*args) - LOG.debug("ipmitool stdout: '%(out)s', stderr: '%(err)s'", - {'out': out, 'err': err}) + # NOTE(deva): ensure that no communications are sent to a BMC more + # often than once every min_command_interval seconds. + time_till_next_poll = CONF.ipmi.min_command_interval - ( + time.time() - LAST_CMD_TIME.get(driver_info['address'], 0)) + if time_till_next_poll > 0: + time.sleep(time_till_next_poll) + try: + out, err = utils.execute(*args) + finally: + LAST_CMD_TIME[driver_info['address']] = time.time() return out, err |