diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 9900d65da3b..1a2d1646b51 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -911,42 +911,53 @@ class RedfishUtils(object): result = {} psu_list = [] psu_results = [] - key = "PoweredBy" + key = "PowerSupplies" # Get these entries, but does not fail if not found properties = ['Name', 'Model', 'SerialNumber', 'PartNumber', 'Manufacturer', 'FirmwareVersion', 'PowerCapacityWatts', 'PowerSupplyType', 'Status'] - # Get a list of all PSUs and build respective URIs - response = self.get_request(self.root_uri + self.systems_uri) - if response['ret'] is False: - return response - result['ret'] = True - data = response['data'] - - if 'Links' not in data: - return {'ret': False, 'msg': "Property not found"} - if key not in data[u'Links']: - return {'ret': False, 'msg': "Key %s not found" % key} - - for psu in data[u'Links'][u'PoweredBy']: - psu_list.append(psu[u'@odata.id']) - - for p in psu_list: - psu = {} - uri = self.root_uri + p - response = self.get_request(uri) + # Get a list of all Chassis and build URIs, then get all PowerSupplies + # from each Power entry in the Chassis + chassis_uri_list = self.chassis_uri_list + for chassis_uri in chassis_uri_list: + response = self.get_request(self.root_uri + chassis_uri) if response['ret'] is False: return response result['ret'] = True data = response['data'] - for property in properties: - if property in data: - psu[property] = data[property] - psu_results.append(psu) + if 'Power' in data: + power_uri = data[u'Power'][u'@odata.id'] + else: + continue + + response = self.get_request(self.root_uri + power_uri) + data = response['data'] + + if key not in data: + return {'ret': False, 'msg': "Key %s not found" % key} + + psu_list = data[key] + for psu in psu_list: + psu_not_present = False + psu_data = {} + for property in properties: + if property in psu: + if psu[property] is not None: + if property == 'Status': + if 'State' in psu[property]: + if psu[property]['State'] == 'Absent': + psu_not_present = True + psu_data[property] = psu[property] + if psu_not_present: + continue + psu_results.append(psu_data) + result["entries"] = psu_results + if not result["entries"]: + return {'ret': False, 'msg': "No PowerSupply objects found"} return result def get_system_inventory(self): diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index d37e1e566a2..ff64817179a 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -73,7 +73,7 @@ EXAMPLES = ''' - name: Get several inventories redfish_facts: category: Systems - command: GetNicInventory,GetPsuInventory,GetBiosAttributes + command: GetNicInventory,GetBiosAttributes baseuri: "{{ baseuri }}" username: "{{ username }}" password: "{{ password }}" @@ -129,10 +129,10 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.redfish_utils import RedfishUtils CATEGORY_COMMANDS_ALL = { - "Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory", + "Systems": ["GetSystemInventory", "GetCpuInventory", "GetNicInventory", "GetStorageControllerInventory", "GetDiskInventory", "GetBiosAttributes", "GetBootOrder"], - "Chassis": ["GetFanInventory"], + "Chassis": ["GetFanInventory", "GetPsuInventory"], "Accounts": ["ListUsers"], "Update": ["GetFirmwareInventory"], "Manager": ["GetManagerNicInventory", "GetLogs"], @@ -211,8 +211,6 @@ def main(): for command in command_list: if command == "GetSystemInventory": result["system"] = rf_utils.get_system_inventory() - elif command == "GetPsuInventory": - result["psu"] = rf_utils.get_psu_inventory() elif command == "GetCpuInventory": result["cpu"] = rf_utils.get_cpu_inventory() elif command == "GetNicInventory": @@ -235,6 +233,8 @@ def main(): for command in command_list: if command == "GetFanInventory": result["fan"] = rf_utils.get_fan_inventory() + elif command == "GetPsuInventory": + result["psu"] = rf_utils.get_psu_inventory() elif category == "Accounts": # execute only if we find an Account service resource