diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index eeb8bf7ca0d..7527039c50d 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -80,7 +80,7 @@ type Driver interface { Info() Info // SetConfig sets the configuration for the instance. - Configure(inst *store.Instance, sshLocalPort int) *ConfiguredDriver + Configure(inst *store.Instance) *ConfiguredDriver } type ConfiguredDriver struct { diff --git a/pkg/driver/external/client/methods.go b/pkg/driver/external/client/methods.go index 5bd4dfb6319..120d2b3f088 100644 --- a/pkg/driver/external/client/methods.go +++ b/pkg/driver/external/client/methods.go @@ -281,8 +281,8 @@ func (d *DriverClient) Info() driver.Info { return info } -func (d *DriverClient) Configure(inst *store.Instance, sshLocalPort int) *driver.ConfiguredDriver { - d.logger.Debugf("Setting config for instance %s with SSH local port %d", inst.Name, sshLocalPort) +func (d *DriverClient) Configure(inst *store.Instance) *driver.ConfiguredDriver { + d.logger.Debugf("Setting config for instance %s with SSH local port %d", inst.Name, inst.SSHLocalPort) instJSON, err := inst.MarshalJSON() if err != nil { @@ -295,7 +295,6 @@ func (d *DriverClient) Configure(inst *store.Instance, sshLocalPort int) *driver _, err = d.DriverSvc.SetConfig(ctx, &pb.SetConfigRequest{ InstanceConfigJson: instJSON, - SshLocalPort: int64(sshLocalPort), }) if err != nil { d.logger.Errorf("Failed to set config: %v", err) diff --git a/pkg/driver/external/driver.pb.go b/pkg/driver/external/driver.pb.go index 29719a4a2ec..96ae1b4befd 100644 --- a/pkg/driver/external/driver.pb.go +++ b/pkg/driver/external/driver.pb.go @@ -121,7 +121,6 @@ func (x *StartResponse) GetError() string { type SetConfigRequest struct { state protoimpl.MessageState `protogen:"open.v1"` InstanceConfigJson []byte `protobuf:"bytes,1,opt,name=instance_config_json,json=instanceConfigJson,proto3" json:"instance_config_json,omitempty"` - SshLocalPort int64 `protobuf:"varint,3,opt,name=ssh_local_port,json=sshLocalPort,proto3" json:"ssh_local_port,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -163,13 +162,6 @@ func (x *SetConfigRequest) GetInstanceConfigJson() []byte { return nil } -func (x *SetConfigRequest) GetSshLocalPort() int64 { - if x != nil { - return x.SshLocalPort - } - return 0 -} - type ChangeDisplayPasswordRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Password string `protobuf:"bytes,1,opt,name=password,proto3" json:"password,omitempty"` @@ -487,10 +479,9 @@ const file_pkg_driver_external_driver_proto_rawDesc = "" + "\tinfo_json\x18\x01 \x01(\fR\binfoJson\"?\n" + "\rStartResponse\x12\x18\n" + "\asuccess\x18\x01 \x01(\bR\asuccess\x12\x14\n" + - "\x05error\x18\x02 \x01(\tR\x05error\"j\n" + + "\x05error\x18\x02 \x01(\tR\x05error\"D\n" + "\x10SetConfigRequest\x120\n" + - "\x14instance_config_json\x18\x01 \x01(\fR\x12instanceConfigJson\x12$\n" + - "\x0essh_local_port\x18\x03 \x01(\x03R\fsshLocalPort\":\n" + + "\x14instance_config_json\x18\x01 \x01(\fR\x12instanceConfigJson\":\n" + "\x1cChangeDisplayPasswordRequest\x12\x1a\n" + "\bpassword\x18\x01 \x01(\tR\bpassword\">\n" + "\x1cGetDisplayConnectionResponse\x12\x1e\n" + @@ -528,7 +519,7 @@ const file_pkg_driver_external_driver_proto_rawDesc = "" + "\x11ForwardGuestAgent\x12\x16.google.protobuf.Empty\x1a\x1a.ForwardGuestAgentResponse\x12@\n" + "\x0eGuestAgentConn\x12\x16.google.protobuf.Empty\x1a\x16.google.protobuf.Empty\x126\n" + "\tSetConfig\x12\x11.SetConfigRequest\x1a\x16.google.protobuf.Empty\x120\n" + - "\aGetInfo\x12\x16.google.protobuf.Empty\x1a\r.InfoResponseB-Z+github.com/lima-vm/lima/pkg/driver/externalb\x06proto3" + "\aGetInfo\x12\x16.google.protobuf.Empty\x1a\r.InfoResponseB0Z.github.com/lima-vm/lima/v2/pkg/driver/externalb\x06proto3" var ( file_pkg_driver_external_driver_proto_rawDescOnce sync.Once diff --git a/pkg/driver/external/driver.proto b/pkg/driver/external/driver.proto index 83c8b4c53ba..48282c50360 100644 --- a/pkg/driver/external/driver.proto +++ b/pkg/driver/external/driver.proto @@ -42,7 +42,6 @@ message StartResponse { message SetConfigRequest { bytes instance_config_json = 1; - int64 ssh_local_port = 3; } message ChangeDisplayPasswordRequest { diff --git a/pkg/driver/external/server/methods.go b/pkg/driver/external/server/methods.go index 5c773c8753b..44c190fe925 100644 --- a/pkg/driver/external/server/methods.go +++ b/pkg/driver/external/server/methods.go @@ -62,7 +62,7 @@ func (s *DriverServer) SetConfig(_ context.Context, req *pb.SetConfigRequest) (* return &emptypb.Empty{}, err } - _ = s.driver.Configure(&inst, int(req.SshLocalPort)) + _ = s.driver.Configure(&inst) return &emptypb.Empty{}, nil } diff --git a/pkg/driver/qemu/qemu_driver.go b/pkg/driver/qemu/qemu_driver.go index 2d2c2e43ee1..7ab3947cfb8 100644 --- a/pkg/driver/qemu/qemu_driver.go +++ b/pkg/driver/qemu/qemu_driver.go @@ -64,9 +64,9 @@ func New() *LimaQemuDriver { } } -func (l *LimaQemuDriver) Configure(inst *store.Instance, sshLocalPort int) *driver.ConfiguredDriver { +func (l *LimaQemuDriver) Configure(inst *store.Instance) *driver.ConfiguredDriver { l.Instance = inst - l.SSHLocalPort = sshLocalPort + l.SSHLocalPort = inst.SSHLocalPort return &driver.ConfiguredDriver{ Driver: l, diff --git a/pkg/driver/vz/vz_driver_darwin.go b/pkg/driver/vz/vz_driver_darwin.go index e28f082f471..605bac31709 100644 --- a/pkg/driver/vz/vz_driver_darwin.go +++ b/pkg/driver/vz/vz_driver_darwin.go @@ -87,9 +87,9 @@ func New() *LimaVzDriver { } } -func (l *LimaVzDriver) Configure(inst *store.Instance, sshLocalPort int) *driver.ConfiguredDriver { +func (l *LimaVzDriver) Configure(inst *store.Instance) *driver.ConfiguredDriver { l.Instance = inst - l.SSHLocalPort = sshLocalPort + l.SSHLocalPort = inst.SSHLocalPort return &driver.ConfiguredDriver{ Driver: l, diff --git a/pkg/driver/wsl2/wsl_driver_windows.go b/pkg/driver/wsl2/wsl_driver_windows.go index 1f2d6393a88..54d96992d17 100644 --- a/pkg/driver/wsl2/wsl_driver_windows.go +++ b/pkg/driver/wsl2/wsl_driver_windows.go @@ -68,9 +68,9 @@ func New() *LimaWslDriver { } } -func (l *LimaWslDriver) Configure(inst *store.Instance, sshLocalPort int) *driver.ConfiguredDriver { +func (l *LimaWslDriver) Configure(inst *store.Instance) *driver.ConfiguredDriver { l.Instance = inst - l.SSHLocalPort = sshLocalPort + l.SSHLocalPort = inst.SSHLocalPort return &driver.ConfiguredDriver{ Driver: l, diff --git a/pkg/driverutil/instance.go b/pkg/driverutil/instance.go index f135cc8f61b..2d865a806db 100644 --- a/pkg/driverutil/instance.go +++ b/pkg/driverutil/instance.go @@ -22,6 +22,7 @@ func CreateConfiguredDriver(inst *store.Instance, sshLocalPort int) (*driver.Con return nil, fmt.Errorf("unknown or unsupported VM type: %s", *limaDriver) } + inst.SSHLocalPort = sshLocalPort if extDriver != nil { extDriver.Logger.Debugf("Using external driver %q", extDriver.Name) if extDriver.Client == nil || extDriver.Command == nil { @@ -35,9 +36,9 @@ func CreateConfiguredDriver(inst *store.Instance, sshLocalPort int) (*driver.Con extDriver.InstanceName = inst.Name } - return extDriver.Client.Configure(inst, sshLocalPort), nil + return extDriver.Client.Configure(inst), nil } logrus.Debugf("Using internal driver %q", intDriver.Info().DriverName) - return intDriver.Configure(inst, sshLocalPort), nil + return intDriver.Configure(inst), nil } diff --git a/pkg/registry/registry_test.go b/pkg/registry/registry_test.go index 39afcee557d..4abd3a54159 100644 --- a/pkg/registry/registry_test.go +++ b/pkg/registry/registry_test.go @@ -27,24 +27,24 @@ func newMockDriver(name string) *mockDriver { var _ driver.Driver = (*mockDriver)(nil) -func (m *mockDriver) Validate() error { return nil } -func (m *mockDriver) Initialize(_ context.Context) error { return nil } -func (m *mockDriver) CreateDisk(_ context.Context) error { return nil } -func (m *mockDriver) Start(_ context.Context) (chan error, error) { return nil, nil } -func (m *mockDriver) Stop(_ context.Context) error { return nil } -func (m *mockDriver) RunGUI() error { return nil } -func (m *mockDriver) ChangeDisplayPassword(_ context.Context, _ string) error { return nil } -func (m *mockDriver) DisplayConnection(_ context.Context) (string, error) { return "", nil } -func (m *mockDriver) CreateSnapshot(_ context.Context, _ string) error { return nil } -func (m *mockDriver) ApplySnapshot(_ context.Context, _ string) error { return nil } -func (m *mockDriver) DeleteSnapshot(_ context.Context, _ string) error { return nil } -func (m *mockDriver) ListSnapshots(_ context.Context) (string, error) { return "", nil } -func (m *mockDriver) Register(_ context.Context) error { return nil } -func (m *mockDriver) Unregister(_ context.Context) error { return nil } -func (m *mockDriver) ForwardGuestAgent() bool { return false } -func (m *mockDriver) GuestAgentConn(_ context.Context) (net.Conn, string, error) { return nil, "", nil } -func (m *mockDriver) Info() driver.Info { return driver.Info{DriverName: m.Name} } -func (m *mockDriver) Configure(_ *store.Instance, _ int) *driver.ConfiguredDriver { return nil } +func (m *mockDriver) Validate() error { return nil } +func (m *mockDriver) Initialize(_ context.Context) error { return nil } +func (m *mockDriver) CreateDisk(_ context.Context) error { return nil } +func (m *mockDriver) Start(_ context.Context) (chan error, error) { return nil, nil } +func (m *mockDriver) Stop(_ context.Context) error { return nil } +func (m *mockDriver) RunGUI() error { return nil } +func (m *mockDriver) ChangeDisplayPassword(_ context.Context, _ string) error { return nil } +func (m *mockDriver) DisplayConnection(_ context.Context) (string, error) { return "", nil } +func (m *mockDriver) CreateSnapshot(_ context.Context, _ string) error { return nil } +func (m *mockDriver) ApplySnapshot(_ context.Context, _ string) error { return nil } +func (m *mockDriver) DeleteSnapshot(_ context.Context, _ string) error { return nil } +func (m *mockDriver) ListSnapshots(_ context.Context) (string, error) { return "", nil } +func (m *mockDriver) Register(_ context.Context) error { return nil } +func (m *mockDriver) Unregister(_ context.Context) error { return nil } +func (m *mockDriver) ForwardGuestAgent() bool { return false } +func (m *mockDriver) GuestAgentConn(_ context.Context) (net.Conn, string, error) { return nil, "", nil } +func (m *mockDriver) Info() driver.Info { return driver.Info{DriverName: m.Name} } +func (m *mockDriver) Configure(_ *store.Instance) *driver.ConfiguredDriver { return nil } func TestRegister(t *testing.T) { BackupRegistry(t)