| 1 | syntax = "proto3"; |
| 2 | |
| 3 | import "google/protobuf/empty.proto"; |
| 4 | |
| 5 | option go_package = "github.com/lima-vm/lima/v2/pkg/driver/external"; |
| 6 | |
| 7 | // Driver is the transport used by an external VM driver. It is the gRPC |
| 8 | // projection of the Go `driver.Driver` interface (pkg/driver/driver.go): the |
| 9 | // host agent runs a gRPC client and each external driver binary |
| 10 | // (lima-driver-<name>) runs the server. The RPCs mirror the interface methods |
| 11 | // one-to-one, so this file is the authoritative contract for driver authors. |
| 12 | // |
| 13 | // Call ordering on the instance start path: instance.Prepare (pkg/instance) |
| 14 | // runs steps 1-4, then the host agent (pkg/hostagent) boots the VM and runs |
| 15 | // steps 5-7. Creating an instance without starting it (limactl create) only |
| 16 | // runs Configure and Create. |
| 17 | // 1. Configure - set the instance config; must run before any method that |
| 18 | // depends on it. |
| 19 | // 2. Validate - reject configs the driver cannot support. |
| 20 | // 3. Create - first-time provisioning; a no-op on existing instances. |
| 21 | // 4. CreateDisk - create the instance disk(s). |
| 22 | // 5. Start - begin booting the VM. It returns once boot has been |
| 23 | // initiated (the initial StartResponse), not once the guest has finished |
| 24 | // booting; later boot errors arrive on the stream. See StartResponse. |
| 25 | // 6. AdditionalSetupForSSH - runs right after Start returns (boot initiated, |
| 26 | // the guest is not necessarily up yet), before the first SSH connection. |
| 27 | // 7. SSHAddress - re-queried after Start only when Info reports |
| 28 | // Features.dynamicSSHAddress. |
| 29 | // |
| 30 | // Unless stated otherwise, an RPC returning google.protobuf.Empty completes |
| 31 | // synchronously and reports failures as a gRPC error status. Requests and |
| 32 | // responses that carry structured data use JSON payloads (Info, Configure) to |
| 33 | // stay in sync with the Go types without duplicating them here. |
| 34 | // |
| 35 | // Concurrency: the start-path RPCs above are invoked sequentially in the |
| 36 | // order listed. Once the VM is running, the host agent polls read-only RPCs |
| 37 | // (notably Info and ForwardGuestAgent) from background goroutines, so the |
| 38 | // driver server must be safe to handle concurrent RPCs. |
| 39 | service Driver { |
| 40 | // Validate reports whether the driver supports the currently configured |
| 41 | // instance. It is called early on the start path, before Create. Returning |
| 42 | // an error aborts the operation. |
| 43 | rpc Validate(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 44 | |
| 45 | // Create performs first-time provisioning of the instance (e.g. writing a |
| 46 | // "vz-identifier" file). It MUST return successfully (no-op) when called |
| 47 | // against an instance that already exists, and it MUST NOT create the disks |
| 48 | // (that is CreateDisk's job). |
| 49 | rpc Create(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 50 | |
| 51 | // CreateDisk creates the instance disk(s). It is called after Create. |
| 52 | rpc CreateDisk(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 53 | |
| 54 | // Start begins booting the VM. It is a server-streaming RPC that mirrors the |
| 55 | // `(chan error, error)` return of the in-process interface: the call returns |
| 56 | // once boot has been initiated (the initial StartResponse), not once the |
| 57 | // guest has finished booting, and later boot errors arrive on the stream. See |
| 58 | // StartResponse for the streaming protocol. |
| 59 | rpc Start(google.protobuf.Empty) returns (stream StartResponse); |
| 60 | |
| 61 | // Stop terminates the running VM. It blocks until the VM has fully exited |
| 62 | // (or the driver's internal shutdown deadline elapses) and returns a gRPC |
| 63 | // error status if the shutdown failed. |
| 64 | rpc Stop(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 65 | |
| 66 | // Delete removes the instance created by Create (and its driver-specific |
| 67 | // files). The generic instance directory is removed by the host agent. |
| 68 | rpc Delete(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 69 | |
| 70 | // BootScripts returns the boot scripts to inject into the VM via cloud-init. |
| 71 | // See BootScriptsResponse for the required key format. |
| 72 | rpc BootScripts(google.protobuf.Empty) returns (BootScriptsResponse); |
| 73 | |
| 74 | // RunGUI starts the GUI synchronously. It blocks and returns only after the |
| 75 | // VM terminates. It is only used by drivers that report Features.canRunGui. |
| 76 | rpc RunGUI(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 77 | |
| 78 | // ChangeDisplayPassword sets the password for the VM display (e.g. VNC). |
| 79 | rpc ChangeDisplayPassword(ChangeDisplayPasswordRequest) returns (google.protobuf.Empty); |
| 80 | |
| 81 | // GetDisplayConnection returns the connection string for the VM display. |
| 82 | rpc GetDisplayConnection(google.protobuf.Empty) returns (GetDisplayConnectionResponse); |
| 83 | |
| 84 | // CreateSnapshot creates a VM snapshot identified by the given tag. |
| 85 | rpc CreateSnapshot(CreateSnapshotRequest) returns (google.protobuf.Empty); |
| 86 | |
| 87 | // ApplySnapshot restores the VM to the snapshot identified by the given tag. |
| 88 | rpc ApplySnapshot(ApplySnapshotRequest) returns (google.protobuf.Empty); |
| 89 | |
| 90 | // DeleteSnapshot removes the snapshot identified by the given tag. |
| 91 | rpc DeleteSnapshot(DeleteSnapshotRequest) returns (google.protobuf.Empty); |
| 92 | |
| 93 | // ListSnapshots returns the driver-formatted list of existing snapshots. |
| 94 | rpc ListSnapshots(google.protobuf.Empty) returns (ListSnapshotsResponse); |
| 95 | |
| 96 | // ForwardGuestAgent reports whether the host agent must forward the guest |
| 97 | // agent socket over SSH. When false, the driver provides a direct guest agent |
| 98 | // connection via GuestAgentConn (e.g. vsock/virtio). |
| 99 | rpc ForwardGuestAgent(google.protobuf.Empty) returns (ForwardGuestAgentResponse); |
| 100 | |
| 101 | // GuestAgentConn returns a direct guest agent connection, used when |
| 102 | // ForwardGuestAgent is false; it returns nil when the socket is forwarded |
| 103 | // over SSH instead. Over this transport the server bridges the connection to |
| 104 | // a unix socket in the instance directory when it is not already one, so the |
| 105 | // client relies on that socket rather than on a returned connection. |
| 106 | rpc GuestAgentConn(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 107 | |
| 108 | // Configure sets the instance configuration on the driver. It must be called |
| 109 | // before RPCs that depend on the config. |
| 110 | rpc Configure(SetConfigRequest) returns (SetConfigResponse); |
| 111 | |
| 112 | // Info returns driver metadata and capability flags (see InfoResponse). The |
| 113 | // host agent uses it to discover features such as dynamicSSHAddress. |
| 114 | rpc Info(google.protobuf.Empty) returns (InfoResponse); |
| 115 | |
| 116 | // SSHAddress returns the address used to SSH into the guest. For drivers that |
| 117 | // report Features.dynamicSSHAddress the address is not known until after |
| 118 | // Start, so the host agent re-queries it at that point. |
| 119 | rpc SSHAddress(google.protobuf.Empty) returns (SSHAddressResponse); |
| 120 | |
| 121 | // AdditionalSetupForSSH provides additional setup required for SSH connection. |
| 122 | // It is called right after Start returns (boot initiated, the guest is not |
| 123 | // necessarily up yet), before the first SSH connection. |
| 124 | rpc AdditionalSetupForSSH(google.protobuf.Empty) returns (google.protobuf.Empty); |
| 125 | } |
| 126 | |
| 127 | // BootScriptsResponse carries the boot scripts injected into the VM. |
| 128 | message BootScriptsResponse { |
| 129 | // Maps a script path to its content. Each key must be |
| 130 | // "boot.<OS>/<SCRIPT>", or "<SCRIPT>" as a deprecated alias for |
| 131 | // "boot.Linux/<SCRIPT>". |
| 132 | map<string, bytes> scripts = 1; |
| 133 | } |
| 134 | |
| 135 | // SSHAddressResponse carries the guest SSH address. |
| 136 | message SSHAddressResponse { |
| 137 | // Host/IP used to SSH into the guest. |
| 138 | string address = 1; |
| 139 | } |
| 140 | |
| 141 | // InfoResponse carries driver metadata and capability flags. |
| 142 | message InfoResponse { |
| 143 | // JSON-encoded driver.Info (name, ports, instance dir and feature flags). |
| 144 | // JSON keeps it in sync with the Go type. The full set of fields is defined at |
| 145 | // https://pkg.go.dev/github.com/lima-vm/lima/v2/pkg/driver#Info |
| 146 | bytes info_json = 1; |
| 147 | } |
| 148 | |
| 149 | // StartResponse is a streamed response for the Start RPC. It mimics the |
| 150 | // errChan from pkg/driver/driver.go. The server sends an initial response with |
| 151 | // success=true once Start is initiated (this unblocks the client). If errors |
| 152 | // occur they are sent as success=false with the error field populated. When the |
| 153 | // error channel closes, a final success=true message is sent and the stream ends. |
| 154 | message StartResponse { |
| 155 | // True for the initial "started" message and the final "done" message, and |
| 156 | // false for each streamed error. |
| 157 | bool success = 1; |
| 158 | // Error message when success is false; empty otherwise. |
| 159 | string error = 2; |
| 160 | } |
| 161 | |
| 162 | // SetConfigRequest carries the instance configuration for Configure. |
| 163 | message SetConfigRequest { |
| 164 | // JSON-encoded limatype.Instance. JSON keeps it in sync with the Go type. |
| 165 | bytes instance_config_json = 1; |
| 166 | } |
| 167 | |
| 168 | // SetConfigResponse carries the instance configuration after Configure applied |
| 169 | // the driver's defaults and validation. It is returned so the caller picks up |
| 170 | // those changes (the in-process interface mutates the instance in place). |
| 171 | message SetConfigResponse { |
| 172 | // JSON-encoded limatype.Instance after Configure applied the driver's defaults |
| 173 | // and validation. JSON keeps it in sync with the Go type. |
| 174 | bytes instance_config_json = 1; |
| 175 | } |
| 176 | |
| 177 | // ChangeDisplayPasswordRequest carries the new display password. |
| 178 | message ChangeDisplayPasswordRequest { |
| 179 | // New VM display (e.g. VNC) password. |
| 180 | string password = 1; |
| 181 | } |
| 182 | |
| 183 | // GetDisplayConnectionResponse carries the VM display connection string. |
| 184 | message GetDisplayConnectionResponse { |
| 185 | // Driver-specific display connection string. |
| 186 | string connection = 1; |
| 187 | } |
| 188 | |
| 189 | // CreateSnapshotRequest identifies the snapshot to create. |
| 190 | message CreateSnapshotRequest { |
| 191 | // Names the snapshot. |
| 192 | string tag = 1; |
| 193 | } |
| 194 | |
| 195 | // ApplySnapshotRequest identifies the snapshot to restore. |
| 196 | message ApplySnapshotRequest { |
| 197 | // Names the snapshot to restore. |
| 198 | string tag = 1; |
| 199 | } |
| 200 | |
| 201 | // DeleteSnapshotRequest identifies the snapshot to delete. |
| 202 | message DeleteSnapshotRequest { |
| 203 | // Names the snapshot to delete. |
| 204 | string tag = 1; |
| 205 | } |
| 206 | |
| 207 | // ListSnapshotsResponse carries the existing snapshots. |
| 208 | message ListSnapshotsResponse { |
| 209 | // Driver-formatted list of existing snapshots. |
| 210 | string snapshots = 1; |
| 211 | } |
| 212 | |
| 213 | // ForwardGuestAgentResponse reports how the guest agent is reached. |
| 214 | message ForwardGuestAgentResponse { |
| 215 | // True when the host agent forwards the guest agent socket over SSH; false |
| 216 | // means the driver provides a direct connection via GuestAgentConn. |
| 217 | bool should_forward = 1; |
| 218 | } |