Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame^] | 5 | OPTS="bmcstate,bootprogress,chassisoff,chassison,chassisstate,hoststate,\ |
| 6 | power,poweroff,poweron,state,status" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 7 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 8 | USAGE="Usage: obmcutil [-h] |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 9 | {$OPTS}" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 10 | |
| 11 | INTERFACE_ROOT=xyz.openbmc_project |
| 12 | STATE_INTERFACE=$INTERFACE_ROOT.State |
| 13 | |
| 14 | OBJECT_ROOT=/xyz/openbmc_project |
| 15 | STATE_OBJECT=$OBJECT_ROOT/state |
| 16 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 17 | print_help () |
| 18 | { |
| 19 | echo "$USAGE" |
| 20 | echo "" |
| 21 | echo "positional arguments:" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 22 | echo " {$OPTS}" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 23 | echo "" |
| 24 | echo "optional arguments:" |
| 25 | echo " -h, --help show this help message and exit" |
| 26 | exit 0 |
| 27 | } |
| 28 | |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame^] | 29 | set_property () |
| 30 | { |
| 31 | busctl set-property "$@" |
| 32 | } |
| 33 | |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 34 | get_property () |
| 35 | { |
| 36 | busctl get-property "$@" |
| 37 | } |
| 38 | |
| 39 | state_query () |
| 40 | { |
| 41 | local state=$(get_property "$@" | cut -d '"' -f2) |
| 42 | printf "%-20s: %s\n" $4 $state |
| 43 | } |
| 44 | |
| 45 | handle_cmd () |
| 46 | { |
| 47 | case "$1" in |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame^] | 48 | chassisoff) |
| 49 | OBJECT=$STATE_OBJECT/chassis0 |
| 50 | SERVICE=$(mapper get-service $OBJECT) |
| 51 | INTERFACE=$STATE_INTERFACE.Chassis |
| 52 | PROPERTY=RequestedPowerTransition |
| 53 | VALUE=$INTERFACE.Transition.Off |
| 54 | set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
| 55 | ;; |
| 56 | chassison) |
| 57 | OBJECT=$STATE_OBJECT/chassis0 |
| 58 | SERVICE=$(mapper get-service $OBJECT) |
| 59 | INTERFACE=$STATE_INTERFACE.Chassis |
| 60 | PROPERTY=RequestedPowerTransition |
| 61 | VALUE=$INTERFACE.Transition.On |
| 62 | set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
| 63 | ;; |
| 64 | poweroff) |
| 65 | OBJECT=$STATE_OBJECT/host0 |
| 66 | SERVICE=$(mapper get-service $OBJECT) |
| 67 | INTERFACE=$STATE_INTERFACE.Host |
| 68 | PROPERTY=RequestedHostTransition |
| 69 | VALUE=$INTERFACE.Transition.Off |
| 70 | set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
| 71 | ;; |
| 72 | poweron) |
| 73 | OBJECT=$STATE_OBJECT/host0 |
| 74 | SERVICE=$(mapper get-service $OBJECT) |
| 75 | INTERFACE=$STATE_INTERFACE.Host |
| 76 | PROPERTY=RequestedHostTransition |
| 77 | VALUE=$INTERFACE.Transition.On |
| 78 | set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
| 79 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 80 | bmcstate) |
| 81 | OBJECT=$STATE_OBJECT/bmc0 |
| 82 | SERVICE=$(mapper get-service $OBJECT) |
| 83 | INTERFACE=$STATE_INTERFACE.BMC |
| 84 | PROPERTY=CurrentBMCState |
| 85 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 86 | ;; |
| 87 | chassisstate) |
| 88 | OBJECT=$STATE_OBJECT/chassis0 |
| 89 | SERVICE=$(mapper get-service $OBJECT) |
| 90 | INTERFACE=$STATE_INTERFACE.Chassis |
| 91 | PROPERTY=CurrentPowerState |
| 92 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 93 | ;; |
| 94 | hoststate) |
| 95 | OBJECT=$STATE_OBJECT/host0 |
| 96 | SERVICE=$(mapper get-service $OBJECT) |
| 97 | INTERFACE=$STATE_INTERFACE.Host |
| 98 | PROPERTY=CurrentHostState |
| 99 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 100 | ;; |
| 101 | state|status) |
| 102 | for query in bmcstate chassisstate hoststate |
| 103 | do |
| 104 | handle_cmd $query |
| 105 | done |
| 106 | ;; |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 107 | bootprogress) |
| 108 | OBJECT=$STATE_OBJECT/host0 |
| 109 | SERVICE=$(mapper get-service $OBJECT) |
| 110 | INTERFACE=$STATE_INTERFACE.Boot.Progress |
| 111 | PROPERTY=BootProgress |
| 112 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 113 | ;; |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 114 | power) |
| 115 | OBJECT=/org/openbmc/control/power0 |
| 116 | SERVICE=$(mapper get-service $OBJECT) |
| 117 | INTERFACE=org.openbmc.control.Power |
| 118 | for property in pgood state pgood_timeout |
| 119 | do |
| 120 | # get_property can potentially return several |
| 121 | # different formats of values, so we do the parsing outside |
| 122 | # of get_property depending on the query. These queries |
| 123 | # return 'i VALUE' formatted strings. |
| 124 | STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \ |
| 125 | | sed 's/i[ ^I]*//') |
| 126 | printf "%s = %s\n" $property $STATE |
| 127 | done |
| 128 | ;; |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 129 | -h|--help) |
| 130 | print_help |
| 131 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 132 | *) |
| 133 | echo "ERROR: Invalid Choice: '$1'" |
| 134 | echo "$USAGE" |
| 135 | ;; |
| 136 | esac |
| 137 | } |
| 138 | |
| 139 | handle_cmd $1 |