Skip to content

Commit

Permalink
Merge pull request #3 from simplysoft/fix-vm-from-uuid
Browse files Browse the repository at this point in the history
fix early abort in VirtualMachineFromUUID
  • Loading branch information
sp-yduck authored Oct 10, 2023
2 parents 832aa90 + 8f7fde8 commit 4334991
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions proxmox/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (s *Service) CreateVirtualMachine(ctx context.Context, node string, vmid in
return s.VirtualMachine(ctx, vmid)
}

// VirtualMachineFromUUID attempts to find virtual machine based on SMBIOS UUID. It will ignore any error that prevents
// it from inspecting additional virtual machines (e.g. offline node, vm config not accessible, malformed uuids)
func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*VirtualMachine, error) {
nodes, err := s.Nodes(ctx)
if err != nil {
Expand All @@ -77,16 +79,16 @@ func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*Vir
for _, node := range nodes {
vms, err := s.restclient.GetVirtualMachines(ctx, node.Node)
if err != nil {
return nil, err
continue
}
for _, vm := range vms {
config, err := s.restclient.GetVirtualMachineConfig(ctx, node.Node, vm.VMID)
if err != nil {
return nil, err
continue
}
vmuuid, err := ConvertSMBiosToUUID(config.SMBios1)
if err != nil {
return nil, err
continue
}
if vmuuid == uuid {
return &VirtualMachine{service: s, restclient: s.restclient, VM: vm, Node: node.Node, config: config}, nil
Expand Down

0 comments on commit 4334991

Please sign in to comment.