diff --git a/cmd/utils.go b/cmd/utils.go index a23cc21..8c36dbf 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -33,7 +33,9 @@ func createStoreOrExit() *storage.Storage { return store } -func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManager, *share.NetTapRuntimeContext) int, forwardPortsRules []vm.PortForwardingRule, unrestrictedNetworking bool, withNetTap bool) int { +type runVMFunc func(context.Context, *vm.VM, *vm.FileManager, *share.NetTapRuntimeContext) int + +func runVM(passthroughArg string, fn runVMFunc, forwardPortsRules []vm.PortForwardingRule, unrestrictedNetworking bool, withNetTap bool) int { store := createStoreOrExit() vmImagePath, err := store.CheckVMImageExists() @@ -196,6 +198,10 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag ShowDisplay: vmDebugFlag, } + return innerRunVM(vmCfg, tapRuntimeCtx, fn) +} + +func innerRunVM(vmCfg vm.VMConfig, tapRuntimeCtx *share.NetTapRuntimeContext, fn runVMFunc) int { vi, err := vm.NewVM(slog.Default().With("caller", "vm"), vmCfg) if err != nil { slog.Error("Failed to create vm instance", "error", err.Error()) diff --git a/vm/net.go b/vm/net.go index 990023d..af09d9f 100644 --- a/vm/net.go +++ b/vm/net.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" ) -func (vi *VM) ConfigureInterfaceStaticNet(ctx context.Context, iface string, cidr string) error { +func (vm *VM) ConfigureInterfaceStaticNet(ctx context.Context, iface string, cidr string) error { ip, _, err := net.ParseCIDR(cidr) if err != nil { return errors.Wrap(err, "invalid cidr") @@ -21,7 +21,7 @@ func (vi *VM) ConfigureInterfaceStaticNet(ctx context.Context, iface string, cid return fmt.Errorf("ipv6 addresses accepted only (have '%v')", ip) } - sc, err := vi.DialSSH() + sc, err := vm.DialSSH() if err != nil { return errors.Wrap(err, "dial ssh") }