Update GetBiosBootOrder to use standard spec resources (#51764)

* update GetBiosBootOrder to use standard spec resources

* handle case where BootOrder is present but BootOptions is missing
This commit is contained in:
Bill Dodd 2019-02-11 08:50:10 -06:00 committed by John R Barker
parent e81b74d6c8
commit e0538610bf
2 changed files with 57 additions and 36 deletions

View file

@ -558,52 +558,73 @@ class RedfishUtils(object):
result["entries"] = bios_attributes result["entries"] = bios_attributes
return result return result
def get_bios_boot_order(self): def get_boot_order(self):
result = {} result = {}
boot_device_list = [] # Get these entries from BootOption, if present
boot_device_details = [] properties = ['DisplayName', 'BootOptionReference']
key = "Bios"
bootsources = "BootSources"
# Get these entries, but does not fail if not found
properties = ['Index', 'Id', 'Name', 'Enabled']
# Search for 'key' entry and extract URI from it # Retrieve System resource
response = self.get_request(self.root_uri + self.systems_uri) response = self.get_request(self.root_uri + self.systems_uri)
if response['ret'] is False: if response['ret'] is False:
return response return response
result['ret'] = True result['ret'] = True
data = response['data'] data = response['data']
if key not in data: # Confirm needed Boot properties are present
return {'ret': False, 'msg': "Key %s not found" % key} if 'Boot' not in data or 'BootOrder' not in data['Boot']:
return {'ret': False, 'msg': "Key BootOrder not found"}
bios_uri = data[key]["@odata.id"] boot = data['Boot']
boot_order = boot['BootOrder']
# Get boot mode first as it will determine what attribute to read # Retrieve BootOptions if present
response = self.get_request(self.root_uri + bios_uri) if 'BootOptions' in boot and '@odata.id' in boot['BootOptions']:
if response['ret'] is False: boot_options_uri = boot['BootOptions']["@odata.id"]
return response # Get BootOptions resource
data = response['data'] response = self.get_request(self.root_uri + boot_options_uri)
boot_mode = data[u'Attributes']["BootMode"] if response['ret'] is False:
if boot_mode == "Uefi": return response
boot_seq = "UefiBootSeq" data = response['data']
# Retrieve Members array
if 'Members' not in data:
return {'ret': False,
'msg': "Members not found in BootOptionsCollection"}
members = data['Members']
else: else:
boot_seq = "BootSeq" members = []
response = self.get_request(self.root_uri + self.systems_uri + "/" + bootsources) # Build dict of BootOptions keyed by BootOptionReference
if response['ret'] is False: boot_options_dict = {}
return response for member in members:
result['ret'] = True if '@odata.id' not in member:
data = response['data'] 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"}
boot_option_ref = data['BootOptionReference']
boot_device_list = data[u'Attributes'][boot_seq] # fetch the props to display for this boot device
for b in boot_device_list: boot_props = {}
boot_device = {} for prop in properties:
for property in properties: if prop in data:
if property in b: boot_props[prop] = data[prop]
boot_device[property] = b[property]
boot_device_details.append(boot_device) boot_options_dict[boot_option_ref] = boot_props
result["entries"] = boot_device_details
# Build boot device list
boot_device_list = []
for ref in boot_order:
boot_device_list.append(
boot_options_dict.get(ref, {'BootOptionReference': ref}))
result["entries"] = boot_device_list
return result return result
def set_bios_default_settings(self): def set_bios_default_settings(self):

View file

@ -131,7 +131,7 @@ from ansible.module_utils.redfish_utils import RedfishUtils
CATEGORY_COMMANDS_ALL = { CATEGORY_COMMANDS_ALL = {
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory", "Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
"GetNicInventory", "GetStorageControllerInventory", "GetNicInventory", "GetStorageControllerInventory",
"GetDiskInventory", "GetBiosAttributes", "GetBiosBootOrder"], "GetDiskInventory", "GetBiosAttributes", "GetBootOrder"],
"Chassis": ["GetFanInventory"], "Chassis": ["GetFanInventory"],
"Accounts": ["ListUsers"], "Accounts": ["ListUsers"],
"Update": ["GetFirmwareInventory"], "Update": ["GetFirmwareInventory"],
@ -223,8 +223,8 @@ def main():
result["disk"] = rf_utils.get_disk_inventory() result["disk"] = rf_utils.get_disk_inventory()
elif command == "GetBiosAttributes": elif command == "GetBiosAttributes":
result["bios_attribute"] = rf_utils.get_bios_attributes() result["bios_attribute"] = rf_utils.get_bios_attributes()
elif command == "GetBiosBootOrder": elif command == "GetBootOrder":
result["bios_boot_order"] = rf_utils.get_bios_boot_order() result["boot_order"] = rf_utils.get_boot_order()
elif category == "Chassis": elif category == "Chassis":
# execute only if we find Chassis resource # execute only if we find Chassis resource