[Fuego] [PATCH] ftc: add a new command to interact with pdudaemon
Daniel Sangorrin
daniel.sangorrin at toshiba.co.jp
Tue Mar 5 07:34:11 UTC 2019
This patch adds the "pdu" command to send requests for pdudaemon
to power-on/off or reboot a board.
Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
---
scripts/ftc | 80 +++++++++++++++++++++++++++++++++++++++++++++++
scripts/ftc_completion.sh | 5 +++
2 files changed, 85 insertions(+)
diff --git a/scripts/ftc b/scripts/ftc
index 7153c01..30ea470 100755
--- a/scripts/ftc
+++ b/scripts/ftc
@@ -426,6 +426,29 @@ A message and the exit code indicate if the resource was released.
ex: ftc release-resource -b beaglebone"""),
+"pdu": ("Send a request to pdudaemon.",
+ """Usage: ftc pdu -b <board> --command on|off|reboot [--pdudaemon_hostname localhost --pdudaemon_port 16421]
+
+This command is used to send a request for pdudaemon to power-on, power-off or reboot a board.
+
+The command accepts these arguments:
+ - board file: bbb, raspberrypi3, etc (see ftc list-boards)
+ - command: on|off|reboot
+ - pdudaemon_hostname: hostname or IP address where pdudaemon is running (default: localhost)
+ - pdudaemon_port: port where pdudaemon is listening (default: 16421)
+ [Note] make sure that pdudaemon is configured to accept http requests
+
+Additionally, you need to define two variables in your board file:
+ - PDU_HOSTNAME: the PDU hostname or IP address used in the pdudaemon configuration file
+ - PDU_PORT: the PDU port number (a plug port, not a tcp port)
+
+You need to install pdudaemon by yourself
+ $ git clone https://github.com/pdudaemon/pdudaemon
+ $ cd pdudaemon
+ $ less README.md
+
+Example: ftc pdu -b raspberrypi3 --command on"""),
+
"package-test": ("Package a test.",
"""Usage: ftc package-test <test_name> [options]
@@ -4783,6 +4806,59 @@ def do_release_resource(conf, options):
return 0
+def do_pdu(bvars, conf, options):
+ # pdudaemon hostname
+ pdudaemon_hostname = 'localhost'
+ if '--pdudaemon_hostname' in options:
+ try:
+ pdudaemon_hostname = options[options.index('--pdudaemon_hostname')+1]
+ except IndexError:
+ error_out('Value not provided after --pdudaemon_hostname')
+ options.remove(pdudaemon_hostname)
+ options.remove('--pdudaemon_hostname')
+
+ # pdudaemon port
+ pdudaemon_port = '16421'
+ if '--pdudaemon_port' in options:
+ try:
+ pdudaemon_port = options[options.index('--pdudaemon_port')+1]
+ except IndexError:
+ error_out('Value not provided after --pdudaemon_port')
+ options.remove(pdudaemon_port)
+ options.remove('--pdudaemon_port')
+
+ # pdu hostname
+ if 'PDU_HOSTNAME' in bvars:
+ pdu_hostname = bvars['PDU_HOSTNAME']
+ else:
+ error_out('PDU_HOSTNAME not specified in board file')
+
+ # pdu port
+ if 'PDU_PORT' in bvars:
+ pdu_port = bvars['PDU_PORT']
+ else:
+ error_out('PDU_PORT not specified in board file')
+
+ # command (on|off|reboot)
+ if '--command' in options:
+ try:
+ command = options[options.index('--command')+1]
+ except IndexError:
+ error_out('Value not provided after --command')
+ options.remove(command)
+ options.remove('--command')
+ if command not in ['on', 'off', 'reboot']:
+ error_out('Unrecognized PDU command %s' % command)
+ else:
+ error_out('Command not supplied')
+
+ query='&'.join(['hostname='+pdu_hostname, 'port='+pdu_port])
+ url = 'http://%s:%s/power/control/%s?%s' % (pdudaemon_hostname, pdudaemon_port, command, query)
+ resp = requests.get(url)
+ if resp.status_code != 200:
+ error_out("pdudaemon did not accept the request")
+ return 0
+
def main():
# use global module names
global re, time, copy2, subprocess, signal, fcntl, requests, json
@@ -5094,6 +5170,10 @@ def main():
do_delete_var(bvars, options)
sys.exit(0)
+ if command == "pdu":
+ rcode = do_pdu(bvars, conf, options)
+ sys.exit(rcode)
+
error_out("Unknown command %s" % command)
diff --git a/scripts/ftc_completion.sh b/scripts/ftc_completion.sh
index 984e003..2cfb77a 100755
--- a/scripts/ftc_completion.sh
+++ b/scripts/ftc_completion.sh
@@ -55,6 +55,7 @@ _ftc()
["list-tests"]="-q"
["package-run"]="-o -f"
["package-test"]="-o -f"
+ ["pdu"]="-b --command --pdudaemon_hostname --pdudaemon_port"
["put-request"]="-R -s"
["put-run"]=""
["put-test"]=""
@@ -123,6 +124,10 @@ _ftc()
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
+ '--command')
+ COMPREPLY=( $( compgen -W "on off reboot" -- "$cur" ) )
+ return 0
+ ;;
'put-run')
COMPREPLY=( $( compgen -W "$(ftc list-runs -q)" -- "$cur" ) )
return 0
--
2.7.4
More information about the Fuego
mailing list