From b108d01b0f4c71278c258e1c5a751e76a51e529a Mon Sep 17 00:00:00 2001 From: Xander Madsen Date: Thu, 2 May 2019 09:08:16 -0400 Subject: [PATCH] Feat/add GetBootOverride to Systems category of redfish_facts (#54273) * Add GetBootOverride as possible Systems command * Add conditional to call get_boot_override if command == GetBootOverride * Implement get_boot_override() in redfish_utils * Implement get_multi_boot_override() and modify get_boot_override() to support the multi wrapper * Update GetBootOverride to use get_multi_boot_override * Add example for new command in docstring * fix indent * Update lib/ansible/module_utils/redfish_utils.py Co-Authored-By: xmadsen --- lib/ansible/module_utils/redfish_utils.py | 35 ++++++++++++++++++- .../redfish/redfish_facts.py | 12 ++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 219cf9783f3..3e4abf56793 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -786,6 +786,39 @@ class RedfishUtils(object): def get_multi_boot_order(self): return self.aggregate(self.get_boot_order) + def get_boot_override(self, systems_uri): + result = {} + + properties = ["BootSourceOverrideEnabled", "BootSourceOverrideTarget", + "BootSourceOverrideMode", "UefiTargetBootSourceOverride", "BootSourceOverrideTarget@Redfish.AllowableValues"] + + response = self.get_request(self.root_uri + systems_uri) + if response['ret'] is False: + return response + result['ret'] = True + data = response['data'] + + if 'Boot' not in data: + return {'ret': False, 'msg': "Key Boot not found"} + + boot = data['Boot'] + + boot_overrides = {} + if "BootSourceOverrideEnabled" in boot: + if boot["BootSourceOverrideEnabled"] is not False: + for property in properties: + if property in boot: + if boot[property] is not None: + boot_overrides[property] = boot[property] + else: + return {'ret': False, 'msg': "No boot override is enabled."} + + result['entries'] = boot_overrides + return result + + def get_multi_boot_override(self): + return self.aggregate(self.get_boot_override) + def set_bios_default_settings(self): result = {} key = "Bios" @@ -1216,7 +1249,7 @@ class RedfishUtils(object): ret = inventory.pop('ret') and ret if 'entries' in inventory: entries.append(({'resource_uri': resource_uri}, - inventory['entries'])) + inventory['entries'])) return dict(ret=ret, entries=entries) def get_psu_inventory(self): diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index 28a9bb1fb97..d6935e84919 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -129,6 +129,14 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" + - name: Get boot override information + redfish_facts: + category: Systems + command: GetBootOverride + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + - name: Get all information available in the Manager category redfish_facts: category: Manager @@ -169,7 +177,7 @@ CATEGORY_COMMANDS_ALL = { "Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory", "GetMemoryInventory", "GetNicInventory", "GetStorageControllerInventory", "GetDiskInventory", - "GetBiosAttributes", "GetBootOrder"], + "GetBiosAttributes", "GetBootOrder", "GetBootOverride"], "Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisPower", "GetChassisThermals"], "Accounts": ["ListUsers"], "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities"], @@ -267,6 +275,8 @@ def main(): result["bios_attribute"] = rf_utils.get_multi_bios_attributes() elif command == "GetBootOrder": result["boot_order"] = rf_utils.get_multi_boot_order() + elif command == "GetBootOverride": + result["boot_override"] = rf_utils.get_multi_boot_override() elif category == "Chassis": # execute only if we find Chassis resource