use std::collections::BTreeMap;
use async_trait::async_trait;
use crate::protocol::Protocol;
use super::{host_rpc_call, Error};
pub const LOCAL_RPC_ENDPOINT_VOLUME_MANAGER: &str = "volume-manager";
pub const METHOD_VOLUME_ADD: &str = "VolumeAdd";
pub const METHOD_VOLUME_REMOVE: &str = "VolumeRemove";
pub const METHOD_VOLUME_LIST: &str = "VolumeList";
#[async_trait]
pub trait VolumeManager: Send + Sync {
async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error>;
async fn volume_remove(&self, args: VolumeRemoveRequest)
-> Result<VolumeRemoveResponse, Error>;
async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error>;
}
#[async_trait]
impl VolumeManager for Protocol {
async fn volume_add(&self, args: VolumeAddRequest) -> Result<VolumeAddResponse, Error> {
host_rpc_call(
self,
LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
METHOD_VOLUME_ADD,
args,
)
.await
}
async fn volume_remove(
&self,
args: VolumeRemoveRequest,
) -> Result<VolumeRemoveResponse, Error> {
host_rpc_call(
self,
LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
METHOD_VOLUME_REMOVE,
args,
)
.await
}
async fn volume_list(&self, args: VolumeListRequest) -> Result<VolumeListResponse, Error> {
host_rpc_call(
self,
LOCAL_RPC_ENDPOINT_VOLUME_MANAGER,
METHOD_VOLUME_LIST,
args,
)
.await
}
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeAddRequest {
pub labels: BTreeMap<String, String>,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeAddResponse {
pub id: String,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeRemoveRequest {
pub labels: BTreeMap<String, String>,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeRemoveResponse {}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeListRequest {
pub labels: BTreeMap<String, String>,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeListResponse {
#[cbor(optional)]
pub volumes: Vec<VolumeInfo>,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct VolumeInfo {
pub id: String,
pub labels: BTreeMap<String, String>,
}