blob: 61c85dd48f2a8e46e64c80879b2a53715a4c1510 [file] [log] [blame]
Anthony Wilson79f697e2018-09-13 13:48:52 -05001#!/bin/sh -e
2
3set -euo pipefail
4
Anthony Wilson3ae0a352018-09-13 14:47:56 -05005OPTS="bmcstate,bootprogress,chassisoff,chassison,chassisstate,hoststate,\
6power,poweroff,poweron,state,status"
Anthony Wilson0f359832018-09-13 14:28:07 -05007
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -05008USAGE="Usage: obmcutil [-h]
Anthony Wilson0f359832018-09-13 14:28:07 -05009 {$OPTS}"
Anthony Wilson79f697e2018-09-13 13:48:52 -050010
11INTERFACE_ROOT=xyz.openbmc_project
12STATE_INTERFACE=$INTERFACE_ROOT.State
13
14OBJECT_ROOT=/xyz/openbmc_project
15STATE_OBJECT=$OBJECT_ROOT/state
16
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050017print_help ()
18{
19 echo "$USAGE"
20 echo ""
21 echo "positional arguments:"
Anthony Wilson0f359832018-09-13 14:28:07 -050022 echo " {$OPTS}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050023 echo ""
24 echo "optional arguments:"
25 echo " -h, --help show this help message and exit"
26 exit 0
27}
28
Anthony Wilson3ae0a352018-09-13 14:47:56 -050029set_property ()
30{
31 busctl set-property "$@"
32}
33
Anthony Wilson79f697e2018-09-13 13:48:52 -050034get_property ()
35{
36 busctl get-property "$@"
37}
38
39state_query ()
40{
41 local state=$(get_property "$@" | cut -d '"' -f2)
42 printf "%-20s: %s\n" $4 $state
43}
44
45handle_cmd ()
46{
47 case "$1" in
Anthony Wilson3ae0a352018-09-13 14:47:56 -050048 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 Wilson79f697e2018-09-13 13:48:52 -050080 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 Wilson50c5f882018-09-13 14:19:37 -0500107 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 Wilson0f359832018-09-13 14:28:07 -0500114 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 Wilsonf3f16fa2018-09-13 14:10:52 -0500129 -h|--help)
130 print_help
131 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500132 *)
133 echo "ERROR: Invalid Choice: '$1'"
134 echo "$USAGE"
135 ;;
136 esac
137}
138
139handle_cmd $1