Skip to content

Commit

Permalink
add new func VirtualMachineExistsWithName
Browse files Browse the repository at this point in the history
  • Loading branch information
sp-yduck committed Nov 25, 2023
1 parent a3ef481 commit 65b652c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions proxmox/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*Vir
return nil, rest.NotFoundErr
}

// return true if there is any vm having specified name
func (s *Service) VirtualMachineExistsWithName(ctx context.Context, name string) (bool, error) {
nodes, err := s.Nodes(ctx)
if err != nil {
return false, err
}
for _, node := range nodes {
vms, err := s.restclient.GetVirtualMachines(ctx, node.Node)
if err != nil {
continue
}
for _, vm := range vms {
if vm.Name == name {
return true, nil
}
}
}
return false, nil
}

func ConvertSMBiosToUUID(smbios string) (string, error) {
re := regexp.MustCompile(fmt.Sprintf("uuid=%s", UUIDFormat))
match := re.FindString(smbios)
Expand Down

0 comments on commit 65b652c

Please sign in to comment.