oasis_core_runtime/host/
volume_manager.rs1use std::collections::BTreeMap;
2
3use async_trait::async_trait;
4
5use crate::protocol::Protocol;
6
7use super::{host_rpc_call, Error};
8
9pub const LOCAL_RPC_ENDPOINT_VOLUME_MANAGER: &str = "volume-manager";
11
12pub const METHOD_VOLUME_ADD: &str = "VolumeAdd";
14pub const METHOD_VOLUME_REMOVE: &str = "VolumeRemove";
16pub const METHOD_VOLUME_LIST: &str = "VolumeList";
18
19#[async_trait]
21pub trait VolumeManager: Send + Sync {
22 async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error>;
26
27 async fn volume_remove(&self, args: VolumeRemoveRequest)
31 -> Result<VolumeRemoveResponse, Error>;
32
33 async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error>;
37}
38
39#[async_trait]
40impl VolumeManager for Protocol {
41 async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error> {
42 host_rpc_call(
43 self,
44 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
45 METHOD_VOLUME_ADD,
46 args,
47 )
48 .await
49 }
50
51 async fn volume_remove(
52 &self,
53 args: VolumeRemoveRequest,
54 ) -> Result<VolumeRemoveResponse, Error> {
55 host_rpc_call(
56 self,
57 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
58 METHOD_VOLUME_REMOVE,
59 args,
60 )
61 .await
62 }
63
64 async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error> {
65 host_rpc_call(
66 self,
67 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
68 METHOD_VOLUME_LIST,
69 args,
70 )
71 .await
72 }
73}
74
75#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
79pub struct VolumeAddRequest {
80 pub labels: BTreeMap<String, String>,
82}
83
84#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
86pub struct VolumeAddResponse {
87 pub id: String,
89}
90
91#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
95pub struct VolumeRemoveRequest {
96 pub labels: BTreeMap<String, String>,
98}
99
100#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
102pub struct VolumeRemoveResponse {}
103
104#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
108pub struct VolumeListRequest {
109 pub labels: BTreeMap<String, String>,
111}
112
113#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
115pub struct VolumeListResponse {
116 #[cbor(optional)]
117 pub volumes: Vec<VolumeInfo>,
118}
119
120#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
122pub struct VolumeInfo {
123 pub id: String,
125 pub labels: BTreeMap<String, String>,
127}