2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-12-25 12:41:39 +00:00

Fix power off detection

This commit is contained in:
Amanda Duffy 2017-05-02 15:30:39 -04:00
parent 443b678d8a
commit f4c191c280

View File

@ -651,11 +651,7 @@ def conserver_command(filehandle, localcommand):
else:
print("Unknown power state.]\r")
global powerstate
powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value']
powertime = time.time()
if powerstate == 'off':
sys.stdout.write("\r\n[powered off]\r\n")
check_power_state()
elif localcommand[0] == '?':
print("help]\r")
@ -765,6 +761,25 @@ elif shellargs:
powerstate = None
powertime = None
def check_power_state():
global powerstate, powertime
for rsp in session.read('/nodes/' + consolename + '/power/state'):
if type(rsp) == dict and 'state' in rsp:
powerstate = rsp['state']['value']
powertime = time.time()
if powerstate == 'off':
sys.stdout.write("\r\n[powered off]\r\n")
elif type(rsp) == dict and '_requestdone' in rsp:
break
elif type(rsp) == dict:
updatestatus(rsp)
else:
sys.stdout.write(rsp)
sys.stdout.flush()
while inconsole or not doexit:
if inconsole:
rdylist, _, _ = select.select(
@ -819,10 +834,8 @@ while inconsole or not doexit:
if myinput:
tlvdata.send(session.connection, myinput)
if powerstate is None or powertime < time.time() - 60: # Check powerstate every 60 seconds
powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value']
powertime = time.time()
if powerstate == 'off':
sys.stdout.write("\r\n[powered off]\r\n")
check_power_state()
else:
currcommand = prompt()
try: