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

Function findGuestByVMID

internal/cli/cli_helpers.go:663–682  ·  view source on GitHub ↗

findGuestByVMID scans all nodes for a guest with the given VMID.

(client *api.Client, vmid int)

Source from the content-addressed store, hash-verified

661
662// findGuestByVMID scans all nodes for a guest with the given VMID.
663func 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}

Callers 1

findVMMethod · 0.85

Calls 1

GetClusterStatusMethod · 0.80

Tested by

no test coverage detected