| 1 | package vm |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | |
| 7 | "github.com/lima-vm/lima/v2/pkg/limatype" |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | var ErrNetworkOpen = errors.New("agent-vm starts no VM with a network besides its own") |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | func NetworkConfined(cfg *limatype.LimaYAML) error { |
| 19 | |
| 20 | |
| 21 | |
| 22 | if cfg.VMType != nil && *cfg.VMType != limatype.QEMU && *cfg.VMType != limatype.VZ { |
| 23 | return fmt.Errorf("%w: VM driver %q does not use the confined network", ErrNetworkOpen, *cfg.VMType) |
| 24 | } |
| 25 | for i, n := range cfg.Networks { |
| 26 | what := "a network" |
| 27 | switch { |
| 28 | case n.Lima != "": |
| 29 | what = fmt.Sprintf("the shared network %q", n.Lima) |
| 30 | case n.Socket != "": |
| 31 | what = fmt.Sprintf("the socket %q", n.Socket) |
| 32 | case n.VZNAT != nil && *n.VZNAT: |
| 33 | what = "vzNAT" |
| 34 | } |
| 35 | return fmt.Errorf("%w: networks[%d] is %s", ErrNetworkOpen, i, what) |
| 36 | } |
| 37 | return nil |
| 38 | } |