blob: 68b5454d3745be06b82baacb8e816e94e15df277 [file] [log] [blame]
Anthony Wilson79f697e2018-09-13 13:48:52 -05001#!/bin/sh -e
2
3set -euo pipefail
4
Anthony Wilson0f359832018-09-13 14:28:07 -05005OPTS="bmcstate,bootprogress,chassisstate,hoststate,power,state,status"
6
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -05007USAGE="Usage: obmcutil [-h]
Anthony Wilson0f359832018-09-13 14:28:07 -05008 {$OPTS}"
Anthony Wilson79f697e2018-09-13 13:48:52 -05009
10INTERFACE_ROOT=xyz.openbmc_project
11STATE_INTERFACE=$INTERFACE_ROOT.State
12
13OBJECT_ROOT=/xyz/openbmc_project
14STATE_OBJECT=$OBJECT_ROOT/state
15
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050016print_help ()
17{
18 echo "$USAGE"
19 echo ""
20 echo "positional arguments:"
Anthony Wilson0f359832018-09-13 14:28:07 -050021 echo " {$OPTS}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050022 echo ""
23 echo "optional arguments:"
24 echo " -h, --help show this help message and exit"
25 exit 0
26}
27
Anthony Wilson79f697e2018-09-13 13:48:52 -050028get_property ()
29{
30 busctl get-property "$@"
31}
32
33state_query ()
34{
35 local state=$(get_property "$@" | cut -d '"' -f2)
36 printf "%-20s: %s\n" $4 $state
37}
38
39handle_cmd ()
40{
41 case "$1" in
42 bmcstate)
43 OBJECT=$STATE_OBJECT/bmc0
44 SERVICE=$(mapper get-service $OBJECT)
45 INTERFACE=$STATE_INTERFACE.BMC
46 PROPERTY=CurrentBMCState
47 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
48 ;;
49 chassisstate)
50 OBJECT=$STATE_OBJECT/chassis0
51 SERVICE=$(mapper get-service $OBJECT)
52 INTERFACE=$STATE_INTERFACE.Chassis
53 PROPERTY=CurrentPowerState
54 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
55 ;;
56 hoststate)
57 OBJECT=$STATE_OBJECT/host0
58 SERVICE=$(mapper get-service $OBJECT)
59 INTERFACE=$STATE_INTERFACE.Host
60 PROPERTY=CurrentHostState
61 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
62 ;;
63 state|status)
64 for query in bmcstate chassisstate hoststate
65 do
66 handle_cmd $query
67 done
68 ;;
Anthony Wilson50c5f882018-09-13 14:19:37 -050069 bootprogress)
70 OBJECT=$STATE_OBJECT/host0
71 SERVICE=$(mapper get-service $OBJECT)
72 INTERFACE=$STATE_INTERFACE.Boot.Progress
73 PROPERTY=BootProgress
74 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
75 ;;
Anthony Wilson0f359832018-09-13 14:28:07 -050076 power)
77 OBJECT=/org/openbmc/control/power0
78 SERVICE=$(mapper get-service $OBJECT)
79 INTERFACE=org.openbmc.control.Power
80 for property in pgood state pgood_timeout
81 do
82 # get_property can potentially return several
83 # different formats of values, so we do the parsing outside
84 # of get_property depending on the query. These queries
85 # return 'i VALUE' formatted strings.
86 STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \
87 | sed 's/i[ ^I]*//')
88 printf "%s = %s\n" $property $STATE
89 done
90 ;;
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050091 -h|--help)
92 print_help
93 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -050094 *)
95 echo "ERROR: Invalid Choice: '$1'"
96 echo "$USAGE"
97 ;;
98 esac
99}
100
101handle_cmd $1