Add function to calculate memory
Move logic to calculate memory to its own function. Change-Id: I5ab98b6450ff45dff35ddae093a83140f37047a8 (cherry picked from commit2738e57f2a) (cherry picked from commite03d80d572)
This commit is contained in:
committed by
Julia Kreger
parent
b6f02de4b6
commit
0c230a6f09
@@ -146,6 +146,27 @@ def _get_component_devices(raid_device):
|
||||
return component_devices
|
||||
|
||||
|
||||
def _calc_memory(sys_dict):
|
||||
physical = 0
|
||||
for sys_child in sys_dict['children']:
|
||||
if sys_child['id'] != 'core':
|
||||
continue
|
||||
for core_child in sys_child['children']:
|
||||
if not _MEMORY_ID_RE.match(core_child['id']):
|
||||
continue
|
||||
if (not core_child.get("children")
|
||||
and core_child.get('size')):
|
||||
value = ("%(size)s %(units)s" % core_child)
|
||||
physical += int(UNIT_CONVERTER(value).to
|
||||
('MB').magnitude)
|
||||
for bank in core_child.get('children', ()):
|
||||
if bank.get('size'):
|
||||
value = ("%(size)s %(units)s" % bank)
|
||||
physical += int(UNIT_CONVERTER(value).to
|
||||
('MB').magnitude)
|
||||
return physical
|
||||
|
||||
|
||||
def get_holder_disks(raid_device):
|
||||
"""Get the holder disks of a Software RAID device.
|
||||
|
||||
@@ -947,22 +968,7 @@ class GenericHardwareManager(HardwareManager):
|
||||
LOG.warning('Could not get real physical RAM from lshw: %s', e)
|
||||
physical = None
|
||||
else:
|
||||
physical = 0
|
||||
# locate memory information in system_dict
|
||||
for sys_child in sys_dict['children']:
|
||||
if sys_child['id'] == 'core':
|
||||
for core_child in sys_child['children']:
|
||||
if _MEMORY_ID_RE.match(core_child['id']):
|
||||
if (not core_child.get("children") and
|
||||
core_child.get('size')):
|
||||
value = ("%(size)s %(units)s" % core_child)
|
||||
physical += int(UNIT_CONVERTER(value).to
|
||||
('MB').magnitude)
|
||||
for bank in core_child.get('children', ()):
|
||||
if bank.get('size'):
|
||||
value = ("%(size)s %(units)s" % bank)
|
||||
physical += int(UNIT_CONVERTER(value).to
|
||||
('MB').magnitude)
|
||||
physical = _calc_memory(sys_dict)
|
||||
|
||||
if not physical:
|
||||
LOG.warning('Did not find any physical RAM')
|
||||
|
||||
Reference in New Issue
Block a user