mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
Fix SetOneTimeBoot to use standard ComputerSystem 'Boot' property (#54201)
* fix SetOneTimeBoot to use standard ComputerSystem 'Boot' property * add support for UefiTarget and UefiBootNext boot sources
This commit is contained in:
parent
eb7190264e
commit
2614e823df
2 changed files with 97 additions and 15 deletions
|
@ -815,9 +815,13 @@ class RedfishUtils(object):
|
|||
return response
|
||||
return {'ret': True, 'changed': True, 'msg': "Set BIOS to default settings"}
|
||||
|
||||
def set_one_time_boot_device(self, bootdevice):
|
||||
def set_one_time_boot_device(self, bootdevice, uefi_target, boot_next):
|
||||
result = {}
|
||||
key = "Bios"
|
||||
key = "Boot"
|
||||
|
||||
if not bootdevice:
|
||||
return {'ret': False,
|
||||
'msg': "bootdevice option required for SetOneTimeBoot"}
|
||||
|
||||
# Search for 'key' entry and extract URI from it
|
||||
response = self.get_request(self.root_uri + self.systems_uris[0])
|
||||
|
@ -829,23 +833,65 @@ class RedfishUtils(object):
|
|||
if key not in data:
|
||||
return {'ret': False, 'msg': "Key %s not found" % key}
|
||||
|
||||
bios_uri = data[key]["@odata.id"]
|
||||
boot = data[key]
|
||||
|
||||
response = self.get_request(self.root_uri + bios_uri)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
annotation = 'BootSourceOverrideTarget@Redfish.AllowableValues'
|
||||
if annotation in boot:
|
||||
allowable_values = boot[annotation]
|
||||
if isinstance(allowable_values, list) and bootdevice not in allowable_values:
|
||||
return {'ret': False,
|
||||
'msg': "Boot device %s not in list of allowable values (%s)" %
|
||||
(bootdevice, allowable_values)}
|
||||
|
||||
boot_mode = data[u'Attributes']["BootMode"]
|
||||
if boot_mode == "Uefi":
|
||||
payload = {"Boot": {"BootSourceOverrideTarget": "UefiTarget", "UefiTargetBootSourceOverride": bootdevice}}
|
||||
# read existing values
|
||||
enabled = boot.get('BootSourceOverrideEnabled')
|
||||
target = boot.get('BootSourceOverrideTarget')
|
||||
cur_uefi_target = boot.get('UefiTargetBootSourceOverride')
|
||||
cur_boot_next = boot.get('BootNext')
|
||||
|
||||
if bootdevice == 'UefiTarget':
|
||||
if not uefi_target:
|
||||
return {'ret': False,
|
||||
'msg': "uefi_target option required to SetOneTimeBoot for UefiTarget"}
|
||||
if enabled == 'Once' and target == bootdevice and uefi_target == cur_uefi_target:
|
||||
# If properties are already set, no changes needed
|
||||
return {'ret': True, 'changed': False}
|
||||
payload = {
|
||||
'Boot': {
|
||||
'BootSourceOverrideEnabled': 'Once',
|
||||
'BootSourceOverrideTarget': bootdevice,
|
||||
'UefiTargetBootSourceOverride': uefi_target
|
||||
}
|
||||
}
|
||||
elif bootdevice == 'UefiBootNext':
|
||||
if not boot_next:
|
||||
return {'ret': False,
|
||||
'msg': "boot_next option required to SetOneTimeBoot for UefiBootNext"}
|
||||
if enabled == 'Once' and target == bootdevice and boot_next == cur_boot_next:
|
||||
# If properties are already set, no changes needed
|
||||
return {'ret': True, 'changed': False}
|
||||
payload = {
|
||||
'Boot': {
|
||||
'BootSourceOverrideEnabled': 'Once',
|
||||
'BootSourceOverrideTarget': bootdevice,
|
||||
'BootNext': boot_next
|
||||
}
|
||||
}
|
||||
else:
|
||||
payload = {"Boot": {"BootSourceOverrideTarget": bootdevice}}
|
||||
if enabled == 'Once' and target == bootdevice:
|
||||
# If properties are already set, no changes needed
|
||||
return {'ret': True, 'changed': False}
|
||||
payload = {
|
||||
'Boot': {
|
||||
'BootSourceOverrideEnabled': 'Once',
|
||||
'BootSourceOverrideTarget': bootdevice
|
||||
}
|
||||
}
|
||||
|
||||
response = self.patch_request(self.root_uri + self.systems_uris[0], payload)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
return {'ret': True}
|
||||
return {'ret': True, 'changed': True}
|
||||
|
||||
def set_bios_attributes(self, attr):
|
||||
result = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue