aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-08-22 20:19:31 +0200
committerGuido Günther <agx@sigxcpu.org>2017-08-22 20:22:05 +0200
commit6a1b1813733b1f21094d55ecdf48fcfe2c5950ce (patch)
tree42290eb4b4130f189f6ad6ca1747a10c8cbea793
parente7e611f00475925e6691f3302648cdda1b48cb57 (diff)
Handle new power state names
Foreman changed power state names in 1.15+.
-rw-r--r--foremanhost.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/foremanhost.py b/foremanhost.py
index 980743f..0823a06 100644
--- a/foremanhost.py
+++ b/foremanhost.py
@@ -319,13 +319,14 @@ def set_host_power(hid, state):
return json.loads(ret['text'])['power']
-def wait_host_power(hid, state, timeout):
+def wait_host_power(hid, states, timeout):
while timeout > 0:
timeout -= 2
time.sleep(2)
cur_state = get_host_power(hid)
- if cur_state == state:
- return state
+ module.debug("cur_state: %s, want: %s" % (cur_state, states))
+ if cur_state in states:
+ return cur_state
return None
@@ -520,14 +521,15 @@ def ensure_power_state(hid, state, power_timeout):
if state == 'present':
state = 'poweredOn'
if cur_state != state:
- waitfor, action = ('poweredOff', 'stop') if cur_state == 'poweredOn' else ('poweredOn', 'start')
+ waitfor, action = (['poweredOff', 'off'], 'stop') if cur_state in ['poweredOn', 'running'] else (['poweredOn', 'running'], 'start')
+ module.debug("cur_state: %s, waitfor: %s, action: %s" % (cur_state, waitfor, action))
if set_host_power(hid, action):
new_state = wait_host_power(hid, waitfor, power_timeout)
if new_state:
ret = new_state
else:
module.fail_json(
- msg="Host did not enter power state %s in %d seconds" % (waitfor, power_timeout)
+ msg="Host did not enter power state %s in %d seconds" % (waitfor[0], power_timeout)
)
changed = True
else: