From c9a669e42c3fd90ec9d6d28c60a0f56f1bd302a8 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Tue, 29 Oct 2019 08:15:42 -0500 Subject: [PATCH] add GetSoftwareInventory command (#62811) --- lib/ansible/module_utils/redfish_utils.py | 35 +++++++++++++------ .../remote_management/redfish/redfish_info.py | 20 ++++++++++- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 9454253b93a..b8c64048761 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -230,8 +230,11 @@ class RedfishUtils(object): if response['ret'] is False: return response data = response['data'] - firmware_inventory = data['FirmwareInventory'][u'@odata.id'] - self.firmware_uri = firmware_inventory + self.firmware_uri = self.software_uri = None + if 'FirmwareInventory' in data: + self.firmware_uri = data['FirmwareInventory'][u'@odata.id'] + if 'SoftwareInventory' in data: + self.software_uri = data['SoftwareInventory'][u'@odata.id'] return {'ret': True} def _find_chassis_resource(self): @@ -1133,33 +1136,45 @@ class RedfishUtils(object): return {'ret': "False", 'msg': "Key Actions not found."} return result - def get_firmware_inventory(self): + def _software_inventory(self, uri): result = {} - response = self.get_request(self.root_uri + self.firmware_uri) + response = self.get_request(self.root_uri + uri) if response['ret'] is False: return response result['ret'] = True data = response['data'] result['entries'] = [] - for device in data[u'Members']: - uri = self.root_uri + device[u'@odata.id'] - # Get details for each device + for member in data[u'Members']: + uri = self.root_uri + member[u'@odata.id'] + # Get details for each software or firmware member response = self.get_request(uri) if response['ret'] is False: return response result['ret'] = True data = response['data'] - firmware = {} + software = {} # Get these standard properties if present for key in ['Name', 'Id', 'Status', 'Version', 'Updateable', 'SoftwareId', 'LowestSupportedVersion', 'Manufacturer', 'ReleaseDate']: if key in data: - firmware[key] = data.get(key) - result['entries'].append(firmware) + software[key] = data.get(key) + result['entries'].append(software) return result + def get_firmware_inventory(self): + if self.firmware_uri is None: + return {'ret': False, 'msg': 'No FirmwareInventory resource found'} + else: + return self._software_inventory(self.firmware_uri) + + def get_software_inventory(self): + if self.software_uri is None: + return {'ret': False, 'msg': 'No SoftwareInventory resource found'} + else: + return self._software_inventory(self.software_uri) + def get_bios_attributes(self, systems_uri): result = {} bios_attributes = {} diff --git a/lib/ansible/modules/remote_management/redfish/redfish_info.py b/lib/ansible/modules/remote_management/redfish/redfish_info.py index 35c6d20fc84..7395957cac4 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_info.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_info.py @@ -206,6 +206,22 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" + - name: Get firmware inventory + redfish_info: + category: Update + command: GetFirmwareInventory + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + + - name: Get software inventory + redfish_info: + category: Update + command: GetSoftwareInventory + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + - name: Get all information available in all categories redfish_info: category: all @@ -234,7 +250,7 @@ CATEGORY_COMMANDS_ALL = { "Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisPower", "GetChassisThermals", "GetChassisInventory"], "Accounts": ["ListUsers"], "Sessions": ["GetSessions"], - "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"], + "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory"], "Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs"], } @@ -374,6 +390,8 @@ def main(): for command in command_list: if command == "GetFirmwareInventory": result["firmware"] = rf_utils.get_firmware_inventory() + elif command == "GetSoftwareInventory": + result["software"] = rf_utils.get_software_inventory() elif command == "GetFirmwareUpdateCapabilities": result["firmware_update_capabilities"] = rf_utils.get_firmware_update_capabilities()