From e09172ab893e9d4a0102ce414d1e0ed99595ab9f Mon Sep 17 00:00:00 2001 From: xmadsen Date: Fri, 22 Mar 2019 17:26:53 -0400 Subject: [PATCH 01/16] Add GetSupportedFirmwareUpdateMethods to update category commands list --- lib/ansible/modules/remote_management/redfish/redfish_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index d37e1e566a2737..ba9b18c3ddd155 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -134,7 +134,7 @@ "GetDiskInventory", "GetBiosAttributes", "GetBootOrder"], "Chassis": ["GetFanInventory"], "Accounts": ["ListUsers"], - "Update": ["GetFirmwareInventory"], + "Update": ["GetFirmwareInventory", "GetSupportedFirmwareUpdateMethods"], "Manager": ["GetManagerNicInventory", "GetLogs"], } From f303c68464bcd72b60fe3379711ea39ad423d0d1 Mon Sep 17 00:00:00 2001 From: xmadsen Date: Fri, 22 Mar 2019 17:35:00 -0400 Subject: [PATCH 02/16] Add condition when command == GetSupportedFirmwareUpdateMethods to call the forthcoming rf_utils function get_supported_firmware_update_methods --- lib/ansible/modules/remote_management/redfish/redfish_facts.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index ba9b18c3ddd155..763c7f31ffcd7f 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -255,6 +255,8 @@ def main(): for command in command_list: if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() + elif command == "GetSupportedFirmwareUpdateMethods": + result["firmware_update_methods"] = rf_utils.get_supported_firmware_update_methods() elif category == "Manager": # execute only if we find a Manager service resource From 246cf4e6c0125eb5f222ff827fff1ebd5c8e0b64 Mon Sep 17 00:00:00 2001 From: xmadsen Date: Fri, 22 Mar 2019 18:02:44 -0400 Subject: [PATCH 03/16] Implement get_supporte_firmware_update_methods() in redfish_utils --- lib/ansible/module_utils/redfish_utils.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index c32b57bb4c6f7f..ace04ceb21dca1 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -511,6 +511,32 @@ def update_user_password(self, user): return response return {'ret': True} + def get_supported_firmware_update_methods(self): + result = {} + response = self.get_request(self.root_uri + "/redfish/v1") + + if response['ret'] is False: + return response + + result['ret'] = True + + result['entries'] = [] + data = response['data'] + if "UpdateService" in data: + response = self.get_request(self.root_uri + "/redfish/v1/UpdateService") + + data = response['data'] + + if "Actions" in data: + if "#UpdateService.SimpleUpdate" in data["Actions"]: + if "TransferProtocol@Redfish.AllowableValues" in data["Actions"]["#UpdateService.SimpleUpdate"]: + result['entries'] = data["Actions"]["#UpdateService.SimpleUpdate"]["TransferProtocol@Redfish.AllowableValues"] + else: + return {'ret': "False", 'msg': "Key Actions not found."} + else: + return {'ret': "False", 'msg': "Key UpdateService not found."} + return result + def get_firmware_inventory(self): result = {} response = self.get_request(self.root_uri + self.firmware_uri) From 76edcb77ecfd1a641511296cadf24aaff7dc1acd Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Mon, 8 Apr 2019 15:23:27 -0400 Subject: [PATCH 04/16] rename command to GetFirmwareUpdateCapabilities --- .../modules/remote_management/redfish/redfish_facts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index 763c7f31ffcd7f..a6b6222bdb5710 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -134,7 +134,7 @@ "GetDiskInventory", "GetBiosAttributes", "GetBootOrder"], "Chassis": ["GetFanInventory"], "Accounts": ["ListUsers"], - "Update": ["GetFirmwareInventory", "GetSupportedFirmwareUpdateMethods"], + "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"], "Manager": ["GetManagerNicInventory", "GetLogs"], } @@ -255,7 +255,7 @@ def main(): for command in command_list: if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() - elif command == "GetSupportedFirmwareUpdateMethods": + elif command == "GetFirmwareUpdateCapabilities": result["firmware_update_methods"] = rf_utils.get_supported_firmware_update_methods() elif category == "Manager": From 0a9c84c9a84bba24b35d677de30dccaacd4446d1 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Mon, 8 Apr 2019 15:25:28 -0400 Subject: [PATCH 05/16] rename comand get_firmware_update_capabilities() --- lib/ansible/modules/remote_management/redfish/redfish_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index a6b6222bdb5710..fcbd57de5eff04 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -256,7 +256,7 @@ def main(): if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() elif command == "GetFirmwareUpdateCapabilities": - result["firmware_update_methods"] = rf_utils.get_supported_firmware_update_methods() + result["firmware_update_methods"] = rf_utils.get_firmware_update_capabilities() elif category == "Manager": # execute only if we find a Manager service resource From 8b725802ab574b698e5579a1a52c36ba7061ea73 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Mon, 8 Apr 2019 15:25:56 -0400 Subject: [PATCH 06/16] Rename command get_firmware_update_capabilities() --- lib/ansible/module_utils/redfish_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index ace04ceb21dca1..4772cfbcc1c743 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -511,7 +511,7 @@ def update_user_password(self, user): return response return {'ret': True} - def get_supported_firmware_update_methods(self): + def get_firmware_update_capabilities(self): result = {} response = self.get_request(self.root_uri + "/redfish/v1") From 96745c079eff1d1465ca2fcb93a7c7c756d77d9e Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Mon, 8 Apr 2019 15:43:57 -0400 Subject: [PATCH 07/16] Group update protocols by the type of Action they are associated with. --- lib/ansible/module_utils/redfish_utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 4772cfbcc1c743..0936920dd99e17 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -514,23 +514,27 @@ def update_user_password(self, user): def get_firmware_update_capabilities(self): result = {} response = self.get_request(self.root_uri + "/redfish/v1") - if response['ret'] is False: return response result['ret'] = True - result['entries'] = [] + result['entries'] = {} + data = response['data'] if "UpdateService" in data: - response = self.get_request(self.root_uri + "/redfish/v1/UpdateService") + updateservce_uri = data['UpdateService']["@odata.id"] + response = self.get_request(self.root_uri + updateservce_uri) data = response['data'] if "Actions" in data: - if "#UpdateService.SimpleUpdate" in data["Actions"]: - if "TransferProtocol@Redfish.AllowableValues" in data["Actions"]["#UpdateService.SimpleUpdate"]: - result['entries'] = data["Actions"]["#UpdateService.SimpleUpdate"]["TransferProtocol@Redfish.AllowableValues"] + actions = data['Actions'] + if len(actions) > 0: + for action in actions.values(): + result['entries'][action['title']] = action['TransferProtocol@Redfish.AllowableValues'] + else: + return {'ret': "False", 'msg': "Actions list is empty."} else: return {'ret': "False", 'msg': "Key Actions not found."} else: From 9c7357e7a960aa6409e6a0f9b5cd075662df4f82 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Mon, 8 Apr 2019 15:57:04 -0400 Subject: [PATCH 08/16] remove trailing whitespace --- lib/ansible/module_utils/redfish_utils.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 0936920dd99e17..da012ceaa9aba4 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -520,7 +520,7 @@ def get_firmware_update_capabilities(self): result['ret'] = True result['entries'] = {} - + data = response['data'] if "UpdateService" in data: updateservce_uri = data['UpdateService']["@odata.id"] @@ -529,7 +529,7 @@ def get_firmware_update_capabilities(self): data = response['data'] if "Actions" in data: - actions = data['Actions'] + actions = data['Actions'] if len(actions) > 0: for action in actions.values(): result['entries'][action['title']] = action['TransferProtocol@Redfish.AllowableValues'] @@ -635,16 +635,14 @@ def get_boot_order(self): 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 From 1af09b5c0597e521bcd702022f79c8a9ef6c4e9e Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 09:54:26 -0400 Subject: [PATCH 09/16] Use safer method to get 'title' for each action type and its allowablevalues --- lib/ansible/module_utils/redfish_utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index da012ceaa9aba4..ee60ba032f9adf 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -531,8 +531,13 @@ def get_firmware_update_capabilities(self): if "Actions" in data: actions = data['Actions'] if len(actions) > 0: - for action in actions.values(): - result['entries'][action['title']] = action['TransferProtocol@Redfish.AllowableValues'] + 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: From 0313f4169d5b4308cc6cf27bd6a22be84a54840f Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 09:58:33 -0400 Subject: [PATCH 10/16] Add example to docstring for using GetFirmwareUpdateCapabilities --- .../modules/remote_management/redfish/redfish_facts.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index fcbd57de5eff04..c4f9807e98888e 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -108,6 +108,14 @@ 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 @@ -256,7 +264,7 @@ def main(): if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() elif command == "GetFirmwareUpdateCapabilities": - result["firmware_update_methods"] = rf_utils.get_firmware_update_capabilities() + result["firmware_update_capabilities"] = rf_utils.get_firmware_update_capabilities() elif category == "Manager": # execute only if we find a Manager service resource From 4d69eb479e1a16616c63b218e7a426d2247e7bd6 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 10:27:26 -0400 Subject: [PATCH 11/16] fix line too long --- lib/ansible/module_utils/redfish_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index ee60ba032f9adf..4f593241d57a43 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -537,7 +537,8 @@ def get_firmware_update_capabilities(self): title = action['title'] else: title = key - result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', ["Key TransferProtocol@Redfish.AllowableValues not found"]) + result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', + ["Key TransferProtocol@Redfish.AllowableValues not found"]) else: return {'ret': "False", 'msg': "Actions list is empty."} else: From ebdb98edc610535163e3536c53ee5f564d054e8d Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 10:39:52 -0400 Subject: [PATCH 12/16] fix line too long and trailing whitespace --- lib/ansible/module_utils/redfish_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 4f593241d57a43..ee60ba032f9adf 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -537,8 +537,7 @@ def get_firmware_update_capabilities(self): title = action['title'] else: title = key - result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', - ["Key TransferProtocol@Redfish.AllowableValues not found"]) + result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', ["Key TransferProtocol@Redfish.AllowableValues not found"]) else: return {'ret': "False", 'msg': "Actions list is empty."} else: From 39cda21cf9da6aea1a0b5468af02d63875c35128 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 10:54:51 -0400 Subject: [PATCH 13/16] Update redfish_utils.py --- lib/ansible/module_utils/redfish_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index ee60ba032f9adf..ad214a520837a2 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -537,7 +537,8 @@ def get_firmware_update_capabilities(self): title = action['title'] else: title = key - result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', ["Key TransferProtocol@Redfish.AllowableValues not found"]) + result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', + ["Key TransferProtocol@Redfish.AllowableValues not found"]) else: return {'ret': "False", 'msg': "Actions list is empty."} else: From ff9d0012e1a31576bb32d0d52fbb32a1cad0d117 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 10:57:59 -0400 Subject: [PATCH 14/16] remove trailing whitespace --- lib/ansible/module_utils/redfish_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index ad214a520837a2..94be9873fd2764 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -537,7 +537,7 @@ def get_firmware_update_capabilities(self): title = action['title'] else: title = key - result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', + result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', ["Key TransferProtocol@Redfish.AllowableValues not found"]) else: return {'ret': "False", 'msg': "Actions list is empty."} From 403b068aa2687727d08ed78e7e1b56048d609d42 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Wed, 10 Apr 2019 11:02:59 -0400 Subject: [PATCH 15/16] fix overindent --- lib/ansible/module_utils/redfish_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 94be9873fd2764..cce4a191250c29 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -538,7 +538,7 @@ def get_firmware_update_capabilities(self): else: title = key result['entries'][title] = action.get('TransferProtocol@Redfish.AllowableValues', - ["Key TransferProtocol@Redfish.AllowableValues not found"]) + ["Key TransferProtocol@Redfish.AllowableValues not found"]) else: return {'ret': "False", 'msg': "Actions list is empty."} else: From 850eab0b54caedb41f27a67622df0268b3cc2081 Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Tue, 16 Apr 2019 10:16:33 -0400 Subject: [PATCH 16/16] Use self.update_uri instead of hard-coding '/redfish/v1' in get_firmware_update_capabilities() --- lib/ansible/module_utils/redfish_utils.py | 35 +++++++++-------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index cce4a191250c29..4120297340268f 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -513,7 +513,7 @@ def update_user_password(self, user): def get_firmware_update_capabilities(self): result = {} - response = self.get_request(self.root_uri + "/redfish/v1") + response = self.get_request(self.root_uri + self.update_uri) if response['ret'] is False: return response @@ -522,29 +522,22 @@ def get_firmware_update_capabilities(self): result['entries'] = {} data = response['data'] - if "UpdateService" in data: - updateservce_uri = data['UpdateService']["@odata.id"] - response = self.get_request(self.root_uri + updateservce_uri) - 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."} + 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': "Key Actions not found."} + return {'ret': "False", 'msg': "Actions list is empty."} else: - return {'ret': "False", 'msg': "Key UpdateService not found."} + return {'ret': "False", 'msg': "Key Actions not found."} return result def get_firmware_inventory(self):