Skip to content

Commit 65b652c

Browse files
committed
add new func VirtualMachineExistsWithName
1 parent a3ef481 commit 65b652c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

proxmox/qemu.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*Vir
9898
return nil, rest.NotFoundErr
9999
}
100100

101+
// return true if there is any vm having specified name
102+
func (s *Service) VirtualMachineExistsWithName(ctx context.Context, name string) (bool, error) {
103+
nodes, err := s.Nodes(ctx)
104+
if err != nil {
105+
return false, err
106+
}
107+
for _, node := range nodes {
108+
vms, err := s.restclient.GetVirtualMachines(ctx, node.Node)
109+
if err != nil {
110+
continue
111+
}
112+
for _, vm := range vms {
113+
if vm.Name == name {
114+
return true, nil
115+
}
116+
}
117+
}
118+
return false, nil
119+
}
120+
101121
func ConvertSMBiosToUUID(smbios string) (string, error) {
102122
re := regexp.MustCompile(fmt.Sprintf("uuid=%s", UUIDFormat))
103123
match := re.FindString(smbios)

0 commit comments

Comments
 (0)