2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-02-27 07:41:13 +00:00

Add power off detection

This commit is contained in:
Amanda Duffy 2017-05-02 14:54:18 -04:00
parent d79e117c55
commit 443b678d8a

View File

@ -576,7 +576,7 @@ def conserver_command(filehandle, localcommand):
tlvdata.send(session.connection, {'operation': 'break',
'path': currconsole})
print("break sent]\r")
elif localcommand[0] == 'p': # print
elif localcommand[0] == 'p': # power
cmdlen += 1
localcommand = get_command_bytes(filehandle, localcommand, cmdlen)
@ -651,6 +651,12 @@ 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")
elif localcommand[0] == '?':
print("help]\r")
print(". disconnect\r")
@ -757,6 +763,8 @@ elif shellargs:
do_command(command, netserver)
quitconfetty(fullexit=True, fixterm=False)
powerstate = None
powertime = None
while inconsole or not doexit:
if inconsole:
rdylist, _, _ = select.select(
@ -810,6 +818,11 @@ while inconsole or not doexit:
myinput = check_escape_seq(myinput, fh)
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")
else:
currcommand = prompt()
try: