Add GetMemoryInventory command to Systems category in redfish facts module (#54125)

* Add GetMemoryInventory command to CATEGORY_COMMANDS_ALL['Systems']

* Add elif command == GetMemoryInventory to Systems category, to use forthcoming get_memory_inventory() function from redfish_utils

* Add get_memory_inventory() function to redfish_utils.py, which does not include any Absent dimms

* Remove trailing whitespace

* Add get_multi_memory_inventory() function to aggregate get_memory_inventory

* Call new function get_multi_memory_inventory()

* Add memory example in docstring

* Fix comment referring to CPUs instead of DIMMs
This commit is contained in:
Xander Madsen 2019-04-04 02:56:23 -04:00 committed by John R Barker
parent 414ac12ddd
commit 840ceb2777
2 changed files with 72 additions and 4 deletions

View file

@ -280,7 +280,7 @@ class RedfishUtils(object):
ret = inventory.pop('ret') and ret
if 'entries' in inventory:
entries.append(({'systems_uri': systems_uri},
inventory['entries']))
inventory['entries']))
return dict(ret=ret, entries=entries)
def get_storage_controller_inventory(self, systems_uri):
@ -903,6 +903,63 @@ class RedfishUtils(object):
def get_multi_cpu_inventory(self):
return self.aggregate(self.get_cpu_inventory)
def get_memory_inventory(self, systems_uri):
result = {}
memory_list = []
memory_results = []
key = "Memory"
# Get these entries, but does not fail if not found
properties = ['SerialNumber', 'MemoryDeviceType', 'PartNuber',
'MemoryLocation', 'RankCount', 'CapacityMiB', 'OperatingMemoryModes', 'Status', 'Manufacturer', 'Name']
# Search for 'key' entry and extract URI from it
response = self.get_request(self.root_uri + systems_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
if key not in data:
return {'ret': False, 'msg': "Key %s not found" % key}
memory_uri = data[key]["@odata.id"]
# Get a list of all DIMMs and build respective URIs
response = self.get_request(self.root_uri + memory_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
for dimm in data[u'Members']:
memory_list.append(dimm[u'@odata.id'])
for m in memory_list:
dimm = {}
uri = self.root_uri + m
response = self.get_request(uri)
if response['ret'] is False:
return response
data = response['data']
if "Status" in data:
if "State" in data["Status"]:
if data["Status"]["State"] == "Absent":
continue
else:
continue
for property in properties:
if property in data:
dimm[property] = data[property]
memory_results.append(dimm)
result["entries"] = memory_results
return result
def get_multi_memory_inventory(self):
return self.aggregate(self.get_memory_inventory)
def get_nic_inventory(self, resource_uri):
result = {}
nic_list = []