Skip to content

Commit

Permalink
Merge pull request #30 from hthiery/master
Browse files Browse the repository at this point in the history
fix codestyle
  • Loading branch information
hthiery committed Sep 17, 2018
2 parents af05503 + 223c61a commit e8e6247
Show file tree
Hide file tree
Showing 35 changed files with 743 additions and 734 deletions.
23 changes: 13 additions & 10 deletions pyipmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from __future__ import absolute_import

Expand All @@ -39,6 +39,7 @@
except ImportError:
__version__ = 'dev'


def create_connection(interface):
session = Session()
session.interface = interface
Expand All @@ -48,6 +49,7 @@ def create_connection(interface):
ipmi.requester = NullRequester()
return ipmi


class Requester(object):
'''The Requester class represents an IPMI device which initiates a
request/response message exchange.
Expand All @@ -56,6 +58,7 @@ class Requester(object):
def __init__(self, ipmb_address):
self.ipmb_address = ipmb_address


class NullRequester(object):
'''The NullRequester is used for interfaces which doesn't require a
valid requester.
Expand Down Expand Up @@ -84,7 +87,6 @@ def __init__(self, address, bridge_channel):
self.address = address
self.bridge_channel = bridge_channel


def set_routing_information(self, rinfo):
self.set_routing(rinfo)

Expand All @@ -95,15 +97,15 @@ def set_routing(self, rinfo):
bridge_channel).
"""

self.routing = [ self.Routing(*r) for r in rinfo ]
self.routing = [self.Routing(*r) for r in rinfo]


class Session(object):
AUTH_TYPE_NONE = 0x00
AUTH_TYPE_MD2 = 0x01
AUTH_TYPE_MD5 = 0x02
AUTH_TYPE_PASSWORD = 0x04
AUTH_TYPE_OEM = 0x05
AUTH_TYPE_NONE = 0x00
AUTH_TYPE_MD2 = 0x01
AUTH_TYPE_MD5 = 0x02
AUTH_TYPE_PASSWORD = 0x04
AUTH_TYPE_OEM = 0x05

def __init__(self):
self.set_auth_type(self.AUTH_TYPE_NONE)
Expand Down Expand Up @@ -148,8 +150,9 @@ def rmcp_ping(self):

interface = property(_get_interface, _set_interface)


class Ipmi(bmc.Bmc, chassis.Chassis, fru.Fru, picmg.Picmg, hpm.Hpm,
sdr.Sdr, sensor.Sensor, event.Event, sel.Sel, lan.Lan):
sdr.Sdr, sensor.Sensor, event.Event, sel.Sel, lan.Lan):

def __init__(self):
for base in Ipmi.__bases__:
Expand Down Expand Up @@ -198,7 +201,7 @@ def send_message_with_name(self, name, *args, **kwargs):

def raw_command(self, lun, netfn, raw_bytes):
return self.interface.send_and_receive_raw(self.target, lun, netfn,
raw_bytes)
raw_bytes)

def _get_interface(self):
try:
Expand Down
40 changes: 20 additions & 20 deletions pyipmi/bmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from .msgs import create_request_by_name
from .utils import check_completion_code
Expand All @@ -30,10 +30,11 @@ def cold_reset(self):
def warm_reset(self):
self.send_message_with_name('WarmReset')

def i2c_write_read(self, type, id, channel, address, count, data=None):
def i2c_write_read(self, bus_type, bus_id, channel, address, count,
data=None):
req = create_request_by_name('MasterWriteRead')
req.bus_id.type = type
req.bus_id.id = id
req.bus_id.type = bus_type
req.bus_id.id = bus_id
req.bus_id.channel = channel
req.bus_id.slave_address = address
req.read_count = count
Expand All @@ -43,22 +44,21 @@ def i2c_write_read(self, type, id, channel, address, count, data=None):
check_completion_code(rsp.completion_code)
return rsp.data

def i2c_write(self, type, id, channel, address, data):
self.i2c_write_read(type, id, channel, address, 0, data)
def i2c_write(self, bus_type, bus_id, channel, address, data):
self.i2c_write_read(bus_type, bus_id, channel, address, 0, data)

def i2c_read(self, type, id, channel, address, count):
return self.i2c_write_read(type, id, channel, address, count, None)
def i2c_read(self, bus_type, bus_id, channel, address, count):
return self.i2c_write_read(bus_type, bus_id, channel,
address, count, None)

def set_watchdog_timer(self, config):
req = create_request_by_name('SetWatchdogTimer')
req.timer_use.timer_use = config.timer_use
req.timer_use.dont_stop = config.dont_stop and 1 or 0
req.timer_use.dont_log = config.dont_log and 1 or 0

req.timer_actions.pre_timeout_interrupt = \
config.pre_timeout_interrupt
req.timer_actions.timeout_action = \
config.timeout_action
req.timer_actions.pre_timeout_interrupt = config.pre_timeout_interrupt
req.timer_actions.timeout_action = config.timeout_action

req.pre_timeout_interval = config.pre_timeout_interval
req.timer_use_expiration_flags = config.timer_use_expiration_flags
Expand Down Expand Up @@ -114,14 +114,14 @@ def _from_response(self, rsp):
class DeviceId(State):

def __str__(self):
s = 'Device ID: %d' % self.device_id
s += ' revision: %d' % self.revision
s += ' available: %d' % self.available
s += ' fw version: %s' % (self.fw_revision)
s += ' ipmi: %s' % self.ipmi_version
s += ' manufacturer: %d' % self.manufacturer_id
s += ' product: %d' % self.product_id
return s
string = 'Device ID: %d' % self.device_id
string += ' revision: %d' % self.revision
string += ' available: %d' % self.available
string += ' fw version: %s' % (self.fw_revision)
string += ' ipmi: %s' % self.ipmi_version
string += ' manufacturer: %d' % self.manufacturer_id
string += ' product: %d' % self.product_id
return string

def supports_function(self, name):
"""Returns if a function is supported.
Expand Down
13 changes: 10 additions & 3 deletions pyipmi/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from __future__ import absolute_import

Expand Down Expand Up @@ -56,6 +56,15 @@ def chassis_control_soft_shutdown(self):


class ChassisStatus(State):
power_on = None
overload = None
interlock = None
fault = None
control_fault = None
restore_policy = None
last_event = []
chassis_state = []

def _from_response(self, rsp):
self.power_on = bool(rsp.current_power_state.power_on)
self.overload = bool(rsp.current_power_state.power_overload)
Expand All @@ -64,7 +73,6 @@ def _from_response(self, rsp):
self.control_fault = bool(rsp.current_power_state.power_control_fault)
self.restore_policy = rsp.current_power_state.power_restore_policy

self.last_event = []
if rsp.last_power_event.ac_failed:
self.last_event.append('ac_failed')
if rsp.last_power_event.power_overload:
Expand All @@ -76,7 +84,6 @@ def _from_response(self, rsp):
if rsp.last_power_event.power_is_on_via_ipmi_command:
self.last_event.append('power_on_via_ipmi')

self.chassis_state = []
if rsp.misc_chassis_state.chassis_intrusion_active:
self.chassis_state.append('intrusion')
if rsp.misc_chassis_state.front_panel_lockout_active:
Expand Down
6 changes: 4 additions & 2 deletions pyipmi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from .msgs.constants import cc_err_desc


class DecodingError(Exception):
"""Error on message decoding."""
pass
Expand All @@ -38,7 +39,8 @@ def __init__(self, cc):
self.cc_desc = self.find_cc_desc(cc)

def __str__(self):
return "%s cc=0x%02x desc=%s" % (self.__class__.__name__, self.cc, self.cc_desc)
return "%s cc=0x%02x desc=%s" \
% (self.__class__.__name__, self.cc, self.cc_desc)

@staticmethod
def find_cc_desc(error_cc):
Expand Down
3 changes: 2 additions & 1 deletion pyipmi/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from .utils import check_completion_code
from .msgs import create_request_by_name

EVENT_ASSERTION = 0
EVENT_DEASSERTION = 1


class Event(object):
def set_event_receiver(self, ipmb_address, lun):
req = create_request_by_name('SetEventReceiver')
Expand Down
3 changes: 2 additions & 1 deletion pyipmi/fields.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


import array

from .errors import DecodingError


class VersionField(object):
"""This class represent the Version fields defines by IPMI.
Expand Down
21 changes: 12 additions & 9 deletions pyipmi/fru.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import array
import codecs
Expand All @@ -31,13 +31,15 @@ def __init__(self):

def get_fru_inventory_area_info(self, fru_id=0):
rsp = self.send_message_with_name('GetFruInventoryAreaInfo',
fru_id=fru_id)
fru_id=fru_id)
return rsp.area_size

def write_fru_data(self, data, offset=0, fru_id=0):
for chunk in chunks(data, self.write_length):
write_rsp = self.send_message_with_name('WriteFruData',
fru_id=fru_id, offset=offset, data=chunk)
fru_id=fru_id,
offset=offset,
data=chunk)

# check if device wrote the same number of bytes sent
if write_rsp.count_written != len(chunk):
Expand All @@ -47,8 +49,6 @@ def write_fru_data(self, data, offset=0, fru_id=0):
offset += len(chunk)

def read_fru_data(self, offset=None, count=None, fru_id=0):
#off = 0
#area_size = 0
req_size = 32
data = array.array('B')

Expand All @@ -65,8 +65,8 @@ def read_fru_data(self, offset=None, count=None, fru_id=0):
req_size = area_size - off

try:
rsp = self.send_message_with_name('ReadFruData',
fru_id=fru_id, offset=off, count=req_size)
rsp = self.send_message_with_name('ReadFruData', fru_id=fru_id,
offset=off, count=req_size)
except CompletionCodeError as e:
if e.cc in (constants.CC_CANT_RET_NUM_REQ_BYTES,
constants.CC_REQ_DATA_FIELD_EXCEED,
Expand Down Expand Up @@ -120,6 +120,8 @@ def _from_data(self, data, offset=0, force_lang_english=False):


CUSTOM_FIELD_END = 0xc1


def _decode_custom_fields(data):
offset = 0
fields = []
Expand Down Expand Up @@ -207,7 +209,7 @@ def _from_data(self, data):
self.language_code = data[2]
minutes = data[5] << 16 | data[4] << 8 | data[3]
self.mfg_date = (datetime.datetime(1996, 1, 1)
+ datetime.timedelta(minutes=minutes))
+ datetime.timedelta(minutes=minutes))
offset = 6
self.manufacturer = FruDataField(data, offset)
offset += self.manufacturer.length + 1
Expand Down Expand Up @@ -330,7 +332,8 @@ def _from_data(self, data):
if len(data) < 10:
raise DecodingError('data too short')
FruDataMultiRecord._from_data(self, data)
self.manufacturer_id = ord(data[5]) | ord(data[6]) << 8 | ord(data[7]) << 16
self.manufacturer_id = \
ord(data[5]) | ord(data[6]) << 8 | ord(data[7]) << 16
self.picmg_record_type_id = ord(data[8])
self.format_version = ord(data[9])

Expand Down
Loading

0 comments on commit e8e6247

Please sign in to comment.