syntax = "proto3";

package yandex.cloud.compute.v1;

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "yandex/cloud/api/operation.proto";
import "yandex/cloud/compute/v1/disk.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/validation.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/compute/v1;compute";
option java_package = "yandex.cloud.api.compute.v1";

// A set of methods for managing Disk resources.
service DiskService {
  // Returns the specified Disk resource.
  //
  // To get the list of available Disk resources, make a [List] request.
  rpc Get (GetDiskRequest) returns (Disk) {
    option (google.api.http) = { get: "/compute/v1/disks/{disk_id}" };
  }

  // Retrieves the list of Disk resources in the specified folder.
  rpc List (ListDisksRequest) returns (ListDisksResponse) {
    option (google.api.http) = { get: "/compute/v1/disks" };
  }

  // Creates a disk in the specified folder.
  //
  // You can create an empty disk or restore it from a snapshot or an image.
  // Method starts an asynchronous operation that can be cancelled while it is in progress.
  rpc Create (CreateDiskRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/compute/v1/disks" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "CreateDiskMetadata"
      response: "Disk"
    };
  }

  // Updates the specified disk.
  rpc Update (UpdateDiskRequest) returns (operation.Operation) {
    option (google.api.http) = { patch: "/compute/v1/disks/{disk_id}" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "UpdateDiskMetadata"
      response: "Disk"
    };
  }

  // Deletes the specified disk.
  //
  // Deleting a disk removes its data permanently and is irreversible. However, deleting a disk does not delete
  // any snapshots or images previously made from the disk. You must delete snapshots and images separately.
  //
  // It is not possible to delete a disk that is attached to an instance.
  rpc Delete (DeleteDiskRequest) returns (operation.Operation) {
    option (google.api.http) = { delete: "/compute/v1/disks/{disk_id}" };
    option (yandex.cloud.api.operation) = {
      metadata: "DeleteDiskMetadata"
      response: "google.protobuf.Empty"
    };
  }

  // Lists operations for the specified disk.
  rpc ListOperations (ListDiskOperationsRequest) returns (ListDiskOperationsResponse) {
    option (google.api.http) = { get: "/compute/v1/disks/{disk_id}/operations" };
  }
}

message GetDiskRequest {
  // ID of the Disk resource to return.
  // To get the disk ID use a [DiskService.List] request.
  string disk_id = 1 [(required) = true, (length) = "<=50"];
}

message ListDisksRequest {
  // ID of the folder to list disks in.
  // To get the folder ID use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true, (length) = "<=50"];

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size],
  // the service returns a [ListDisksResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  int64 page_size = 2 [(value) = "<=1000"];

  // Page token. To get the next page of results, set [page_token] to the
  // [ListDisksResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];

  // A filter expression that filters resources listed in the response.
  // The expression must specify:
  // 1. The field name. Currently you can use filtering only on the [Disk.name] field.
  // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
  // 3. The value. Must be 3-63 characters long and match the regular expression `^[a-z]([-a-z0-9]{,61}[a-z0-9])?$`.
  string filter = 4 [(length) = "<=1000"];
}

message ListDisksResponse {
  // List of Disk resources.
  repeated Disk disks = 1;

  // This token allows you to get the next page of results for list requests. If the number of results
  // is larger than [ListDisksRequest.page_size], use
  // the [next_page_token] as the value
  // for the [ListDisksRequest.page_token] query parameter
  // in the next list request. Each subsequent list request will have its own
  // [next_page_token] to continue paging through the results.
  string next_page_token = 2;
}

message CreateDiskRequest {
  // ID of the folder to create a disk in.
  // To get the folder ID use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true, (length) = "<=50"];

  // Name of the disk.
  string name = 2 [(pattern) = "|[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

  // Description of the disk.
  string description = 3 [(length) = "<=256"];

  // Resource labels as `key:value` pairs.
  map<string, string> labels = 4 [(yandex.cloud.size) = "<=64", (length) = "<=63", (pattern) = "[-_./\\@0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_./\\@0-9a-z]*"];

  // ID of the disk type.
  // To get a list of available disk types use the [yandex.cloud.compute.v1.DiskTypeService.List] request.
  string type_id = 5 [(length) = "<=50"];

  // ID of the availability zone where the disk resides.
  // To get a list of available zones use the [yandex.cloud.compute.v1.ZoneService.List] request.
  string zone_id = 6 [(required) = true, (length) = "<=50"];

  // Size of the disk, specified in bytes.
  // If the disk was created from a image, this value should be more than the
  // [yandex.cloud.compute.v1.Image.min_disk_size] value.
  int64 size = 7 [(required) = true, (value) = "4194304-28587302322176"];

  oneof source {
    // ID of the image to create the disk from.
    string image_id = 8 [(length) = "<=50"];

    // ID of the snapshot to restore the disk from.
    string snapshot_id = 9 [(length) = "<=50"];
  }

  // Block size used for disk, specified in bytes. The default is 4096.
  int64 block_size = 10;

  // Placement policy configuration.
  DiskPlacementPolicy disk_placement_policy = 11;
}

message CreateDiskMetadata {
  // ID of the disk that is being created.
  string disk_id = 1;
}

message UpdateDiskRequest {
  // ID of the Disk resource to update.
  // To get the disk ID use a [DiskService.List] request.
  string disk_id = 1 [(required) = true, (length) = "<=50"];

  // Field mask that specifies which fields of the Disk resource are going to be updated.
  google.protobuf.FieldMask update_mask = 2;

  // Name of the disk.
  string name = 3 [(pattern) = "|[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

  // Description of the disk.
  string description = 4 [(length) = "<=256"];

  // Resource labels as `key:value` pairs.
  //
  // Existing set of `labels` is completely replaced by the provided set.
  map<string, string> labels = 5 [(yandex.cloud.size) = "<=64", (length) = "<=63", (pattern) = "[-_./\\@0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_./\\@0-9a-z]*"];

  // Size of the disk, specified in bytes.
  int64 size = 6 [(value) = "4194304-4398046511104"];

  // Placement policy configuration.
  DiskPlacementPolicy disk_placement_policy = 7;
}

message UpdateDiskMetadata {
  // ID of the Disk resource that is being updated.
  string disk_id = 1;
}

message DeleteDiskRequest {
  // ID of the disk to delete.
  // To get the disk ID use a [DiskService.List] request.
  string disk_id = 1 [(required) = true, (length) = "<=50"];
}

message DeleteDiskMetadata {
  // ID of the disk that is being deleted.
  string disk_id = 1;
}

message ListDiskOperationsRequest {
  // ID of the Disk resource to list operations for.
  string disk_id = 1 [(required) = true, (length) = "<=50"];

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size], the service returns a [ListDiskOperationsResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  int64 page_size = 2 [(value) = "<=1000"];

  // Page token. To get the next page of results, set [page_token] to the
  // [ListDiskOperationsResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];
}

message ListDiskOperationsResponse {
  // List of operations for the specified disk.
  repeated operation.Operation operations = 1;

  // This token allows you to get the next page of results for list requests. If the number of results
  // is larger than [ListDiskOperationsRequest.page_size], use the [next_page_token] as the value
  // for the [ListDiskOperationsRequest.page_token] query parameter in the next list request.
  // Each subsequent list request will have its own [next_page_token] to continue paging through the results.
  string next_page_token = 2;
}
