[DISCUSSION/FEATURE] Adding the ability to toggle range suspend/resume from the CLI
I was reviewing the code to see ways of targeting a specific range's machines for bulk managing power state. I see the admin scripts here that allow for suspend and resume. I also see the PowerAction that only allows On/Off management.
It would be cool to extend the PowerAction's such that we can also choose suspend and resume. Sometimes it makes sense to pause a range, not completely power off
Looks like the set-vm-state.yml can handle the addition of Suspend/Resume by writing the same logic from the admin helper scripts into the set-vm-state.yml file. Something like this [UNTESTED]:
- name: Suspend VMs
ansible.builtin.uri:
url: "https://{{ api_host }}:8006/api2/json/nodes/{{ node_name }}/qemu/{{ item }}/status/suspend"
method: POST
headers:
Cookie: "PVEAuthCookie={{ hostvars['localhost']['proxmox_ticket'] }}"
CSRFPreventionToken: "{{ hostvars['localhost']['proxmox_csrf'] }}"
validate_certs: false
body_format: json
loop: "{{ vmids_to_change }}"
when: new_vm_state == 'suspended'
register: suspend_result
until: suspend_result.status in [200, 202]
retries: 3
delay: 5
Assuming this snippet works the updates to RunAnsiblePlaybookWithVariables and the tag handler in power.yml should be trivial.