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#[allow(clippy::double_must_use)]
21#[async_trait]
22pub trait VolumeManager: Send + Sync {
23 async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error>;
27
28 async fn volume_remove(&self, args: VolumeRemoveRequest)
32 -> Result<VolumeRemoveResponse, Error>;
33
34 async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error>;
38}
39
40#[allow(clippy::double_must_use)]
41#[async_trait]
42impl VolumeManager for Protocol {
43 async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error> {
44 host_rpc_call(
45 self,
46 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
47 METHOD_VOLUME_ADD,
48 args,
49 )
50 .await
51 }
52
53 async fn volume_remove(
54 &self,
55 args: VolumeRemoveRequest,
56 ) -> Result<VolumeRemoveResponse, Error> {
57 host_rpc_call(
58 self,
59 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
60 METHOD_VOLUME_REMOVE,
61 args,
62 )
63 .await
64 }
65
66 async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error> {
67 host_rpc_call(
68 self,
69 LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
70 METHOD_VOLUME_LIST,
71 args,
72 )
73 .await
74 }
75}
76
77#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
81pub struct VolumeAddRequest {
82 pub labels: BTreeMap<String, String>,
84}
85
86#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
88pub struct VolumeAddResponse {
89 pub id: String,
91}
92
93#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
97pub struct VolumeRemoveRequest {
98 pub labels: BTreeMap<String, String>,
100}
101
102#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
104pub struct VolumeRemoveResponse {}
105
106#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
110pub struct VolumeListRequest {
111 pub labels: BTreeMap<String, String>,
113}
114
115#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
117pub struct VolumeListResponse {
118 #[cbor(optional)]
119 pub volumes: Vec<VolumeInfo>,
120}
121
122#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
124pub struct VolumeInfo {
125 pub id: String,
127 pub labels: BTreeMap<String, String>,
129}