From 8cfc9e6d2204e67c8124d824116c34163d7035b7 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Tue, 30 Apr 2019 08:53:54 -0400 Subject: [PATCH] Add GetSupportedFirmwareUpdateMethods to redfish_facts/Update commands (#54268) * Add GetSupportedFirmwareUpdateMethods to update category commands list * Add condition when command == GetSupportedFirmwareUpdateMethods to call the forthcoming rf_utils function get_supported_firmware_update_methods * Implement get_supporte_firmware_update_methods() in redfish_utils * rename command to GetFirmwareUpdateCapabilities * rename comand get_firmware_update_capabilities() * Rename command get_firmware_update_capabilities() * Group update protocols by the type of Action they are associated with. * remove trailing whitespace * Use safer method to get 'title' for each action type and its allowablevalues * Add example to docstring for using GetFirmwareUpdateCapabilities * fix line too long * fix line too long and trailing whitespace * Update redfish_utils.py * remove trailing whitespace * fix overindent * Use self.update_uri instead of hard-coding '/redfish/v1' in get_firmware_update_capabilities() --- lib/ansible/module_utils/redfish_utils.py | 35 ++++++++++++++++--- .../redfish/redfish_facts.py | 12 ++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 00e2f610ee..083b4c3c4c 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -630,6 +630,35 @@ class RedfishUtils(object): return response return {'ret': True} + def get_firmware_update_capabilities(self): + result = {} + response = self.get_request(self.root_uri + self.update_uri) + if response['ret'] is False: + return response + + result['ret'] = True + + result['entries'] = {} + + data = response['data'] + + if "Actions" in data: + actions = data['Actions'] + if len(actions) > 0: + for key in actions.keys(): + action = actions.get(key) + if 'title' in action: + title = action['title'] + else: + title = key + result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', + ["Key TransferProtocol@Redfish.AllowableValues not found"]) + else: + return {'ret': "False", 'msg': "Actions list is empty."} + else: + return {'ret': "False", 'msg': "Key Actions not found."} + return result + def get_firmware_inventory(self): result = {} response = self.get_request(self.root_uri + self.firmware_uri) @@ -727,16 +756,14 @@ class RedfishUtils(object): boot_options_dict = {} for member in members: if '@odata.id' not in member: - return {'ret': False, - 'msg': "@odata.id not found in BootOptions"} + return {'ret': False, 'msg': "@odata.id not found in BootOptions"} boot_option_uri = member['@odata.id'] response = self.get_request(self.root_uri + boot_option_uri) if response['ret'] is False: return response data = response['data'] if 'BootOptionReference' not in data: - return {'ret': False, - 'msg': "BootOptionReference not found in BootOption"} + return {'ret': False, 'msg': "BootOptionReference not found in BootOption"} boot_option_ref = data['BootOptionReference'] # fetch the props to display for this boot device diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index a8c9faefed..8a8ae59346 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -137,6 +137,14 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" + - name: Get firmware update capability information + redfish_facts: + category: Update + command: GetFirmwareUpdateCapabilities + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + - name: Get all information available in all categories redfish_facts: category: all @@ -164,7 +172,7 @@ CATEGORY_COMMANDS_ALL = { "GetBiosAttributes", "GetBootOrder"], "Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisThermals"], "Accounts": ["ListUsers"], - "Update": ["GetFirmwareInventory"], + "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"], "Manager": ["GetManagerNicInventory", "GetLogs"], } @@ -293,6 +301,8 @@ def main(): for command in command_list: if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() + elif command == "GetFirmwareUpdateCapabilities": + result["firmware_update_capabilities"] = rf_utils.get_firmware_update_capabilities() elif category == "Manager": # execute only if we find a Manager service resource