MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / StartVM

Function StartVM

internal/commands/commands.go:21–51  ·  view source on GitHub ↗

StartVM starts a VM or LXC by ID.

(client *api.Client, id string)

Source from the content-addressed store, hash-verified

19
20// StartVM starts a VM or LXC by ID.
21func StartVM(client *api.Client, id string) error {
22 if client == nil {
23 return fmt.Errorf("nil api client")
24 }
25
26 vmID, err := strconv.Atoi(id)
27 if err != nil {
28 return fmt.Errorf("invalid id %s: %w", id, err)
29 }
30
31 if client.Cluster == nil {
32 if _, err := client.GetClusterStatus(); err != nil {
33 return err
34 }
35 }
36
37 for _, node := range client.Cluster.Nodes {
38 if node == nil {
39 continue
40 }
41
42 for _, vm := range node.VMs {
43 if vm != nil && vm.ID == vmID {
44 _, err := client.StartVM(vm)
45 return err
46 }
47 }
48 }
49
50 return fmt.Errorf("vm %d not found", vmID)
51}
52
53// ShellNode opens an SSH shell to the given node.
54func ShellNode(sshClient *ssh.SSHClient) error {

Callers

nothing calls this directly

Calls 2

GetClusterStatusMethod · 0.80
StartVMMethod · 0.80

Tested by

no test coverage detected