diff --git a/changelogs/fragments/9837-redfish-implement-setting-powerrestorepolicy.yml b/changelogs/fragments/9837-redfish-implement-setting-powerrestorepolicy.yml new file mode 100644 index 0000000000..d4b1f505e1 --- /dev/null +++ b/changelogs/fragments/9837-redfish-implement-setting-powerrestorepolicy.yml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_config - add command ``SetPowerRestorePolicy`` to set the desired power state of the system when power is restored (https://github.com/ansible-collections/community.general/pull/9837). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 38f7c923fb..f4e8cd5a36 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3983,3 +3983,7 @@ class RedfishUtils(object): def get_multi_power_restore_policy(self): return self.aggregate_systems(self.get_power_restore_policy) + + def set_power_restore_policy(self, policy): + body = {'PowerRestorePolicy': policy} + return self.patch_request(self.root_uri + self.systems_uri, body, check_pyld=True) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 80cf094f88..817cc18787 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -171,6 +171,15 @@ options: type: dict default: {} version_added: '7.5.0' + power_restore_policy: + description: + - The desired power state of the system when power is restored after a power loss. + type: str + choices: + - AlwaysOn + - AlwaysOff + - LastState + version_added: '10.5.0' ciphers: required: false description: @@ -358,6 +367,15 @@ EXAMPLES = r""" Drives: - "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" +- name: Set PowerRestorePolicy + community.general.redfish_config: + category: Systems + command: SetPowerRestorePolicy + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + power_restore_policy: "AlwaysOff" + - name: Set service identification to {{ service_id }} community.general.redfish_config: category: Manager @@ -384,7 +402,8 @@ from ansible.module_utils.common.text.converters import to_native # More will be added as module features are expanded CATEGORY_COMMANDS_ALL = { "Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder", - "SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes", "CreateVolume"], + "SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes", "CreateVolume", + "SetPowerRestorePolicy"], "Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface", "SetServiceIdentification"], "Sessions": ["SetSessionService"], } @@ -423,6 +442,7 @@ def main(): volume_ids=dict(type='list', default=[], elements='str'), secure_boot_enable=dict(type='bool', default=True), volume_details=dict(type='dict', default={}), + power_restore_policy=dict(choices=['AlwaysOn', 'AlwaysOff', 'LastState']), ciphers=dict(type='list', elements='str'), ), required_together=[ @@ -488,6 +508,9 @@ def main(): storage_subsystem_id = module.params['storage_subsystem_id'] storage_none_volume_deletion = module.params['storage_none_volume_deletion'] + # Power Restore Policy + power_restore_policy = module.params['power_restore_policy'] + # ciphers ciphers = module.params['ciphers'] @@ -531,6 +554,8 @@ def main(): result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids) elif command == "CreateVolume": result = rf_utils.create_volume(volume_details, storage_subsystem_id, storage_none_volume_deletion) + elif command == "SetPowerRestorePolicy": + result = rf_utils.set_power_restore_policy(power_restore_policy) elif category == "Manager": # execute only if we find a Manager service resource