From 3b1704bc2f5469b54a702941a8d5e2e254f1a498 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 18 Jan 2022 12:22:10 -0500 Subject: [PATCH] Adapt to more variants in the capacitystr The capacity str may be GB or GiB or TB or TiB now. Unfortunately, there's no normalized numeric in the api right now. Change-Id: Iccfb6e837a0f2d5ac516c3e908c663bbddda2ed3 --- pyghmi/ipmi/oem/lenovo/imm.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 4dd15b4b..a889400d 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -99,6 +99,22 @@ def fixup_str(propstr): ' \xff\x00') +def str_to_size(sizestr): + if 'GB' in sizestr: + sizestr = sizestr.replace('GB', '') + sizestr = int(float(sizestr * 1024)) + elif 'GiB' in sizestr: + sizestr = sizestr.replace('GiB', '') + sizestr = int(float(sizestr * 1024)) + elif 'TB' in sizestr: + sizestr = sizestr.replace('TB', '') + sizestr = int(float(sizestr * 1000 * 1000)) + elif 'TiB' in sizestr: + sizestr = sizestr.replace('TiB', '') + sizestr = int(float(sizestr * 1024 * 1024)) + return sizestr + + class IMMClient(object): logouturl = '/data/logout' bmcname = 'IMM' @@ -1502,12 +1518,8 @@ class XCCClient(IMMClient): spares.append(diskinfo) else: disks.append(diskinfo) - totalsize = pool['totalCapacityStr'].replace( - 'GB', '').replace('GiB', '') - totalsize = int(float(totalsize) * 1024) - freesize = pool['freeCapacityStr'].replace( - 'GB', '').replace('GiB', '') - freesize = int(float(freesize) * 1024) + totalsize = str_to_size(pool['totalCapacityStr']) + freesize = str_to_size(pool['freeCapacityStr']) pools.append(storage.Array( disks=disks, raid=pool['rdlvlstr'], volumes=volumes, id=(cid, pool['id']), hotspares=spares,