FindVMByIDInGroup searches for a VM with the given ID across all profiles. Returns the VM and its source profile name, or an error if not found. If the same VMID exists in more than one profile, ErrAmbiguousVMID is returned so that callers can surface a disambiguation message to the user.
(ctx context.Context, vmID int)
| 389 | // If the same VMID exists in more than one profile, ErrAmbiguousVMID is returned |
| 390 | // so that callers can surface a disambiguation message to the user. |
| 391 | func (m *GroupClientManager) FindVMByIDInGroup(ctx context.Context, vmID int) (*VM, string, error) { |
| 392 | vms, err := m.GetGroupVMs(ctx) |
| 393 | if err != nil { |
| 394 | return nil, "", err |
| 395 | } |
| 396 | |
| 397 | var matches []*VM |
| 398 | |
| 399 | for _, vm := range vms { |
| 400 | if vm.ID == vmID { |
| 401 | matches = append(matches, vm) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | switch len(matches) { |
| 406 | case 0: |
| 407 | return nil, "", fmt.Errorf("VM with ID %d not found in any profile", vmID) |
| 408 | case 1: |
| 409 | return matches[0], matches[0].SourceProfile, nil |
| 410 | default: |
| 411 | return nil, "", &AmbiguousVMIDError{VMID: vmID, Matches: matches} |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // AmbiguousVMIDError is returned when a VMID matches guests in more than one |
| 416 | // profile in an aggregate group. The caller should present Matches to the user |