mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add GetChassisPower command to Chassis category of redfish_facts (#54314)
* Add GetChassisPower as viable Chassis command in redfish_facts * Add conditional to catch command == 'GetChassisPower' * Implement get_chassis_power() retrieving Watts-related and other useful power data from each Chassis * Add RelatedItem property and remove MemberId property * Check for length of data['PowerControl'] to be > 0 before checking index 0 of the list. * Fix return statement being inside loop and result key not being 'entries' as is expected * Update lib/ansible/module_utils/redfish_utils.py Co-Authored-By: xmadsen <xander.madsen@gmail.com> * Update lib/ansible/module_utils/redfish_utils.py Co-Authored-By: xmadsen <xander.madsen@gmail.com> * Update redfish_facts.py
This commit is contained in:
parent
9f830b77fc
commit
eb7190264e
2 changed files with 41 additions and 1 deletions
|
@ -920,6 +920,44 @@ class RedfishUtils(object):
|
||||||
result["entries"] = fan_results
|
result["entries"] = fan_results
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_chassis_power(self):
|
||||||
|
result = {}
|
||||||
|
key = "Power"
|
||||||
|
|
||||||
|
# Get these entries, but does not fail if not found
|
||||||
|
properties = ['Name', 'PowerAllocatedWatts',
|
||||||
|
'PowerAvailableWatts', 'PowerCapacityWatts',
|
||||||
|
'PowerConsumedWatts', 'PowerMetrics',
|
||||||
|
'PowerRequestedWatts', 'RelatedItem', 'Status']
|
||||||
|
|
||||||
|
chassis_power_results = []
|
||||||
|
# Go through list
|
||||||
|
for chassis_uri in self.chassis_uri_list:
|
||||||
|
chassis_power_result = {}
|
||||||
|
response = self.get_request(self.root_uri + chassis_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
if key in data:
|
||||||
|
response = self.get_request(self.root_uri + chassis_uri +
|
||||||
|
"/" + key)
|
||||||
|
data = response['data']
|
||||||
|
if 'PowerControl' in data:
|
||||||
|
if len(data['PowerControl']) > 0:
|
||||||
|
data = data['PowerControl'][0]
|
||||||
|
for property in properties:
|
||||||
|
if property in data:
|
||||||
|
chassis_power_result[property] = data[property]
|
||||||
|
else:
|
||||||
|
return {'ret': False, 'msg': 'Key PowerControl not found.'}
|
||||||
|
chassis_power_results.append(chassis_power_result)
|
||||||
|
else:
|
||||||
|
return {'ret': False, 'msg': 'Key Power not found.'}
|
||||||
|
|
||||||
|
result['entries'] = chassis_power_results
|
||||||
|
return result
|
||||||
|
|
||||||
def get_chassis_thermals(self):
|
def get_chassis_thermals(self):
|
||||||
result = {}
|
result = {}
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
|
@ -170,7 +170,7 @@ CATEGORY_COMMANDS_ALL = {
|
||||||
"GetMemoryInventory", "GetNicInventory",
|
"GetMemoryInventory", "GetNicInventory",
|
||||||
"GetStorageControllerInventory", "GetDiskInventory",
|
"GetStorageControllerInventory", "GetDiskInventory",
|
||||||
"GetBiosAttributes", "GetBootOrder"],
|
"GetBiosAttributes", "GetBootOrder"],
|
||||||
"Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisThermals"],
|
"Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisPower", "GetChassisThermals"],
|
||||||
"Accounts": ["ListUsers"],
|
"Accounts": ["ListUsers"],
|
||||||
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"],
|
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"],
|
||||||
"Manager": ["GetManagerNicInventory", "GetLogs"],
|
"Manager": ["GetManagerNicInventory", "GetLogs"],
|
||||||
|
@ -281,6 +281,8 @@ def main():
|
||||||
result["psu"] = rf_utils.get_psu_inventory()
|
result["psu"] = rf_utils.get_psu_inventory()
|
||||||
elif command == "GetChassisThermals":
|
elif command == "GetChassisThermals":
|
||||||
result["thermals"] = rf_utils.get_chassis_thermals()
|
result["thermals"] = rf_utils.get_chassis_thermals()
|
||||||
|
elif command == "GetChassisPower":
|
||||||
|
result["chassis_power"] = rf_utils.get_chassis_power()
|
||||||
|
|
||||||
elif category == "Accounts":
|
elif category == "Accounts":
|
||||||
# execute only if we find an Account service resource
|
# execute only if we find an Account service resource
|
||||||
|
|
Loading…
Reference in a new issue