2
0
mirror of https://opendev.org/x/pyghmi synced 2026-06-16 08:30:52 +00:00
Files
pyghmi/pyghmi/ipmi/private/util.py
T
luyf5 ca9810ca3a Support RS160
https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/919828c30e8c6540f98363885aeb9b69e01b2092 153295)As an user I want to get the inventory information of RS160
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/bec53c4b29f7bade6820d5bc6cba0d2c76e80c7a Fixes problems in previous commit regarding support of RS160
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/fa25b97c891e6edef64267c60cc9fb3e23f01079 (60750) [legacy_Server][Kent2U4N] Get a wrong UUID of the Kent
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/2856c78477aa4081479ed3b55d229b5a4bd31a2a Refine the code in parse_firmware_info to get the firmware version
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/1313280d4035b4417a02b8d82b9a353ff1cfb535 (66249)[legacy_Server]Unreasonable firmware GUI diaplay for RS160
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/7ba0bf98698df7132333d87bb52da9b11cf833f6 (63296) PIT - LXCA Unable to manage RS160 (Endpoint inventory collection has failed)
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/39a52cb29895b2c4f1655b50a66a51c549a91269 (63715)[discovery_Inventory]Only get Memory information of B1 & B2 slot
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/2b52df7542e7b45f64be9a3c33d9a3de92f2d76d (64213)[discovery_Inventory][Riddler_Nov_SDV_LXCA][1.2.1-41]Motherboard LED & LXCA Light Path LED behavior are mismatch when trigger sensor
   https://gitlab.icelab.lenovo.com/pygcon/pyghmi/commit/fa20ef890cc2119a8038a772daab77dd6cfa04ca (67305)[discovery_inventory]When memory install solt 3 and slot 4,Memory Installed Bay Number display error on LXCA Inventory Details page.

Change-Id: I291ca294ab490ce8f6913def95b2e663d6cefda2
2021-09-09 09:25:53 +08:00

135 lines
3.8 KiB
Python

# Copyright 2015-2017 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ctypes
import functools
import os
import socket
import struct
from pyghmi.ipmi.private import constants
try:
range = xrange
except NameError:
pass
try:
buffer
except NameError:
buffer = memoryview
wintime = None
try:
wintime = ctypes.windll.kernel32.GetTickCount64
except AttributeError:
pass
def decode_wireformat_uuid(rawguid, bigendian=False):
"""Decode a wire format UUID
It handles the rather particular scheme where half is little endian
and half is big endian. It returns a string like dmidecode would output.
"""
if isinstance(rawguid, list):
rawguid = bytearray(rawguid)
endian = '<IHH' # little endian
if bigendian:
endian = '>IHH' # big endian
lebytes = struct.unpack_from(endian, buffer(rawguid[:8]))
bebytes = struct.unpack_from('>HHI', buffer(rawguid[8:]))
return '{0:08X}-{1:04X}-{2:04X}-{3:04X}-{4:04X}{5:08X}'.format(
lebytes[0], lebytes[1], lebytes[2], bebytes[0], bebytes[1], bebytes[2])
def urlsplit(url):
"""Split an arbitrary url into protocol, host, rest
The standard urlsplit does not want to provide 'netloc' for arbitrary
protocols, this works around that.
:param url: The url to split into component parts
"""
proto, rest = url.split(':', 1)
host = ''
if rest[:2] == '//':
host, rest = rest[2:].split('/', 1)
rest = '/' + rest
return proto, host, rest
def get_ipv4(hostname):
"""Get list of ipv4 addresses for hostname
"""
addrinfo = socket.getaddrinfo(hostname, None, socket.AF_INET,
socket.SOCK_STREAM)
return [addrinfo[x][4][0] for x in range(len(addrinfo))]
def get_ipmi_error(response, suffix=""):
if 'error' in response:
return response['error'] + suffix
code = response['code']
if code == 0:
return False
command = response['command']
netfn = response['netfn']
if ((netfn, command) in constants.command_completion_codes
and code in constants.command_completion_codes[(netfn, command)]):
res = constants.command_completion_codes[(netfn, command)][code]
res += suffix
elif code in constants.ipmi_completion_codes:
res = constants.ipmi_completion_codes[code] + suffix
else:
res = "Unknown code 0x%2x encountered" % code
return res
def _monotonic_time():
"""Provides a monotonic timer
This code is concerned with relative, not absolute time.
This function facilitates that prior to python 3.3
"""
# Python does not provide one until 3.3, so we make do
# for most OSes, os.times()[4] works well.
# for microsoft, GetTickCount64
if wintime:
return wintime() / 1000.0
return os.times()[4]
class protect(object):
def __init__(self, lock):
self.lock = lock
def __call__(self, func):
@functools.wraps(func)
def _wrapper(*args, **kwargs):
self.lock.acquire()
try:
return func(*args, **kwargs)
finally:
self.lock.release()
return _wrapper
def __enter__(self):
self.lock.acquire()
def __exit__(self, exc_type, exc_value, traceback):
self.lock.release()