Skip to content

Commit ecf4026

Browse files
committed
update driver interface
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 6c0e64a commit ecf4026

File tree

10 files changed

+66
-60
lines changed

10 files changed

+66
-60
lines changed

pkg/driver/driver.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ type Lifecycle interface {
1515
// Validate returns error if the current driver isn't support for given config
1616
Validate() error
1717

18-
// Initialize is called on creating the instance for initialization.
18+
// Create is called on creating the instance for the first time.
1919
// (e.g., creating "vz-identifier" file)
2020
//
21-
// Initialize MUST return nil when it is called against an existing instance.
21+
// Create MUST return nil when it is called against an existing instance.
2222
//
23-
// Initialize does not create the disks.
24-
Initialize(_ context.Context) error
23+
// Create does not create the disks.
24+
Create(_ context.Context) error
2525

2626
// CreateDisk returns error if the current driver fails in creating disk
2727
CreateDisk(_ context.Context) error
@@ -34,6 +34,8 @@ type Lifecycle interface {
3434
// Stop will terminate the running vm instance.
3535
// It returns error if there are any errors during Stop
3636
Stop(_ context.Context) error
37+
38+
Delete(_ context.Context) error
3739
}
3840

3941
// GUI defines GUI-related operations.
@@ -54,12 +56,6 @@ type SnapshotManager interface {
5456
ListSnapshots(ctx context.Context) (string, error)
5557
}
5658

57-
// Registration defines operations for registering and unregistering the driver instance.
58-
type Registration interface {
59-
Register(ctx context.Context) error
60-
Unregister(ctx context.Context) error
61-
}
62-
6359
// GuestAgent defines operations for the guest agent.
6460
type GuestAgent interface {
6561
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
@@ -74,7 +70,6 @@ type Driver interface {
7470
Lifecycle
7571
GUI
7672
SnapshotManager
77-
Registration
7873
GuestAgent
7974

8075
Info() Info

pkg/driver/external/client/methods.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (d *DriverClient) Validate() error {
3333
return nil
3434
}
3535

36-
func (d *DriverClient) Initialize(ctx context.Context) error {
36+
func (d *DriverClient) Create(ctx context.Context) error {
3737
d.logger.Debug("Initializing driver instance")
3838

3939
_, err := d.DriverSvc.Initialize(ctx, &emptypb.Empty{})
@@ -307,6 +307,10 @@ func (d *DriverClient) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
307307
}
308308
}
309309

310+
func (d *DriverClient) Delete(ctx context.Context) error {
311+
return errors.New("AcceptConfig not implemented in DriverClient")
312+
}
313+
310314
func (d *DriverClient) AcceptConfig(cfg *limatype.LimaYAML, filepath string) error {
311315
return errors.New("AcceptConfig not implemented in DriverClient")
312316
}

pkg/driver/external/server/methods.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ func (s *DriverServer) Validate(_ context.Context, empty *emptypb.Empty) (*empty
127127
return empty, nil
128128
}
129129

130+
// TODO: Update the proto file
130131
func (s *DriverServer) Initialize(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) {
131132
s.logger.Debug("Received Initialize request")
132-
err := s.driver.Initialize(ctx)
133+
err := s.driver.Create(ctx)
133134
if err != nil {
134135
s.logger.Errorf("Initialization failed: %v", err)
135136
return empty, err
@@ -237,27 +238,28 @@ func (s *DriverServer) ListSnapshots(ctx context.Context, _ *emptypb.Empty) (*pb
237238
return &pb.ListSnapshotsResponse{Snapshots: snapshots}, nil
238239
}
239240

240-
func (s *DriverServer) Register(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) {
241-
s.logger.Debug("Received Register request")
242-
err := s.driver.Register(ctx)
243-
if err != nil {
244-
s.logger.Errorf("Register failed: %v", err)
245-
return empty, err
246-
}
247-
s.logger.Debug("Register succeeded")
248-
return empty, nil
249-
}
250-
251-
func (s *DriverServer) Unregister(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) {
252-
s.logger.Debug("Received Unregister request")
253-
err := s.driver.Unregister(ctx)
254-
if err != nil {
255-
s.logger.Errorf("Unregister failed: %v", err)
256-
return empty, err
257-
}
258-
s.logger.Debug("Unregister succeeded")
259-
return empty, nil
260-
}
241+
// TODO: Delete these methods and update the proto file accordingly
242+
// func (s *DriverServer) Register(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) {
243+
// s.logger.Debug("Received Register request")
244+
// err := s.driver.Register(ctx)
245+
// if err != nil {
246+
// s.logger.Errorf("Register failed: %v", err)
247+
// return empty, err
248+
// }
249+
// s.logger.Debug("Register succeeded")
250+
// return empty, nil
251+
// }
252+
253+
// func (s *DriverServer) Unregister(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) {
254+
// s.logger.Debug("Received Unregister request")
255+
// err := s.driver.Unregister(ctx)
256+
// if err != nil {
257+
// s.logger.Errorf("Unregister failed: %v", err)
258+
// return empty, err
259+
// }
260+
// s.logger.Debug("Unregister succeeded")
261+
// return empty, nil
262+
// }
261263

262264
func (s *DriverServer) ForwardGuestAgent(_ context.Context, _ *emptypb.Empty) (*pb.ForwardGuestAgentResponse, error) {
263265
s.logger.Debug("Received ForwardGuestAgent request")

pkg/driver/qemu/qemu_driver.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ func (l *LimaQemuDriver) Info() driver.Info {
641641
return info
642642
}
643643

644-
func (l *LimaQemuDriver) Initialize(_ context.Context) error {
644+
func (l *LimaQemuDriver) Create(_ context.Context) error {
645+
return nil
646+
}
647+
648+
func (l *LimaQemuDriver) Delete(ctx context.Context) error {
645649
return nil
646650
}
647651

pkg/driver/vz/vz_driver_darwin.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (l *LimaVzDriver) Validate() error {
223223
return nil
224224
}
225225

226-
func (l *LimaVzDriver) Initialize(_ context.Context) error {
226+
func (l *LimaVzDriver) Create(_ context.Context) error {
227227
_, err := getMachineIdentifier(l.Instance)
228228
return err
229229
}
@@ -316,6 +316,10 @@ func (l *LimaVzDriver) Info() driver.Info {
316316
return info
317317
}
318318

319+
func (l *LimaVzDriver) Delete(ctx context.Context) error {
320+
return nil
321+
}
322+
319323
func (l *LimaVzDriver) Register(_ context.Context) error {
320324
return nil
321325
}

pkg/driver/wsl2/wsl_driver_windows.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ func (l *LimaWslDriver) Validate() error {
158158
return nil
159159
}
160160

161+
func (l *LimaWslDriver) Delete(ctx context.Context) error {
162+
distroName := "lima-" + l.Instance.Name
163+
status, err := store.GetWslStatus(l.Instance.Name)
164+
if err != nil {
165+
return err
166+
}
167+
switch status {
168+
case limatype.StatusRunning, limatype.StatusStopped, limatype.StatusBroken, limatype.StatusInstalling:
169+
return unregisterVM(ctx, distroName)
170+
}
171+
172+
logrus.Info("WSL VM is not running or does not exist, skipping deletion")
173+
return nil
174+
}
175+
161176
func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
162177
logrus.Infof("Starting WSL VM")
163178
status, err := store.GetWslStatus(l.Instance.Name)
@@ -213,21 +228,6 @@ func (l *LimaWslDriver) Stop(ctx context.Context) error {
213228
return stopVM(ctx, distroName)
214229
}
215230

216-
func (l *LimaWslDriver) Unregister(ctx context.Context) error {
217-
distroName := "lima-" + l.Instance.Name
218-
status, err := store.GetWslStatus(l.Instance.Name)
219-
if err != nil {
220-
return err
221-
}
222-
switch status {
223-
case limatype.StatusRunning, limatype.StatusStopped, limatype.StatusBroken, limatype.StatusInstalling:
224-
return unregisterVM(ctx, distroName)
225-
}
226-
227-
logrus.Info("VM not registered, skipping unregistration")
228-
return nil
229-
}
230-
231231
// GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
232232
// As of 08-01-2024, github.com/mdlayher/vsock does not natively support vsock on
233233
// Windows, so use the winio library to create the connection.
@@ -264,18 +264,14 @@ func (l *LimaWslDriver) Info() driver.Info {
264264
return info
265265
}
266266

267-
func (l *LimaWslDriver) Initialize(_ context.Context) error {
267+
func (l *LimaWslDriver) Create(_ context.Context) error {
268268
return nil
269269
}
270270

271271
func (l *LimaWslDriver) CreateDisk(_ context.Context) error {
272272
return nil
273273
}
274274

275-
func (l *LimaWslDriver) Register(_ context.Context) error {
276-
return nil
277-
}
278-
279275
func (l *LimaWslDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
280276
return nil
281277
}

pkg/instance/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Create(ctx context.Context, instName string, instConfig []byte, saveBrokenY
8585
return nil, fmt.Errorf("failed to create driver instance: %w", err)
8686
}
8787

88-
if err := limaDriver.Register(ctx); err != nil {
88+
if err := limaDriver.Create(ctx); err != nil {
8989
return nil, err
9090
}
9191

pkg/instance/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ func unregister(ctx context.Context, inst *limatype.Instance) error {
4141
return fmt.Errorf("failed to create driver instance: %w", err)
4242
}
4343

44-
return limaDriver.Unregister(ctx)
44+
return limaDriver.Delete(ctx)
4545
}

pkg/instance/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func Prepare(ctx context.Context, inst *limatype.Instance) (*Prepared, error) {
9797
return nil, err
9898
}
9999

100-
if err := limaDriver.Initialize(ctx); err != nil {
100+
if err := limaDriver.Create(ctx); err != nil {
101101
return nil, err
102102
}
103103

pkg/registry/registry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ func newMockDriver(name string) *mockDriver {
2828
var _ driver.Driver = (*mockDriver)(nil)
2929

3030
func (m *mockDriver) Validate() error { return nil }
31-
func (m *mockDriver) Initialize(_ context.Context) error { return nil }
31+
func (m *mockDriver) Create(_ context.Context) error { return nil }
32+
func (m *mockDriver) Delete(_ context.Context) error { return nil }
3233
func (m *mockDriver) CreateDisk(_ context.Context) error { return nil }
3334
func (m *mockDriver) Start(_ context.Context) (chan error, error) { return nil, nil }
3435
func (m *mockDriver) Stop(_ context.Context) error { return nil }

0 commit comments

Comments
 (0)