findGuestByVMID scans all nodes for a guest with the given VMID.
(client *api.Client, vmid int)
| 661 | |
| 662 | // findGuestByVMID scans all nodes for a guest with the given VMID. |
| 663 | func findGuestByVMID(client *api.Client, vmid int) (*api.VM, error) { |
| 664 | cluster, err := client.GetClusterStatus() |
| 665 | if err != nil { |
| 666 | return nil, fmt.Errorf("failed to fetch cluster status: %w", err) |
| 667 | } |
| 668 | |
| 669 | for _, node := range cluster.Nodes { |
| 670 | if node == nil { |
| 671 | continue |
| 672 | } |
| 673 | |
| 674 | for _, vm := range node.VMs { |
| 675 | if vm != nil && vm.ID == vmid { |
| 676 | return vm, nil |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return nil, fmt.Errorf("guest %d not found", vmid) |
| 682 | } |
no test coverage detected