Skip to content

Commit 3b60d77

Browse files
committed
feat: add VirshShutdownVM helper for graceful VM shutdown
1 parent 70d9ad2 commit 3b60d77

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/extended/two_node/utils/services/libvirt.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ func VirshDestroyVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath str
171171
return err
172172
}
173173

174+
// VirshShutdownVM gracefully shuts down a running VM (allows guest OS to shutdown cleanly).
175+
//
176+
// err := VirshShutdownVM("master-0", sshConfig, knownHostsPath)
177+
func VirshShutdownVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error {
178+
klog.V(2).Infof("VirshShutdownVM: Gracefully shutting down VM '%s'", vmName)
179+
_, err := VirshCommand(fmt.Sprintf("shutdown %s", vmName), sshConfig, knownHostsPath)
180+
if err != nil {
181+
klog.ErrorS(err, "VirshShutdownVM failed", "vm", vmName)
182+
} else {
183+
klog.V(2).Infof("VirshShutdownVM: Successfully initiated shutdown for VM '%s'", vmName)
184+
}
185+
return err
186+
}
187+
174188
// VirshDefineVM defines a new VM from an XML configuration file.
175189
//
176190
// err := VirshDefineVM("/tmp/master-0.xml", sshConfig, knownHostsPath)

0 commit comments

Comments
 (0)