2
0
mirror of https://opendev.org/x/pyghmi synced 2025-11-01 03:42:26 +00:00

Convert to using xraw_command

It is more efficient and exception based

Change-Id: Icddfb7272d9839e7ff74905132dc23276ce60b24
This commit is contained in:
Jarrod Johnson
2018-02-02 16:16:22 -05:00
parent 81858f13cc
commit 93bf10d7d0
2 changed files with 18 additions and 18 deletions

View File

@@ -55,10 +55,10 @@ class LenovoFirmwareConfig(object):
for i in range(len(filename)):
data += [ord(filename[i])]
response = self.connection.raw_command(netfn=IMM_NETFN,
command=IMM_COMMAND, data=data)
response = self.connection.xraw_command(netfn=IMM_NETFN,
command=IMM_COMMAND, data=data)
size = ''.join(chr(c) for c in response['data'][3:7])
size = response['data'][3:7]
size = struct.unpack("i", size)
return size[0]
@@ -84,9 +84,9 @@ class LenovoFirmwareConfig(object):
while retries:
retries = retries-1
response = self.connection.raw_command(netfn=IMM_NETFN,
command=IMM_COMMAND,
data=data)
response = self.connection.xraw_command(netfn=IMM_NETFN,
command=IMM_COMMAND,
data=data)
try:
if response['code'] == 0 or retries == 0:
break
@@ -94,7 +94,7 @@ class LenovoFirmwareConfig(object):
pass
self.connection.ipmi_session.pause(5)
filehandle = ''.join(chr(byte) for byte in response['data'][3:7])
filehandle = response['data'][3:7]
filehandle = struct.unpack("<I", filehandle)[0]
return filehandle
@@ -108,8 +108,8 @@ class LenovoFirmwareConfig(object):
for byte in hex_filehandle[:4]:
data += [ord(byte)]
self.connection.raw_command(netfn=IMM_NETFN,
command=IMM_COMMAND, data=data)
self.connection.xraw_command(netfn=IMM_NETFN,
command=IMM_COMMAND, data=data)
def imm_write(self, filehandle, size, inputdata):
blocksize = 0xc8
@@ -135,13 +135,13 @@ class LenovoFirmwareConfig(object):
data += [ord(byte)]
remaining -= blocksize
offset += blocksize
self.connection.raw_command(netfn=IMM_NETFN, command=IMM_COMMAND,
data=data)
self.connection.xraw_command(netfn=IMM_NETFN, command=IMM_COMMAND,
data=data)
def imm_read(self, filehandle, size):
blocksize = 0xc8
offset = 0
output = []
output = ''
remaining = size
hex_filehandle = struct.pack("<I", filehandle)
@@ -163,13 +163,12 @@ class LenovoFirmwareConfig(object):
remaining -= blocksize
offset += blocksize
response = self.connection.raw_command(netfn=IMM_NETFN,
command=IMM_COMMAND,
data=data)
response = self.connection.xraw_command(netfn=IMM_NETFN,
command=IMM_COMMAND,
data=data)
output += response['data'][5:]
return ''.join(chr(c) for c in output)
return output
def factory_reset(self):
options = self.get_fw_options()

View File

@@ -139,7 +139,7 @@ class IMMClient(object):
# Do not enumerate hidden settings
continue
retcfg[opt] = {}
retcfg[opt]['current'] = self.fwo[opt]['current']
retcfg[opt]['value'] = self.fwo[opt]['current']
retcfg[opt]['default'] = self.fwo[opt]['default']
retcfg[opt]['help'] = self.fwo[opt]['help']
retcfg[opt]['possible'] = self.fwo[opt]['possible']
@@ -150,6 +150,7 @@ class IMMClient(object):
self.fwc = config.LenovoFirmwareConfig(self.ipmicmd)
if not self.fwo or util._monotonic_time() - self.fwovintage > 30:
self.fwo = self.fwc.get_fw_options()
self.fwovintage = util._monotonic_time()
for key in list(changeset):
if key not in self.fwo:
for rkey in self.fwo: