2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-21 17:11:58 +00:00

Merge pull request #78 from aduffy19/power-off-detection

Add power off detection
This commit is contained in:
Jarrod Johnson 2017-05-02 15:35:39 -04:00 committed by GitHub
commit 168f60de06

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,8 @@ def conserver_command(filehandle, localcommand):
else:
print("Unknown power state.]\r")
check_power_state()
elif localcommand[0] == '?':
print("help]\r")
print(". disconnect\r")
@ -757,6 +759,27 @@ elif shellargs:
do_command(command, netserver)
quitconfetty(fullexit=True, fixterm=False)
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(
@ -810,6 +833,9 @@ 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
check_power_state()
else:
currcommand = prompt()
try: