StartVM starts a VM or LXC by ID.
(client *api.Client, id string)
| 19 | |
| 20 | // StartVM starts a VM or LXC by ID. |
| 21 | func 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. |
| 54 | func ShellNode(sshClient *ssh.SSHClient) error { |
nothing calls this directly
no test coverage detected