Repository: ansible-collections/community.general

Issue:
Redfish: Add 'PowerCycle' to the supported ResetType power commands
### Summary

I would like to execute a Redfish `PowerCycle` ResetType operation.

### Issue Type

Feature Idea

### Component Name

redfish_command

### Additional Information

`PowerCycle` is different than a `Force/GracefulRestart` in our hardware models and would be a welcome feature addition to have available in the module.

```
- name: Restart system power gracefully
  community.general.redfish_command:
    category: Systems
    command: PowerCycle
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/redfish_command.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/redfish_command.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @TSKushal @bhavya06 @jyundt @mraineri @rajeevkallur @renxulei @tomasg2012 @xmadsen
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
For additional background - I see that `PowerCycle` is listed in the module:
https://github.com/ansible-collections/community.general/blob/f8265ecc4e407f7ca62349d0977e9d35aa5a6f5a/plugins/module_utils/redfish_utils.py#L1026-L1030

However, attempting to use `PowerCycle` as a reset type returns:
```
TASK [Power Cycle] ************************************************************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [x.x.x.x -> 127.0.0.1]: FAILED! => {"changed": false, "msg": "Invalid Command 'PowerCycle'. Valid Commands = ['PowerOn', 'PowerForceOff', 'PowerForceRestart', 'PowerGracefulRestart', 'PowerGracefulShutdown', 'PowerReboot', 'SetOneTimeBoot', 'EnableContinuousBootOverride', 'DisableBootOverride', 'IndicatorLedOn', 'IndicatorLedOff', 'IndicatorLedBlink', 'VirtualMediaInsert', 'VirtualMediaEject', 'VerifyBiosAttributes']"}
```

The host does support it and can be run manually:
```
{
  "@odata.context": "/redfish/v1/$metadata#ActionInfo.ActionInfo",
  "@odata.etag": "W/\"1691362801\"",
  "@odata.id": "/redfish/v1/Systems/Self/ResetActionInfo",
  "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
  "Description": "This action is used to reset the Systems",
  "Id": "ResetAction",
  "Name": "ResetAction",
  "Parameters": [
    {
      "AllowableValues": [
        "ForceOff",
        "ForceRestart",
        "GracefulShutdown",
        "On",
        "PowerCycle"
      ],
      "DataType": "String",
      "Name": "ResetType",
      "Required": true
    }
  ]
}
```

Is this as simple as adding it to the redfish_command code?
https://github.com/ansible-collections/community.general/blob/a942545dd2ec718993f95db35ac3e988d24e73a5/plugins/modules/redfish_command.py#L749-L751
I'm surprised no one has complained about this... I think you're right about the change needed to fix this though.

You may need to be careful about what gets added to the "Systems" array; I think for anything starting with "Power", it will strip the lead-in "Power" string and provide the rest of the string. So, "PowerOn" changes to "On" when passed to redfish_utils, and simply adding PowerCycle might result in it trying to pass down "Cycle" to the action parameter.
😄 

Testing it out - there's more involved (sadly). 

https://github.com/ansible-collections/community.general/blob/f8265ecc4e407f7ca62349d0977e9d35aa5a6f5a/plugins/module_utils/redfish_utils.py#L1032-L1035

causes the reset_type to get chopped to `Cycle` which causes the conditional check to fail since it no longer is in the approved list.

https://github.com/ansible-collections/community.general/blob/f8265ecc4e407f7ca62349d0977e9d35aa5a6f5a/plugins/module_utils/redfish_utils.py#L1041C2-L1042

Resolving patch:
diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py
--- a/plugins/module_utils/redfish_utils.py
+++ b/plugins/module_utils/redfish_utils.py
@@ -1074,7 +1074,12 @@ def manage_power(self, command, resource_uri, action_name):
         # command should be PowerOn, PowerForceOff, etc.
         if not command.startswith('Power'):
             return {'ret': False, 'msg': 'Invalid Command (%s)' % command}
-        reset_type = command[5:]
+
+        # Commands (except PowerCycle) will be stripped of the 'Power' prefix
+        if command == 'PowerCycle':
+            reset_type = command
+        else:
+            reset_type = command[5:]
 
         # map Reboot to a ResetType that does a reboot
         if reset_type == 'Reboot':
diff --git a/plugins/modules/redfish_command.py b/plugins/modules/redfish_command.py
--- a/plugins/modules/redfish_command.py
+++ b/plugins/modules/redfish_command.py
@@ -747,7 +747,7 @@
 # More will be added as module features are expanded
 CATEGORY_COMMANDS_ALL = {
     "Systems": ["PowerOn", "PowerForceOff", "PowerForceRestart", "PowerGracefulRestart",
-                "PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot", "EnableContinuousBootOverride", "DisableBootOverride",
+                "PowerGracefulShutdown", "PowerReboot", "PowerCycle", "SetOneTimeBoot", "EnableContinuousBootOverride", "DisableBootOverride",
                 "IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink", "VirtualMediaInsert", "VirtualMediaEject", "VerifyBiosAttributes"],
     "Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"],
     "Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",


Test patch: