Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipmitool: add option for json output #166

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions pyipmi/ipmitool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import sys
import getopt
import json
import logging
import traceback
import pprint
Expand All @@ -31,6 +32,7 @@
import pyipmi.interfaces
from pyipmi.utils import py3_array_tobytes

json_output = False

Command = namedtuple('Command', 'name fn')
CommandHelp = namedtuple('CommandHelp', 'name arguments help')
Expand Down Expand Up @@ -329,7 +331,21 @@ def cmd_hpm_install(ipmi, args):

def cmd_chassis_status(ipmi, args):
status = ipmi.get_chassis_status()
print('''

if json_output:
status = {
'power_on': status.power_on,
'overload': status.overload,
'interlock': status.interlock,
'fault': status.fault,
'ctrl_fault': status.control_fault,
'restore_policy': status.restore_policy
}
print(json.dumps(status))
pass
else:

print('''
Power ON: %(power_on)s
Overload: %(overload)s
Interlock: %(interlock)s
Expand All @@ -338,10 +354,10 @@ def cmd_chassis_status(ipmi, args):
Restore Policy: %(restore_policy)s
'''[1:-1] % status.__dict__)

for event in status.last_event:
print(event)
for state in status.chassis_state:
print(state)
for event in status.last_event:
print(event)
for state in status.chassis_state:
print(state)


def cmd_picmg_get_power(ipmi, args):
Expand Down Expand Up @@ -528,7 +544,7 @@ def parse_interface_options(interface_name, options):

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 't:hvVI:H:U:P:L:o:b:p:r:')
opts, args = getopt.getopt(sys.argv[1:], 't:hvVI:H:U:P:L:o:b:p:r:J')
except getopt.GetoptError as err:
print(str(err))
usage()
Expand Down Expand Up @@ -572,6 +588,9 @@ def main():
interface_name = a
elif o == '-o':
interface_options = a
elif o == '-J':
global json_output
json_output = True
else:
assert False, 'unhandled option'

Expand Down
Loading