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
pull/54404/head
Xander Madsen 6 years ago committed by John R Barker
parent 414ac12ddd
commit 840ceb2777

@ -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 = []

@ -74,6 +74,14 @@ EXAMPLES = '''
- debug:
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
- name: Get memory inventory
redfish_facts:
category: Systems
command: GetMemoryInventory
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
- name: Get fan inventory with a timeout of 20 seconds
redfish_facts:
category: Chassis
@ -150,9 +158,10 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.redfish_utils import RedfishUtils
CATEGORY_COMMANDS_ALL = {
"Systems": ["GetSystemInventory", "GetCpuInventory",
"GetNicInventory", "GetStorageControllerInventory",
"GetDiskInventory", "GetBiosAttributes", "GetBootOrder"],
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
"GetMemoryInventory", "GetNicInventory",
"GetStorageControllerInventory", "GetDiskInventory",
"GetBiosAttributes", "GetBootOrder"],
"Chassis": ["GetFanInventory", "GetPsuInventory"],
"Accounts": ["ListUsers"],
"Update": ["GetFirmwareInventory"],
@ -238,6 +247,8 @@ def main():
result["system"] = rf_utils.get_multi_system_inventory()
elif command == "GetCpuInventory":
result["cpu"] = rf_utils.get_multi_cpu_inventory()
elif command == "GetMemoryInventory":
result["memory"] = rf_utils.get_multi_memory_inventory()
elif command == "GetNicInventory":
result["nic"] = rf_utils.get_multi_nic_inventory(category)
elif command == "GetStorageControllerInventory":

Loading…
Cancel
Save