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

Support for Get Device GUID #171

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions pyipmi/bmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Bmc(object):
def get_device_id(self):
return DeviceId(self.send_message_with_name('GetDeviceId'))

def get_device_guid(self):
return DeviceGuid(self.send_message_with_name('GetDeviceGuid'))

def cold_reset(self):
self.send_message_with_name('ColdReset')

Expand Down Expand Up @@ -121,6 +124,7 @@ def __str__(self):
string += ' ipmi: %s' % self.ipmi_version
string += ' manufacturer: %d' % self.manufacturer_id
string += ' product: %d' % self.product_id
string += ' functions: %s' % ','.join(self.supported_functions)
return string

def supports_function(self, name):
Expand Down Expand Up @@ -164,3 +168,14 @@ def _from_response(self, rsp):
self.aux = None
if rsp.auxiliary is not None:
self.aux = list(rsp.auxiliary)


class DeviceGuid(State):
def __str__(self):
return 'Device GUID: %s' % self.device_guid_string

def _from_response(self, rsp):
self.device_guid = rsp.device_guid
self.device_guid_string = \
'%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-' \
'%02x%02x%02x%02x%02x%02x' % tuple(reversed(self.device_guid))
10 changes: 6 additions & 4 deletions pyipmi/msgs/bmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,19 @@ class GetAcpiPowerStateRsp(Message):


@register_message_class
class GetDeviceGuideReq(Message):
class GetDeviceGuidReq(Message):
__cmdid__ = constants.CMDID_GET_DEVICE_GUID
__netfn__ = constants.NETFN_APP
__not_implemented__ = True


@register_message_class
class GetDeviceGuideRsp(Message):
class GetDeviceGuidRsp(Message):
__cmdid__ = constants.CMDID_GET_DEVICE_GUID
__netfn__ = constants.NETFN_APP | 1
__not_implemented__ = True
__fields__ = (
CompletionCode(),
ByteArray('device_guid', 16),
)


@register_message_class
Expand Down
2 changes: 1 addition & 1 deletion pyipmi/msgs/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create(self):
if self.default is not None:
return array('B', self.default)
else:
return array('B', self.length * '\x00')
return array('B', self.length * b'\x00')


class VariableByteArray(ByteArray):
Expand Down
15 changes: 15 additions & 0 deletions tests/msgs/test_bmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ def test_getdeviceid_decode_valid_rsp_wo_aux():
assert m.product_id == 5310


def test_getdeviceguid_decode_req():
m = pyipmi.msgs.bmc.GetDeviceGuidReq()
decode_message(m, b'')


def test_getdeviceguid_decode_valid_rsp():
m = pyipmi.msgs.bmc.GetDeviceGuidRsp()
decode_message(m, b'\x00\xff\xee\xdd\xcc\xbb\xaa'
b'\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00')
assert m.completion_code == 0x00
assert m.device_guid == array('B', [0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa,
0x99, 0x88, 0x77, 0x66, 0x55, 0x44,
0x33, 0x22, 0x11, 0x00])


def test_getselftestresults_decode_test_passed_rsp():
m = pyipmi.msgs.bmc.GetSelftestResultsRsp()
decode_message(m, b'\x00\x55\x00')
Expand Down
10 changes: 9 additions & 1 deletion tests/test_bmc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyipmi.bmc import DeviceId, Watchdog
from pyipmi.bmc import DeviceId, DeviceGuid, Watchdog
import pyipmi.msgs.bmc
from pyipmi.msgs import decode_message

Expand Down Expand Up @@ -47,3 +47,11 @@ def test_deviceid_object_with_aux():

device_id = DeviceId(msg)
assert device_id.aux == [1, 2, 3, 4]


def test_deviceguid_object():
m = pyipmi.msgs.bmc.GetDeviceGuidRsp()
decode_message(m, b'\x00\xff\xee\xdd\xcc\xbb\xaa'
b'\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00')
guid = DeviceGuid(m)
assert guid.device_guid_string == '00112233-4455-6677-8899-aabbccddeeff'
Loading