#!/usr/bin/env python3
import pexpect
import sys
import os
import time

# propagate env vars for configuration
child = pexpect.spawn('./ipmi_helper.sh console', env=os.environ)
child.logfile = sys.stdout.buffer

child.expect('SOL Session operational', timeout=15)

try:
    # server firmware is done initing and trying to boot
    child.expect('Booting', timeout=120)

    # Grub lists Nautilus option
    child.expect('Nautilus', timeout=120)

    # grub wants our input
    child.expect('automatically', timeout=5)

    # send down-arrow
    for _ in range(7):
        csi = '\x1b['
        down = f'{csi}B'
        child.send(down)
        print('down')
        time.sleep(1)

    # press enter
    # sometimes the first \n doesn't take
    for _ in range(3):
        child.send('\r\n')
        print('enter')
        time.sleep(1)

    index = child.expect(['app_main done', 'HALTING', 'EXCEPTION', 'root-shell>', 'TEST: Shutting down'], timeout=None)
except KeyboardInterrupt:
    print('keyboard interrupt')
finally:
    for _ in range(3):
        child.send('\r\n')
        print('enter')
        time.sleep(1)
    
    # exits the SOL session
    child.send('\n')
    child.send('@.')
    print('quit')

child.wait()

sys.exit(index)

#!/usr/bin/env python3
import pexpect
import sys
import os
import time

# propagate env vars for configuration
child = pexpect.spawn('./ipmi_helper.sh console', env=os.environ)
child.logfile = sys.stdout.buffer

child.expect('SOL Session operational', timeout=15)

try:
    # server firmware is done initing and trying to boot
    child.expect('Booting', timeout=120)

    # Grub lists Nautilus option
    child.expect('Nautilus', timeout=120)

    # grub wants our input
    child.expect('automatically', timeout=5)

    # send down-arrow
    for _ in range(7):
        csi = '\x1b['
        down = f'{csi}B'
        child.send(down)
        print('down')
        time.sleep(1)

    # press enter
    # sometimes the first \n doesn't take
    for _ in range(3):
        child.send('\r\n')
        print('enter')
        time.sleep(1)

    index = child.expect(['app_main done', 'HALTING', 'EXCEPTION', 'root-shell>', 'TEST: Shutting down'], timeout=None)
except KeyboardInterrupt:
    print('keyboard interrupt')
finally:
    for _ in range(3):
        child.send('\r\n')
        print('enter')
        time.sleep(1)
    
    # exits the SOL session
    child.send('\n')
    child.send('@.')
    print('quit')

child.wait()

sys.exit(index)

#!/usr/bin/env python3 # propagate env vars for configuration # server firmware is done initing and trying to boot # Grub lists Nautilus option # grub wants our input # send down-arrow # press enter # sometimes the first \n doesn't take # exits the SOL session