# coding=utf8 # Copyright 2016-2023 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 base64 import binascii from datetime import datetime import errno import fnmatch import json import math import os.path import random import re import socket import struct import weakref import six import zipfile import pyghmi.constants as pygconst import pyghmi.exceptions as pygexc import pyghmi.ipmi.oem.lenovo.config as config import pyghmi.ipmi.oem.lenovo.energy as energy import pyghmi.ipmi.private.session as ipmisession import pyghmi.ipmi.private.util as util from pyghmi.ipmi import sdr import pyghmi.media as media import pyghmi.storage as storage from pyghmi.util.parse import parse_time import pyghmi.util.webclient as webclient try: from urllib import urlencode except ImportError: from urllib.parse import urlencode numregex = re.compile('([0-9]+)') funtypes = { 0: 'RAID Controller', 1: 'Ethernet', 2: 'Fibre Channel', 3: 'Infiniband', 4: 'GPU', 10: 'NVMe Controller', 12: 'Fabric Controller', } def naturalize_string(key): """Analyzes string in a human way to enable natural sort :param key: string for the split :returns: A structure that can be consumed by 'sorted' """ return [int(text) if text.isdigit() else text.lower() for text in re.split(numregex, key)] def natural_sort(iterable): """Return a sort using natural sort if possible :param iterable: :return: """ try: return sorted(iterable, key=naturalize_string) except TypeError: # The natural sort attempt failed, fallback to ascii sort return sorted(iterable) def fixup_uuid(uuidprop): baduuid = ''.join(uuidprop.split()) uuidprefix = (baduuid[:8], baduuid[8:12], baduuid[12:16]) a = struct.pack('