Skip to content

Commit 7105a78

Browse files
committed
Merge branch 'fix-list-on-error' into 'main'
Make 'list' skips VM an error is found See merge request bootc-org/podman-bootc-cli!67
2 parents 5e20d32 + 03c94b9 commit 7105a78

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

cmd/list.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/sirupsen/logrus"
45
"os"
56

67
"gitlab.com/bootc-org/podman-bootc/pkg/config"
@@ -65,25 +66,35 @@ func CollectVmList(user user.User, libvirtUri string) (vmList []vm.BootcVMConfig
6566

6667
for _, f := range files {
6768
if f.IsDir() {
68-
vm, err := vm.NewVM(vm.NewVMParameters{
69-
ImageID: f.Name(),
70-
User: user,
71-
LibvirtUri: libvirtUri,
72-
})
73-
69+
cfg, err := getVMInfo(user, libvirtUri, f.Name())
7470
if err != nil {
75-
return nil, err
71+
logrus.Warningf("skipping vm %s reason: %v", f.Name(), err)
72+
continue
7673
}
7774

78-
cfg, err := vm.GetConfig()
79-
if err != nil {
80-
return nil, err
81-
}
82-
83-
vm.CloseConnection()
84-
8575
vmList = append(vmList, *cfg)
8676
}
8777
}
8878
return vmList, nil
8979
}
80+
81+
func getVMInfo(user user.User, libvirtUri string, imageId string) (*vm.BootcVMConfig, error) {
82+
bootcVM, err := vm.NewVM(vm.NewVMParameters{
83+
ImageID: imageId,
84+
User: user,
85+
LibvirtUri: libvirtUri,
86+
})
87+
88+
if err != nil {
89+
return nil, err
90+
}
91+
92+
defer bootcVM.CloseConnection()
93+
94+
cfg, err := bootcVM.GetConfig()
95+
if err != nil {
96+
return nil, err
97+
}
98+
99+
return cfg, nil
100+
}

0 commit comments

Comments
 (0)