Skip to content

Commit

Permalink
Update GetBiosBootOrder to use standard spec resources (#51764)
Browse files Browse the repository at this point in the history
* update GetBiosBootOrder to use standard spec resources

* handle case where BootOrder is present but BootOptions is missing
  • Loading branch information
billdodd authored and gundalow committed Feb 11, 2019
1 parent e81b74d commit e053861
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 36 deletions.
87 changes: 54 additions & 33 deletions lib/ansible/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,52 +558,73 @@ def get_bios_attributes(self):
result["entries"] = bios_attributes
return result

def get_bios_boot_order(self):
def get_boot_order(self):
result = {}
boot_device_list = []
boot_device_details = []
key = "Bios"
bootsources = "BootSources"
# Get these entries, but does not fail if not found
properties = ['Index', 'Id', 'Name', 'Enabled']
# Get these entries from BootOption, if present
properties = ['DisplayName', 'BootOptionReference']

# Search for 'key' entry and extract URI from it
# Retrieve System resource
response = self.get_request(self.root_uri + self.systems_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']

if key not in data:
return {'ret': False, 'msg': "Key %s not found" % key}
# Confirm needed Boot properties are present
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
response = self.get_request(self.root_uri + bios_uri)
if response['ret'] is False:
return response
data = response['data']
boot_mode = data[u'Attributes']["BootMode"]
if boot_mode == "Uefi":
boot_seq = "UefiBootSeq"
# Retrieve BootOptions if present
if 'BootOptions' in boot and '@odata.id' in boot['BootOptions']:
boot_options_uri = boot['BootOptions']["@odata.id"]
# Get BootOptions resource
response = self.get_request(self.root_uri + boot_options_uri)
if response['ret'] is False:
return response
data = response['data']

# Retrieve Members array
if 'Members' not in data:
return {'ret': False,
'msg': "Members not found in BootOptionsCollection"}
members = data['Members']
else:
boot_seq = "BootSeq"
members = []

response = self.get_request(self.root_uri + self.systems_uri + "/" + bootsources)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
# Build dict of BootOptions keyed by BootOptionReference
boot_options_dict = {}
for member in members:
if '@odata.id' not in member:
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]
for b in boot_device_list:
boot_device = {}
for property in properties:
if property in b:
boot_device[property] = b[property]
boot_device_details.append(boot_device)
result["entries"] = boot_device_details
# fetch the props to display for this boot device
boot_props = {}
for prop in properties:
if prop in data:
boot_props[prop] = data[prop]

boot_options_dict[boot_option_ref] = boot_props

# 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

def set_bios_default_settings(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
CATEGORY_COMMANDS_ALL = {
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
"GetNicInventory", "GetStorageControllerInventory",
"GetDiskInventory", "GetBiosAttributes", "GetBiosBootOrder"],
"GetDiskInventory", "GetBiosAttributes", "GetBootOrder"],
"Chassis": ["GetFanInventory"],
"Accounts": ["ListUsers"],
"Update": ["GetFirmwareInventory"],
Expand Down Expand Up @@ -223,8 +223,8 @@ def main():
result["disk"] = rf_utils.get_disk_inventory()
elif command == "GetBiosAttributes":
result["bios_attribute"] = rf_utils.get_bios_attributes()
elif command == "GetBiosBootOrder":
result["bios_boot_order"] = rf_utils.get_bios_boot_order()
elif command == "GetBootOrder":
result["boot_order"] = rf_utils.get_boot_order()

elif category == "Chassis":
# execute only if we find Chassis resource
Expand Down

0 comments on commit e053861

Please sign in to comment.