kontron / python-ipmi

A pure python IPMI library
GNU Lesser General Public License v2.1
187 stars 75 forks source link

show methods or show class for py-ipmi #57

Closed FerencFarkasPhD closed 5 years ago

FerencFarkasPhD commented 5 years ago

Based on your example I made an created the following code: `

def show_device_id(device_id):
"""
Function printing the result of the get_device_id() in the order
as presented in the IPMI 2.0 standard. The only exception is the
'Additional Device Support' which is placed at the end and shows
all possible functions marking with [X] which are supported.
"""
functions = (
        ('SENSOR', 'Sensor Device', 11),
        ('SDR_REPOSITORY', 'SDR Repository Device', 3),
        ('SEL', 'SEL Device', 14),
        ('FRU_INVENTORY', 'FRU Inventory Device', 4),
        ('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver', 5),
        ('IPMB_EVENT_GENERATOR', 'IPMB Event Generator', 4),
        ('BRIDGE', 'Bridge', 18),
        ('CHASSIS', 'Chassis Device', 10))
ChkBox=['[ ]','[X]']
print('''\n
Device ID:                  %(device_id)s
Provides Device SDRs:       %(provides_sdrs)s
Device Revision:            %(revision)s
Device Available:           %(available)d
Firmware Revision:          %(fw_revision)s
IPMI Version:               %(ipmi_version)s
Manufacturer ID:            %(manufacturer_id)d (0x%(manufacturer_id)04x)
Product ID:                 %(product_id)d (0x%(product_id)04x)
Aux Firmware Rev Info:      %(aux)s
Additional Device Support: '''[1:-1] % device_id.__dict__)
for n, s, l in functions:
    if device_id.supports_function(n):
        print('        %s%s%s' % (s,l*' ',ChkBox[1]))
    else:
        print('        %s%s%s' % (s,l*' ',ChkBox[0]))`

similarly I created another one: `

def show_watchdog_timer(watchdog_timer):
"""
Function printing the result of the get_watchdog_timer().
"""
timer_use_const=['BIOS FRB2','BIOS/POST','OS Load','SMS/OS','OEM']
pretime_intr_const=['None','SMI','NMI','Msg intr']
timeout_act_const=['No action','Hard Reset','Power Down','Power Cycle']
print("""\n
Don't log:                  {0[dont_log]:}
Timer is running:           {0[is_running]:}
Pre-timout interval:        {0[pre_timeout_interval]:d}
Initial countdown value:    {0[initial_countdown]:d}
Present countdown value:    {0[present_countdown]:d}
"""[1:-1].format(watchdog.__dict__),end='')
print("    Timer use:                 ",
      timer_use_const[watchdog.__dict__['timer_use']-1])
print("    Timer use expiration flag: ",
      timer_use_const[watchdog_timer.__dict__['timer_use_expiration_flags']-1])
print("    Pre-timeout interrupt:     ",
      pretime_intr_const[watchdog.__dict__['pre_timeout_interval']])
print("    Time out action:           ",
      timeout_act_const[watchdog.__dict__['timeout_action']])`

Currently I am working on a third one, namely def show_chassis_status(chassis_status):

So, probably we should create a new file where we collect all these functions. Of course, a more elegant solution would be to create a show' class which show method is inherited by the Ipmi class and based on the object type passed as an argument different method would be called. As an example, when you code you can do something like this `

ipmi.show(device_id) # First function would be called
ipmi.show(watchdog_timer) # Second function would be called
ipmi.show(chassis_status) # Third function would be called`

What do you think?

BR/Ferenc

FerencFarkasPhD commented 5 years ago

I added these functions as examples to the documentation (https://python-ipmi.readthedocs.io). There are more important methods to be implemented in the library, so I close this issue. /Ferenc