1// Copyright 2023 The ChromiumOS Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5syntax = "proto3"; 6 7package chromiumos.test.api; 8 9option go_package = "go.chromium.org/chromiumos/config/go/test/api"; 10 11import "google/protobuf/duration.proto"; 12import "google/protobuf/timestamp.proto"; 13import "chromiumos/test/api/device_leasing.proto"; 14 15service DeviceLeaseService { 16 // Lease a device and create a lease. 17 rpc LeaseDevice(LeaseDeviceRequest) returns (LeaseDeviceResponse) {}; 18 19 // Bulk lease devices and create leases for all of them. 20 rpc BulkLeaseDevices(BulkLeaseDevicesRequest) returns (BulkLeaseDevicesResponse) {}; 21 22 // Release a device lease. 23 rpc ReleaseDevice(ReleaseDeviceRequest) returns (ReleaseDeviceResponse) {}; 24 25 // Extend a device lease by modifying the expiration time. 26 rpc ExtendLease(ExtendLeaseRequest) returns (ExtendLeaseResponse) {}; 27 28 // Get a device by device id. 29 // Designed to adhere to https://google.aip.dev/131. 30 rpc GetDevice(GetDeviceRequest) returns (Device) {}; 31 32 // List devices managed by Device Manager. 33 // Designed to adhere to https://google.aip.dev/132. 34 rpc ListDevices(ListDevicesRequest) returns (ListDevicesResponse) {}; 35} 36 37message Device { 38 // In the case of VMs, device id could be the GCE instance name. For physical 39 // DUTs we use the IDs we get from UFS. 40 string id = 1; 41 // dut_id is the asset tag for a Device 42 string dut_id = 6; 43 44 DeviceAddress address = 2; 45 DeviceType type = 3; 46 DeviceState state = 4; 47 48 // This proto contains per-DUT hardware relevant information including labels. 49 HardwareRequirements hardware_reqs = 5; 50} 51 52message DeviceAddress { 53 // IP address of the device. 54 // For physical DUTs it can be a hostname. 55 string host = 1; 56 int32 port = 2; 57} 58 59// This is different than device features which are expressed in 60// requirements_eq. This is more about virtual, physical, or either initially. 61enum DeviceType { 62 DEVICE_TYPE_UNSPECIFIED = 0; 63 DEVICE_TYPE_VIRTUAL = 1; 64 DEVICE_TYPE_PHYSICAL = 2; 65} 66 67// The list is not final and can be extended later. 68enum DeviceState { 69 DEVICE_STATE_UNSPECIFIED = 0; 70 // Default state. 71 // Device is available to be leased. 72 DEVICE_STATE_AVAILABLE = 1; 73 // Device is leased. 74 DEVICE_STATE_LEASED = 2; 75} 76 77message DeviceLeaseRecord { 78 // Lease id 79 // Should be uniquely generated by UUID4. 80 string id = 1; 81 // Key specified by client per request. 82 // Requests with the same key will be treated as duplicate requests. 83 string idempotency_key = 2; 84 85 // Device data. 86 // Id (hostname) corresponding to the device name. 87 string device_id = 3; 88 // DUT ID (asset tag) corresponding to the device name. 89 string dut_id = 11; 90 // SSH-able address to access the device. 91 DeviceAddress device_address = 4; 92 // Type of device leased. 93 DeviceType device_type = 5; 94 95 // Tracking times. 96 // Time when the device was leased. 97 google.protobuf.Timestamp leased_time = 6; 98 // Time when the device was released by a request or cron. 99 google.protobuf.Timestamp released_time = 7; 100 // Lease expiration time. The time can be updated several times. 101 // The record keeps the last known value. 102 google.protobuf.Timestamp expiration_time = 8; 103 // Last updated time. The time when the lease was last updated. 104 // This will be used as a versioning timestamp 105 google.protobuf.Timestamp last_updated_time = 9; 106 107 // Request data. 108 // All parameters used to create a device will be saved for further analysis. 109 // Possible that the data will be removed later if established as not needed. 110 map<string,string> request_parameters = 10; 111} 112 113message LeaseDeviceRequest { 114 // Generated on the client side, shared across retries but pseudo-unique 115 // across different logical requests. Requests with the same key will be 116 // treated as duplicate of original request, return the same response. 117 string idempotency_key = 1; 118 119 // This is the final end user (can be human or robot). Useful for both 120 // debugging and analytics. For example, for a tests triggered for a CL, 121 // this field could indicate the CL author as they are the end user. 122 // 123 // For direct invocations like CLI, this is enforced at first entry point 124 // but trusted from there. 125 // 126 // Not to be confused with LUCI auth which is done by the caller assuming 127 // the appropriate identity from a permissions perspective — like LUCI 128 // project. 129 string on_behalf_of = 2; 130 131 // This is the quota the end user is requesting to use. One user can have 132 // access to multiple quotas. For example, release, CQ, performance testing, 133 // etc. 134 string quota_id = 3; 135 136 // Optional with a good default. 137 // Important to configure a good max (e.g. 10 min). This will put a ceiling 138 // on time wasted if the client dies. 139 google.protobuf.Duration lease_duration = 4; 140 141 // The populated requirements will specify what kind of device manager 142 // returns. The client can populate both to indicate that they are ok with 143 // either a VM or Hardware DUT. 144 VMRequirements vm_host_reqs = 5; 145 HardwareRequirements hardware_device_reqs = 6; 146} 147 148message LeaseDeviceResponse { 149 DeviceLeaseRecord device_lease = 1; 150 151 // Eventually we will include authentication token to access device for the 152 // duration of the lease. Shared and long lived secrets are not good security. 153 // Today there is no such enforcement so this is not a regression. 154 155 LeaseDeviceResponseErrorType error_type = 2; 156 string error_string = 3; 157} 158 159enum LeaseDeviceResponseErrorType { 160 LEASE_ERROR_TYPE_NONE = 0; 161 LEASE_ERROR_TYPE_DEVICE_NOT_FOUND = 1; 162 LEASE_ERROR_TYPE_DEVICE_ALREADY_LEASED = 2; 163} 164 165message BulkLeaseDevicesRequest { 166 // A list of LeaseDeviceRequests. 167 repeated LeaseDeviceRequest lease_device_requests = 1; 168} 169 170message BulkLeaseDevicesResponse { 171 // One LeaseDeviceResponse for each LeaseDeviceRequest in the 172 // BulkLeaseDevicesRequest. 173 repeated LeaseDeviceResponse lease_device_responses = 1; 174 175 // Overall error for the bulk request. It is possible for the response to 176 // error with partial success of leasing. 177 BulkLeaseDevicesResponseErrorType error_type = 2; 178 string error_string = 3; 179} 180 181enum BulkLeaseDevicesResponseErrorType { 182 BULK_LEASE_ERROR_TYPE_NONE = 0; 183 // Internal Postgres errors. 184 BULK_LEASE_ERROR_TYPE_INTERNAL_DATABASE_ERR = 1; 185 // Some Devices failed to be leased. See individual lease request errors. 186 BULK_LEASE_ERROR_TYPE_PARTIAL_LEASE_FAILURE = 2; 187} 188 189message ReleaseDeviceRequest { 190 string lease_id = 1; 191} 192 193message ReleaseDeviceResponse { 194 string lease_id = 1; 195 ReleaseDeviceResponseErrorType error_type = 2; 196 string error_string = 3; 197} 198 199enum ReleaseDeviceResponseErrorType { 200 ERROR_TYPE_NONE = 0; 201 ERROR_TYPE_DEVICE_ALREADY_RELEASED = 1; 202} 203 204message GetDeviceRequest { 205 // The name of the device to retrieve. 206 // Format: devices/{device_id}. 207 string name = 1; 208} 209 210// The response for GetDevice is Device. 211 212message ListDevicesRequest { 213 // The parent for which to list devices. Based on collections of pools. 214 // If no parent is specified, all devices will be queried. 215 // Format: pools/{pool}. 216 string parent = 1; 217 218 // The maximum number of devices to return. The service may return fewer than 219 // this value. If unspecified, at most 50 devices will be returned. 220 int32 page_size = 2; 221 222 // A page token, received from a previous `ListDevices` call. Provide this to 223 // retrieve the subsequent page. 224 // 225 // When paginating, all other parameters provided to `ListDevices` must match 226 // the call that provided the page token. 227 string page_token = 3; 228 229 // The string filter follows AIP-160 (https://google.aip.dev/160) for the 230 // filtering syntax. 231 string filter = 4; 232} 233 234message ListDevicesResponse { 235 // List of devices to be returned. 236 repeated Device devices = 1; 237 238 // A token, which can be sent as `page_token` to retrieve the next page. If 239 // this field is omitted, there are no subsequent pages. 240 string next_page_token = 2; 241} 242