Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame^] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
| 5 | USAGE="Usage: obmcutil {bmcstate,chassisstate,hoststate,state,status}" |
| 6 | |
| 7 | INTERFACE_ROOT=xyz.openbmc_project |
| 8 | STATE_INTERFACE=$INTERFACE_ROOT.State |
| 9 | |
| 10 | OBJECT_ROOT=/xyz/openbmc_project |
| 11 | STATE_OBJECT=$OBJECT_ROOT/state |
| 12 | |
| 13 | get_property () |
| 14 | { |
| 15 | busctl get-property "$@" |
| 16 | } |
| 17 | |
| 18 | state_query () |
| 19 | { |
| 20 | local state=$(get_property "$@" | cut -d '"' -f2) |
| 21 | printf "%-20s: %s\n" $4 $state |
| 22 | } |
| 23 | |
| 24 | handle_cmd () |
| 25 | { |
| 26 | case "$1" in |
| 27 | bmcstate) |
| 28 | OBJECT=$STATE_OBJECT/bmc0 |
| 29 | SERVICE=$(mapper get-service $OBJECT) |
| 30 | INTERFACE=$STATE_INTERFACE.BMC |
| 31 | PROPERTY=CurrentBMCState |
| 32 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 33 | ;; |
| 34 | chassisstate) |
| 35 | OBJECT=$STATE_OBJECT/chassis0 |
| 36 | SERVICE=$(mapper get-service $OBJECT) |
| 37 | INTERFACE=$STATE_INTERFACE.Chassis |
| 38 | PROPERTY=CurrentPowerState |
| 39 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 40 | ;; |
| 41 | hoststate) |
| 42 | OBJECT=$STATE_OBJECT/host0 |
| 43 | SERVICE=$(mapper get-service $OBJECT) |
| 44 | INTERFACE=$STATE_INTERFACE.Host |
| 45 | PROPERTY=CurrentHostState |
| 46 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 47 | ;; |
| 48 | state|status) |
| 49 | for query in bmcstate chassisstate hoststate |
| 50 | do |
| 51 | handle_cmd $query |
| 52 | done |
| 53 | ;; |
| 54 | *) |
| 55 | echo "ERROR: Invalid Choice: '$1'" |
| 56 | echo "$USAGE" |
| 57 | ;; |
| 58 | esac |
| 59 | } |
| 60 | |
| 61 | handle_cmd $1 |