| #!/usr/bin/python |
| |
| import sys |
| import dbus |
| import argparse |
| |
| descriptors = { |
| 'power': { |
| 'bus_name': 'org.openbmc.control.Power', |
| 'object_name': '/org/openbmc/control/power0', |
| 'interface_name': 'org.openbmc.control.Power' |
| }, |
| 'chassison': { |
| 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 'property': 'RequestedPowerTransition', |
| 'value': 'xyz.openbmc_project.State.Chassis.Transition.On' |
| }, |
| 'chassisoff': { |
| 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 'property': 'RequestedPowerTransition', |
| 'value': 'xyz.openbmc_project.State.Chassis.Transition.Off' |
| }, |
| 'poweron': { |
| 'bus_name': 'xyz.openbmc_project.State.Host', |
| 'object_name': '/xyz/openbmc_project/state/host0', |
| 'interface_name': 'xyz.openbmc_project.State.Host', |
| 'property': 'RequestedHostTransition', |
| 'value': 'xyz.openbmc_project.State.Host.Transition.On' |
| }, |
| 'poweroff': { |
| 'bus_name': 'xyz.openbmc_project.State.Host', |
| 'object_name': '/xyz/openbmc_project/state/host0', |
| 'interface_name': 'xyz.openbmc_project.State.Host', |
| 'property': 'RequestedHostTransition', |
| 'value': 'xyz.openbmc_project.State.Host.Transition.Off' |
| }, |
| 'bmcstate': { |
| 'bus_name': 'xyz.openbmc_project.State.BMC', |
| 'object_name': '/xyz/openbmc_project/state/bmc0', |
| 'interface_name': 'xyz.openbmc_project.State.BMC', |
| 'property': 'CurrentBMCState', |
| }, |
| 'chassisstate': { |
| 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 'property': 'CurrentPowerState', |
| }, |
| 'hoststate': { |
| 'bus_name': 'xyz.openbmc_project.State.Host', |
| 'object_name': '/xyz/openbmc_project/state/host0', |
| 'interface_name': 'xyz.openbmc_project.State.Host', |
| 'property': 'CurrentHostState', |
| }, |
| 'bootprogress': { |
| 'bus_name': 'xyz.openbmc_project.State.Host', |
| 'object_name': '/xyz/openbmc_project/state/host0', |
| 'interface_name': 'xyz.openbmc_project.State.Boot.Progress', |
| 'property': 'BootProgress', |
| }, |
| 'state' : ['bmcstate', 'chassisstate', 'hoststate'] |
| } |
| |
| def run_one_command(dbus_bus, descriptor): |
| bus = descriptor['bus_name'] |
| obj = descriptor['object_name'] |
| iface = descriptor['interface_name'] |
| dbus_obj = dbus_bus.get_object(bus, obj) |
| |
| if (descriptor.has_key('property')): |
| prop = descriptor['property'] |
| dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
| if descriptor.has_key('value'): |
| dbus_iface.Set(iface, prop, descriptor['value']) |
| else: |
| dbus_prop = dbus_iface.Get(iface, prop) |
| print '{:<20}: {}'.format(prop, str(dbus_prop)) |
| else: |
| dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
| props = dbus_iface.GetAll(iface) |
| for p in props: |
| print p + " = " + str(props[p]) |
| |
| def run_all_commands(dbus_bus, recipe): |
| if isinstance(recipe, dict): |
| run_one_command(dbus_bus, recipe) |
| return |
| |
| assert isinstance(recipe, list) |
| for command in recipe: |
| run_one_command(dbus_bus, descriptors[command]) |
| |
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument('recipe', choices=sorted(descriptors.keys())) |
| args = parser.parse_args() |
| |
| dbus_bus = dbus.SystemBus() |
| try: |
| run_all_commands(dbus_bus, descriptors[args.recipe], args) |
| finally: |
| dbus_bus.close() |
| |
| if __name__ == "__main__": |
| main() |