From 1e415899ad811597a91cb669dfaff82e54aab84e Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Tue, 18 Dec 2018 10:58:17 -0500 Subject: [PATCH] GetManagerNicInventory (#49961) * Add GetManagerNicInventory command for Manager category, and tweak redfish_utils' get_nic_inventory to accommodate manager nic interfaces * Remove get_manager_nic_inventory, since it is unnecessary while using get_manager in get_nic_inventory * Rework get_nic_inventory() to take a resource_type as a string, which will be just the category parameter from redfish_facts, making it clearer * remove extraneous blank line to conform with pep8 * Add GetManagerNicInventory example task to EXAMPLES docstring --- lib/ansible/module_utils/redfish_utils.py | 11 ++++++++--- .../remote_management/redfish/redfish_facts.py | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index d5be250e16..a1fb9325c8 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -833,7 +833,7 @@ class RedfishUtils(object): result["entries"] = cpu_results return result - def get_nic_inventory(self): + def get_nic_inventory(self, resource_type): result = {} nic_list = [] nic_results = [] @@ -843,8 +843,13 @@ class RedfishUtils(object): 'NameServers', 'PermanentMACAddress', 'SpeedMbps', 'MTUSize', 'AutoNeg', 'Status'] - # Search for 'key' entry and extract URI from it - response = self.get_request(self.root_uri + self.systems_uri) + # Given resource_type, use the proper URI + if resource_type == 'Systems': + resource_uri = self.systems_uri + elif resource_type == 'Manager': + resource_uri = self.manager_uri + + response = self.get_request(self.root_uri + resource_uri) if response['ret'] is False: return response result['ret'] = True diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index c030ea019e..9e8d088195 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -92,6 +92,14 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" + - name: Get Manager NIC inventory information + redfish_facts: + category: Manager + command: GetManagerNicInventory + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + - name: Get all information available in the Manager category redfish_facts: category: Manager @@ -127,7 +135,7 @@ CATEGORY_COMMANDS_ALL = { "Chassis": ["GetFanInventory"], "Accounts": ["ListUsers"], "Update": ["GetFirmwareInventory"], - "Manager": ["GetManagerAttributes", "GetLogs"], + "Manager": ["GetManagerAttributes", "GetManagerNicInventory", "GetLogs"], } CATEGORY_COMMANDS_DEFAULT = { @@ -208,7 +216,7 @@ def main(): elif command == "GetCpuInventory": result["cpu"] = rf_utils.get_cpu_inventory() elif command == "GetNicInventory": - result["nic"] = rf_utils.get_nic_inventory() + result["nic"] = rf_utils.get_nic_inventory(category) elif command == "GetStorageControllerInventory": result["storage_controller"] = rf_utils.get_storage_controller_inventory() elif command == "GetDiskInventory": @@ -257,6 +265,8 @@ def main(): for command in command_list: if command == "GetManagerAttributes": result["manager_attributes"] = rf_utils.get_manager_attributes() + elif command == "GetManagerNicInventory": + result["manager_nics"] = rf_utils.get_nic_inventory(resource_type=category) elif command == "GetLogs": result["log"] = rf_utils.get_logs()