Skip to main content

mountos_admin_sdk/
compat.rs

1//! Backward-compatible aliases for the pre-1.14.0 "Pair" naming. 1.14.0
2//! renamed Pair -> Copyset (types and methods) without shipping migration
3//! aliases, a semver-breaking change in a minor release. This module
4//! restores the old names as aliases/wrapper methods so code written
5//! against <1.14.0 keeps compiling; new code should use the Copyset-named
6//! exports directly. The old names are deprecated.
7//!
8//! `type X = Y` is a genuine Rust type alias (X and Y are the same type),
9//! so this is a lossless, zero-cost compatibility layer for the type-only
10//! renames below (`Pair`, `PairState`, `DrainPairStorageResponse`). It does
11//! NOT cover field-level renames on structs that were never themselves
12//! renamed (`BlockVolume::copyset_id`,
13//! `VolumeBlockPlacementConfig::copyset_ids`,
14//! `VolumeBlockPlacementResizeResult`'s `copyset_count_*`/`copysets_*`
15//! fields): Rust has no field-alias mechanism, so restoring those would
16//! need a hand-written parallel struct with its own Deserialize impl.
17//! Neither is done here; no known Rust consumer of this SDK exists in the
18//! mountOS suite. `UpdateVolumePairConfigRequest` is the one request type
19//! below that had its own field renamed, so it is a distinct struct
20//! translated at the call site rather than a plain alias.
21//!
22//! Hand-written, not touched by `make gen`.
23
24use crate::{
25    Copyset, CopysetState, DrainCopysetStorageResponse, DrainStorageCopysetRequest, Error,
26    StoragesService, UpdateVolumeCopysetConfigRequest, VolumeBlockPlacementConfig,
27    VolumeBlockPlacementResizeResult, VolumesService,
28};
29
30/// Deprecated: use [`CopysetState`] instead.
31pub type PairState = CopysetState;
32
33/// Deprecated: use [`Copyset`] instead.
34pub type Pair = Copyset;
35
36/// Deprecated: use [`DrainCopysetStorageResponse`] instead.
37pub type DrainPairStorageResponse = DrainCopysetStorageResponse;
38
39/// Deprecated: use [`UpdateVolumeCopysetConfigRequest`] instead.
40#[derive(Debug, Clone, Default)]
41#[non_exhaustive]
42pub struct UpdateVolumePairConfigRequest {
43    pub target_pair_count: i32,
44}
45
46impl UpdateVolumePairConfigRequest {
47    /// Builds the request from its required field.
48    pub fn new(target_pair_count: i32) -> Self {
49        Self { target_pair_count }
50    }
51}
52
53impl From<&UpdateVolumePairConfigRequest> for UpdateVolumeCopysetConfigRequest {
54    fn from(req: &UpdateVolumePairConfigRequest) -> Self {
55        UpdateVolumeCopysetConfigRequest {
56            target_copyset_count: req.target_pair_count,
57        }
58    }
59}
60
61impl StoragesService {
62    /// Deprecated: use [`StoragesService::list_copysets`] instead.
63    pub async fn list_pairs(
64        &self,
65        storage_id: i64,
66        state: Option<&str>,
67        include_retired: Option<bool>,
68    ) -> Result<Vec<Pair>, Error> {
69        self.list_copysets(storage_id, state, include_retired).await
70    }
71
72    /// Deprecated: use [`StoragesService::get_copyset_status`] instead.
73    pub async fn get_pair_status(&self, storage_id: i64, pair_id: &str) -> Result<Pair, Error> {
74        self.get_copyset_status(storage_id, pair_id).await
75    }
76
77    /// Deprecated: use [`StoragesService::drain_copyset`] instead.
78    pub async fn drain_pair(
79        &self,
80        storage_id: i64,
81        pair_id: &str,
82    ) -> Result<DrainPairStorageResponse, Error> {
83        self.drain_copyset(
84            storage_id,
85            pair_id,
86            &DrainStorageCopysetRequest { force: None },
87        )
88        .await
89    }
90}
91
92impl VolumesService {
93    /// Deprecated: use [`VolumesService::get_copyset_config`] instead.
94    pub async fn get_pair_config(
95        &self,
96        volume_id: i64,
97    ) -> Result<VolumeBlockPlacementConfig, Error> {
98        self.get_copyset_config(volume_id).await
99    }
100
101    /// Deprecated: use [`VolumesService::update_copyset_config`] instead.
102    pub async fn update_pair_config(
103        &self,
104        volume_id: i64,
105        req: &UpdateVolumePairConfigRequest,
106    ) -> Result<VolumeBlockPlacementResizeResult, Error> {
107        self.update_copyset_config(volume_id, &UpdateVolumeCopysetConfigRequest::from(req))
108            .await
109    }
110}