blob: 65ca7639942016cfb8373c8ac2218086da8f5fec [file] [log] [blame]
Anthony Wilson79f697e2018-09-13 13:48:52 -05001#!/bin/sh -e
2
3set -euo pipefail
4
5USAGE="Usage: obmcutil {bmcstate,chassisstate,hoststate,state,status}"
6
7INTERFACE_ROOT=xyz.openbmc_project
8STATE_INTERFACE=$INTERFACE_ROOT.State
9
10OBJECT_ROOT=/xyz/openbmc_project
11STATE_OBJECT=$OBJECT_ROOT/state
12
13get_property ()
14{
15 busctl get-property "$@"
16}
17
18state_query ()
19{
20 local state=$(get_property "$@" | cut -d '"' -f2)
21 printf "%-20s: %s\n" $4 $state
22}
23
24handle_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
61handle_cmd $1