blob: 9856c4811a03f32ddaea8387a966c0697e5ac612 [file] [log] [blame]
Anthony Wilson79f697e2018-09-13 13:48:52 -05001#!/bin/sh -e
2
3set -euo pipefail
4
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -05005USAGE="Usage: obmcutil [-h]
6 {bmcstate,chassisstate,hoststate,state,status}"
Anthony Wilson79f697e2018-09-13 13:48:52 -05007
8INTERFACE_ROOT=xyz.openbmc_project
9STATE_INTERFACE=$INTERFACE_ROOT.State
10
11OBJECT_ROOT=/xyz/openbmc_project
12STATE_OBJECT=$OBJECT_ROOT/state
13
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050014print_help ()
15{
16 echo "$USAGE"
17 echo ""
18 echo "positional arguments:"
19 echo " {bmcstate,chassisstate,hoststate,state,status}"
20 echo ""
21 echo "optional arguments:"
22 echo " -h, --help show this help message and exit"
23 exit 0
24}
25
Anthony Wilson79f697e2018-09-13 13:48:52 -050026get_property ()
27{
28 busctl get-property "$@"
29}
30
31state_query ()
32{
33 local state=$(get_property "$@" | cut -d '"' -f2)
34 printf "%-20s: %s\n" $4 $state
35}
36
37handle_cmd ()
38{
39 case "$1" in
40 bmcstate)
41 OBJECT=$STATE_OBJECT/bmc0
42 SERVICE=$(mapper get-service $OBJECT)
43 INTERFACE=$STATE_INTERFACE.BMC
44 PROPERTY=CurrentBMCState
45 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
46 ;;
47 chassisstate)
48 OBJECT=$STATE_OBJECT/chassis0
49 SERVICE=$(mapper get-service $OBJECT)
50 INTERFACE=$STATE_INTERFACE.Chassis
51 PROPERTY=CurrentPowerState
52 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
53 ;;
54 hoststate)
55 OBJECT=$STATE_OBJECT/host0
56 SERVICE=$(mapper get-service $OBJECT)
57 INTERFACE=$STATE_INTERFACE.Host
58 PROPERTY=CurrentHostState
59 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
60 ;;
61 state|status)
62 for query in bmcstate chassisstate hoststate
63 do
64 handle_cmd $query
65 done
66 ;;
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050067 -h|--help)
68 print_help
69 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -050070 *)
71 echo "ERROR: Invalid Choice: '$1'"
72 echo "$USAGE"
73 ;;
74 esac
75}
76
77handle_cmd $1