1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

redfish_command: allow setting the BootSourceOverrideEnabled property (#825)

Issue: 824

Co-authored-by: Scott Seekamp <sseekamp@digitalocean.com>
This commit is contained in:
Scott Seekamp 2020-09-10 09:25:48 -06:00 committed by GitHub
parent bfdb76e60d
commit d7ec65c19c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 16 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- redfish_command - add sub-command for ``EnableContinuousBootOverride`` and ``DisableBootOverride`` to allow setting BootSourceOverrideEnabled Redfish property (https://github.com/ansible-collections/community.general/issues/824).

View file

@ -1501,13 +1501,18 @@ class RedfishUtils(object):
return response return response
return {'ret': True, 'changed': True, 'msg': "Set BIOS to default settings"} return {'ret': True, 'changed': True, 'msg': "Set BIOS to default settings"}
def set_one_time_boot_device(self, bootdevice, uefi_target, boot_next): def set_boot_override(self, boot_opts):
result = {} result = {}
key = "Boot" key = "Boot"
if not bootdevice: bootdevice = boot_opts.get('bootdevice')
uefi_target = boot_opts.get('uefi_target')
boot_next = boot_opts.get('boot_next')
override_enabled = boot_opts.get('override_enabled')
if not bootdevice and override_enabled != 'Disabled':
return {'ret': False, return {'ret': False,
'msg': "bootdevice option required for SetOneTimeBoot"} 'msg': "bootdevice option required for temporary boot override"}
# Search for 'key' entry and extract URI from it # Search for 'key' entry and extract URI from it
response = self.get_request(self.root_uri + self.systems_uri) response = self.get_request(self.root_uri + self.systems_uri)
@ -1530,21 +1535,27 @@ class RedfishUtils(object):
(bootdevice, allowable_values)} (bootdevice, allowable_values)}
# read existing values # read existing values
enabled = boot.get('BootSourceOverrideEnabled') cur_enabled = boot.get('BootSourceOverrideEnabled')
target = boot.get('BootSourceOverrideTarget') target = boot.get('BootSourceOverrideTarget')
cur_uefi_target = boot.get('UefiTargetBootSourceOverride') cur_uefi_target = boot.get('UefiTargetBootSourceOverride')
cur_boot_next = boot.get('BootNext') cur_boot_next = boot.get('BootNext')
if bootdevice == 'UefiTarget': if override_enabled == 'Disabled':
payload = {
'Boot': {
'BootSourceOverrideEnabled': override_enabled
}
}
elif bootdevice == 'UefiTarget':
if not uefi_target: if not uefi_target:
return {'ret': False, return {'ret': False,
'msg': "uefi_target option required to SetOneTimeBoot for UefiTarget"} 'msg': "uefi_target option required to SetOneTimeBoot for UefiTarget"}
if enabled == 'Once' and target == bootdevice and uefi_target == cur_uefi_target: if override_enabled == cur_enabled and target == bootdevice and uefi_target == cur_uefi_target:
# If properties are already set, no changes needed # If properties are already set, no changes needed
return {'ret': True, 'changed': False} return {'ret': True, 'changed': False}
payload = { payload = {
'Boot': { 'Boot': {
'BootSourceOverrideEnabled': 'Once', 'BootSourceOverrideEnabled': override_enabled,
'BootSourceOverrideTarget': bootdevice, 'BootSourceOverrideTarget': bootdevice,
'UefiTargetBootSourceOverride': uefi_target 'UefiTargetBootSourceOverride': uefi_target
} }
@ -1553,23 +1564,23 @@ class RedfishUtils(object):
if not boot_next: if not boot_next:
return {'ret': False, return {'ret': False,
'msg': "boot_next option required to SetOneTimeBoot for UefiBootNext"} 'msg': "boot_next option required to SetOneTimeBoot for UefiBootNext"}
if enabled == 'Once' and target == bootdevice and boot_next == cur_boot_next: if cur_enabled == override_enabled and target == bootdevice and boot_next == cur_boot_next:
# If properties are already set, no changes needed # If properties are already set, no changes needed
return {'ret': True, 'changed': False} return {'ret': True, 'changed': False}
payload = { payload = {
'Boot': { 'Boot': {
'BootSourceOverrideEnabled': 'Once', 'BootSourceOverrideEnabled': override_enabled,
'BootSourceOverrideTarget': bootdevice, 'BootSourceOverrideTarget': bootdevice,
'BootNext': boot_next 'BootNext': boot_next
} }
} }
else: else:
if enabled == 'Once' and target == bootdevice: if cur_enabled == override_enabled and target == bootdevice:
# If properties are already set, no changes needed # If properties are already set, no changes needed
return {'ret': True, 'changed': False} return {'ret': True, 'changed': False}
payload = { payload = {
'Boot': { 'Boot': {
'BootSourceOverrideEnabled': 'Once', 'BootSourceOverrideEnabled': override_enabled,
'BootSourceOverrideTarget': bootdevice 'BootSourceOverrideTarget': bootdevice
} }
} }

View file

@ -238,6 +238,21 @@ EXAMPLES = '''
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
- name: Set persistent boot device override
community.general.redfish_command:
category: Systems
command: EnableContinuousBootOverride
resource_id: 437XR1138R2
bootdevice: "{{ bootdevice }}"
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
- name: Disable persistent boot device override
community.general.redfish_command:
category: Systems
command: DisableBootOverride
- name: Set chassis indicator LED to blink - name: Set chassis indicator LED to blink
community.general.redfish_command: community.general.redfish_command:
category: Chassis category: Chassis
@ -442,7 +457,7 @@ from ansible.module_utils._text import to_native
# More will be added as module features are expanded # More will be added as module features are expanded
CATEGORY_COMMANDS_ALL = { CATEGORY_COMMANDS_ALL = {
"Systems": ["PowerOn", "PowerForceOff", "PowerForceRestart", "PowerGracefulRestart", "Systems": ["PowerOn", "PowerForceOff", "PowerForceRestart", "PowerGracefulRestart",
"PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot"], "PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot", "EnableContinuousBootOverride", "DisableBootOverride"],
"Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"], "Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"],
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser", "Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
"UpdateUserRole", "UpdateUserPassword", "UpdateUserName", "UpdateUserRole", "UpdateUserPassword", "UpdateUserName",
@ -530,6 +545,13 @@ def main():
'update_creds': module.params['update_creds'] 'update_creds': module.params['update_creds']
} }
# Boot override options
boot_opts = {
'bootdevice': module.params['bootdevice'],
'uefi_target': module.params['uefi_target'],
'boot_next': module.params['boot_next']
}
# VirtualMedia options # VirtualMedia options
virtual_media = module.params['virtual_media'] virtual_media = module.params['virtual_media']
@ -579,10 +601,14 @@ def main():
if "Power" in command: if "Power" in command:
result = rf_utils.manage_system_power(command) result = rf_utils.manage_system_power(command)
elif command == "SetOneTimeBoot": elif command == "SetOneTimeBoot":
result = rf_utils.set_one_time_boot_device( boot_opts['override_enabled'] = 'Once'
module.params['bootdevice'], result = rf_utils.set_boot_override(boot_opts)
module.params['uefi_target'], elif command == "EnableContinuousBootOverride":
module.params['boot_next']) boot_opts['override_enabled'] = 'Continuous'
result = rf_utils.set_boot_override(boot_opts)
elif command == "DisableBootOverride":
boot_opts['override_enabled'] = 'Disabled'
result = rf_utils.set_boot_override(boot_opts)
elif category == "Chassis": elif category == "Chassis":
result = rf_utils._find_chassis_resource() result = rf_utils._find_chassis_resource()