def _switch(driver_info, enabled):
conn = _get_connection(driver_info)
relay_id = driver_info['relay_id']
def _wait_for_switch(mutable):
if mutable['retries'] > CONF.iboot.max_retry:
LOG.warning(
'Reached maximum number of attempts (%(attempts)d) to set '
'power state for node %(node)s to "%(op)s"',
{'attempts': mutable['retries'], 'node': driver_info['uuid'],
'op': states.POWER_ON if enabled else states.POWER_OFF})
raise loopingcall.LoopingCallDone()
try:
mutable['retries'] += 1
mutable['response'] = conn.switch(relay_id, enabled)
if mutable['response']:
raise loopingcall.LoopingCallDone()
except (TypeError, IndexError):
LOG.warning("Cannot call set power state for node '%(node)s' "
"at relay '%(relay)s'. iBoot switch() failed.",
{'node': driver_info['uuid'], 'relay': relay_id})
mutable = {'response': False, 'retries': 0}
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_switch,
mutable)
timer.start(interval=CONF.iboot.retry_interval).wait()
return mutable['response']
评论列表
文章目录