From aeb0b5bb240a9a7f644c6f43a380a22c02857083 Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Tue, 8 Nov 2016 15:15:14 -0500 Subject: [PATCH 1/4] Provide a command, nodeboot, to combine setboot and power commands. --- confluent_client/bin/nodeboot.py | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 confluent_client/bin/nodeboot.py diff --git a/confluent_client/bin/nodeboot.py b/confluent_client/bin/nodeboot.py new file mode 100644 index 00000000..9aa940a6 --- /dev/null +++ b/confluent_client/bin/nodeboot.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2015 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sys + +path = os.path.dirname(os.path.realpath(__file__)) +path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) +if path.startswith('/opt'): + sys.path.append(path) + +import confluent.client as client + +argparser = optparse.OptionParser() +argparser.add_option('-b', '--bios', dest='biosmode', + action='store_true', default=False, + help='Request BIOS style boot (rather than UEFI)') +argparser.add_option('-p', '--persist', dest='persist', action='store_true', + default=False, + help='Request the boot device be persistent rather than ' + 'one time') + +(options, args) = argparser.parse_args() + +try: + noderange = args[0] +except IndexError: + sys.stderr.write( + 'Usage: {0} [default|cd|network|setup|hd]\n'.format( + sys.argv[0])) + sys.exit(1) +bootdev = None +if len(sys.argv) > 2: + bootdev = sys.argv[2] + if bootdev in ('net', 'pxe'): + bootdev = 'network' +session = client.Command() +exitcode = 0 +if options.biosmode: + bootmode = 'bios' +else: + bootmode = 'uefi' + +rc = session.simple_noderange_command(noderange, '/boot/nextdevice', bootdev, + bootmode=bootmode, + persistent=options.persist) + +if rc: + sys.exit(rc) +else: + sys.exit(session.simple_noderange_command(noderange, '/power/state', 'boot')) \ No newline at end of file From bdde7e719d41246d00641163680181c8b7c19f40 Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Tue, 8 Nov 2016 15:15:14 -0500 Subject: [PATCH 2/4] Provide a command, nodeboot, to combine setboot and power commands. --- confluent_client/bin/nodeboot.py | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 confluent_client/bin/nodeboot.py diff --git a/confluent_client/bin/nodeboot.py b/confluent_client/bin/nodeboot.py new file mode 100644 index 00000000..9aa940a6 --- /dev/null +++ b/confluent_client/bin/nodeboot.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2015 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sys + +path = os.path.dirname(os.path.realpath(__file__)) +path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) +if path.startswith('/opt'): + sys.path.append(path) + +import confluent.client as client + +argparser = optparse.OptionParser() +argparser.add_option('-b', '--bios', dest='biosmode', + action='store_true', default=False, + help='Request BIOS style boot (rather than UEFI)') +argparser.add_option('-p', '--persist', dest='persist', action='store_true', + default=False, + help='Request the boot device be persistent rather than ' + 'one time') + +(options, args) = argparser.parse_args() + +try: + noderange = args[0] +except IndexError: + sys.stderr.write( + 'Usage: {0} [default|cd|network|setup|hd]\n'.format( + sys.argv[0])) + sys.exit(1) +bootdev = None +if len(sys.argv) > 2: + bootdev = sys.argv[2] + if bootdev in ('net', 'pxe'): + bootdev = 'network' +session = client.Command() +exitcode = 0 +if options.biosmode: + bootmode = 'bios' +else: + bootmode = 'uefi' + +rc = session.simple_noderange_command(noderange, '/boot/nextdevice', bootdev, + bootmode=bootmode, + persistent=options.persist) + +if rc: + sys.exit(rc) +else: + sys.exit(session.simple_noderange_command(noderange, '/power/state', 'boot')) \ No newline at end of file From fdf74dbf11dfc676cb042ce1f8bec15defef5035 Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Fri, 27 Jan 2017 13:44:12 -0500 Subject: [PATCH 3/4] Add power options for console commands --- confluent_client/bin/confetty | 103 ++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 10 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index fe65742f..f471d57f 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -542,7 +542,7 @@ def get_session_node(shellargs): return None -def conserver_command(filehandle, command): +def conserver_command(filehandle, localcommand): # x - conserver has that as 'show baud', I am inclined to replace that with # 'request exclusive' # b - conserver has that as 'broadcast message', I'm tempted to use that @@ -557,33 +557,116 @@ def conserver_command(filehandle, command): # d - down a console... never used this... # L - toggle logging # w - who is on console - while not command: - ready, _, _ = select.select((filehandle,), (), (), 1) - if ready: - command += filehandle.read() - if command[0] == '.': + + cmdlen = 1 + localcommand = get_command_bytes(filehandle, localcommand, cmdlen) + + if localcommand[0] == '.': print("disconnect]\r") quitconfetty(fullexit=consoleonly) - elif command[0] == 'o': + elif localcommand[0] == 'o': tlvdata.send(session.connection, {'operation': 'reopen', 'path': currconsole}) print('reopen]\r') - elif command[0] == 'b': + elif localcommand[0] == 'b': tlvdata.send(session.connection, {'operation': 'break', 'path': currconsole}) print("break sent]\r") - elif command[0] == '?': + elif localcommand[0] == 'p': # print + cmdlen += 1 + localcommand = get_command_bytes(filehandle, localcommand, cmdlen) + + if localcommand[1] == 'o': # off + print("powering off...") + session.simple_noderange_command(consolename, '/power/state', 'off') + print("complete]\r") + elif localcommand[1] == 's': # shutdown + print("shutting down...") + session.simple_noderange_command(consolename, '/power/state', 'shutdown') + print("complete]\r") + elif localcommand[1] == 'b': # boot + cmdlen += 1 + localcommand = get_command_bytes(filehandle, localcommand, cmdlen) + + if localcommand[2] == 's': # boot to setup + print("booting to setup...") + + bootmode = 'uefi' + bootdev = 'setup' + + rc = session.simple_noderange_command(consolename, '/boot/nextdevice', bootdev, bootmode=bootmode) + + if rc: + print("Error]\r") + else: + rc = session.simple_noderange_command(consolename, '/power/state', 'boot') + if rc: + print("Error]\r") + else: + print("complete]\r") + + elif localcommand[2] == 'n': # boot to network + print("booting to network...") + + bootmode = 'uefi' + bootdev = 'network' + + rc = session.simple_noderange_command(consolename, '/boot/nextdevice', bootdev, bootmode=bootmode) + + if rc: + print("Error]\r") + else: + rc = session.simple_noderange_command(consolename, '/power/state', 'boot') + + if rc: + print("Error]\r") + else: + print("complete]\r") + + elif localcommand[2] == '\x0d': # boot to default + print("booting to default...") + + bootmode = 'uefi' + bootdev = 'default' + + rc = session.simple_noderange_command(consolename, '/boot/nextdevice', bootdev, bootmode=bootmode) + + if rc: + print("Error]\r") + else: + rc = session.simple_noderange_command(consolename, '/power/state', 'boot') + + if rc: + print("Error]\r") + else: + print("complete]\r") + + else: + print("Unknown boot state.\r") + + else: + print("Unknown power state.\r") + + elif localcommand[0] == '?': print("help]\r") print(". disconnect\r") print("b break\r") print("o reopen\r") print(" abort command\r") - elif command[0] == '\x0d': + elif localcommand[0] == '\x0d': print("ignored]\r") else: # not a command at all.. print("unknown -- use '?']\r") +def get_command_bytes(filehandle, localcommand, cmdlen): + while len(localcommand) < cmdlen: + ready, _, _ = select.select((filehandle,), (), (), 1) + if ready: + localcommand += filehandle.read() + return localcommand + + def check_escape_seq(currinput, filehandle): while conserversequence.startswith(currinput): if currinput.startswith(conserversequence): # We have full sequence From 36bc81448ea9c0d76a87ba7c9f51b95b2baca2fd Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Fri, 27 Jan 2017 14:25:42 -0500 Subject: [PATCH 4/4] Fix missing ] and add entries to printed menu --- confluent_client/bin/confetty | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index f471d57f..4b34490f 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -642,16 +642,21 @@ def conserver_command(filehandle, localcommand): print("complete]\r") else: - print("Unknown boot state.\r") + print("Unknown boot state.]\r") else: - print("Unknown power state.\r") + print("Unknown power state.]\r") elif localcommand[0] == '?': print("help]\r") - print(". disconnect\r") - print("b break\r") - print("o reopen\r") + print(". disconnect\r") + print("b break\r") + print("o reopen\r") + print("po power off\r") + print("ps shutdown\r") + print("pbs boot to setup\r") + print("pbn boot to network\r") + print("pb boot to default\r") print(" abort command\r") elif localcommand[0] == '\x0d': print("ignored]\r")