Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redfish_facts GetPsuInventory command not returning correct output #52675

Merged
merged 9 commits into from
Mar 6, 2019
59 changes: 35 additions & 24 deletions lib/ansible/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,42 +866,53 @@ def get_psu_inventory(self):
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):
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/remote_management/redfish/redfish_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
- name: Get several inventories
redfish_facts:
category: Systems
command: GetNicInventory,GetPsuInventory,GetBiosAttributes
command: GetNicInventory,GetBiosAttributes
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
Expand Down Expand Up @@ -129,10 +129,10 @@
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"],
Expand Down Expand Up @@ -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":
Expand All @@ -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
Expand Down