feat(kubevirt_vm): add state=start/stop/restart to manage VM lifecycle

It adds support for starting, stopping, and restarting VirtualMachines.
The operations are performed through the KubeVirt restart subresource
API (PUT to `subresources.kubevirt.io/v1`). These calls are extracted
into a single shared helper function `_call_subresource()` to handle the
common flow, i.e., check mode, API call and wait conditions.
Moreover, it adds the optional parameter  `grace_period_seconds` for
stop and start operations.

Additionally, it adds unit tests and integration tests for all
operations.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
This commit is contained in:
Javier Cano Cano
2026-05-11 15:48:59 +02:00
parent 19cc611159
commit 0475a8d39b
6 changed files with 840 additions and 13 deletions

10
examples/play-restart.yml Normal file
View File

@@ -0,0 +1,10 @@
---
- name: Playbook restarting a virtual machine
hosts: localhost
tasks:
- name: Restart VM
kubevirt.core.kubevirt_vm:
state: restarted
name: testvm
namespace: default
wait: true

10
examples/play-start.yml Normal file
View File

@@ -0,0 +1,10 @@
---
- name: Playbook starting a virtual machine
hosts: localhost
tasks:
- name: Start VM
kubevirt.core.kubevirt_vm:
state: started
name: testvm
namespace: default
wait: true

10
examples/play-stop.yml Normal file
View File

@@ -0,0 +1,10 @@
---
- name: Playbook stopping a virtual machine
hosts: localhost
tasks:
- name: Stop VM
kubevirt.core.kubevirt_vm:
state: stopped
name: testvm
namespace: default
wait: true