diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index f48624f6c1..23491ae6eb 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -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 = [] diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index 6ed6672789..1cd3bc6503 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -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":