Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add VirshShutdownVM helper for graceful VM shutdown
  • Loading branch information
clobrano committed Dec 1, 2025
commit 129b681f08dd2427b5def3397d98c571bee2026b
14 changes: 14 additions & 0 deletions test/extended/two_node/utils/services/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ func VirshGetVMUUID(vmName string, sshConfig *core.SSHConfig, knownHostsPath str
return uuid, err
}

// VirshShutdownVM gracefully shuts down a running VM (allows guest OS to shutdown cleanly).
//
// err := VirshShutdownVM("master-0", sshConfig, knownHostsPath)
func VirshShutdownVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error {
klog.V(2).Infof("VirshShutdownVM: Gracefully shutting down VM '%s'", vmName)
_, err := VirshCommand(fmt.Sprintf("shutdown %s", vmName), sshConfig, knownHostsPath)
if err != nil {
klog.ErrorS(err, "VirshShutdownVM failed", "vm", vmName)
} else {
klog.V(2).Infof("VirshShutdownVM: Successfully initiated shutdown for VM '%s'", vmName)
}
return err
}

// VirshUndefineVM undefines a VM (removes libvirt config, not disk images).
//
// err := VirshUndefineVM("master-0", sshConfig, knownHostsPath)
Expand Down