-
Notifications
You must be signed in to change notification settings - Fork 648
/
Copy pathdriver.go
158 lines (117 loc) · 4.29 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package driver
import (
"context"
"fmt"
"net"
"github.com/lima-vm/lima/pkg/store"
)
// Driver interface is used by hostagent for managing vm.
//
// This interface is extended by BaseDriver which provides default implementation.
// All other driver definition must extend BaseDriver.
type Driver interface {
// Validate returns error if the current driver isn't support for given config
Validate() error
// Initialize is called on creating the instance for initialization.
// (e.g., creating "vz-identifier" file)
//
// Initialize MUST return nil when it is called against an existing instance.
//
// Initialize does not create the disks.
Initialize(_ context.Context) error
// CreateDisk returns error if the current driver fails in creating disk
CreateDisk(_ context.Context) error
// Start is used for booting the vm using driver instance
// It returns a chan error on successful boot
// The second argument may contain error occurred while starting driver
Start(_ context.Context) (chan error, error)
// CanRunGUI returns bool to indicate if the hostagent need to run GUI synchronously
CanRunGUI() bool
// RunGUI is for starting GUI synchronously by hostagent. This method should be wait and return only after vm terminates
// It returns error if there are any failures
RunGUI() error
// Stop will terminate the running vm instance.
// It returns error if there are any errors during Stop
Stop(_ context.Context) error
// Register will add an instance to a registry.
// It returns error if there are any errors during Register
Register(_ context.Context) error
// Unregister will perform any cleanup related to the vm instance.
// It returns error if there are any errors during Unregister
Unregister(_ context.Context) error
ChangeDisplayPassword(_ context.Context, password string) error
GetDisplayConnection(_ context.Context) (string, error)
CreateSnapshot(_ context.Context, tag string) error
ApplySnapshot(_ context.Context, tag string) error
DeleteSnapshot(_ context.Context, tag string) error
ListSnapshots(_ context.Context) (string, error)
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
ForwardGuestAgent() bool
// GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
GuestAgentConn(_ context.Context) (net.Conn, error)
// RuntimeConfig accepts config containing changes to the runtime configuration, and returns the updated runtime configuration.
RuntimeConfig(_ context.Context, config interface{}) (interface{}, error)
}
type BaseDriver struct {
Instance *store.Instance
SSHLocalPort int
VSockPort int
VirtioPort string
}
var _ Driver = (*BaseDriver)(nil)
func (d *BaseDriver) Validate() error {
return nil
}
func (d *BaseDriver) Initialize(_ context.Context) error {
return nil
}
func (d *BaseDriver) CreateDisk(_ context.Context) error {
return nil
}
func (d *BaseDriver) Start(_ context.Context) (chan error, error) {
return nil, nil
}
func (d *BaseDriver) CanRunGUI() bool {
return false
}
func (d *BaseDriver) RunGUI() error {
return nil
}
func (d *BaseDriver) Stop(_ context.Context) error {
return nil
}
func (d *BaseDriver) Register(_ context.Context) error {
return nil
}
func (d *BaseDriver) Unregister(_ context.Context) error {
return nil
}
func (d *BaseDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
return nil
}
func (d *BaseDriver) GetDisplayConnection(_ context.Context) (string, error) {
return "", nil
}
func (d *BaseDriver) CreateSnapshot(_ context.Context, _ string) error {
return fmt.Errorf("unimplemented")
}
func (d *BaseDriver) ApplySnapshot(_ context.Context, _ string) error {
return fmt.Errorf("unimplemented")
}
func (d *BaseDriver) DeleteSnapshot(_ context.Context, _ string) error {
return fmt.Errorf("unimplemented")
}
func (d *BaseDriver) ListSnapshots(_ context.Context) (string, error) {
return "", fmt.Errorf("unimplemented")
}
func (d *BaseDriver) ForwardGuestAgent() bool {
// if driver is not providing, use host agent
return d.VSockPort == 0 && d.VirtioPort == ""
}
func (d *BaseDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
// use the unix socket forwarded by host agent
return nil, nil
}
func (d *BaseDriver) RuntimeConfig(_ context.Context, _ interface{}) (interface{}, error) {
return nil, fmt.Errorf("unimplemented")
}