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

Method FindVMByIDInGroup

pkg/api/grouped-cluster.go:391–413  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
391func (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

Callers 4

findVMMethod · 0.80

Calls 1

GetGroupVMsMethod · 0.95