microsandbox_types/cloud/
snapshots.rs1use std::collections::BTreeMap;
4use std::path::PathBuf;
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8
9use super::CloudErrorDetails;
10use crate::snapshot::cloud_manifest::Manifest as SnapshotManifest;
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
18#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
19#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
20#[serde(rename_all = "snake_case")]
21pub enum CloudSnapshotKind {
22 Disk,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
29#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
30pub struct CloudSnapshotSpec {
31 pub sandbox_id: String,
33 pub name: String,
35 #[serde(default, skip_serializing_if = "Option::is_none")]
38 #[cfg_attr(feature = "ts", ts(type = "string | null"))]
39 #[cfg_attr(feature = "utoipa", schema(value_type = Option<String>))]
40 pub dest_dir: Option<PathBuf>,
41 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
43 pub labels: BTreeMap<String, String>,
44 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
46 pub force: bool,
47 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
49 pub record_integrity: bool,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
55#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
56#[serde(tag = "kind", rename_all = "snake_case")]
57pub enum CloudCreateSnapshotRequest {
58 Disk {
60 #[serde(flatten)]
62 snapshot: CloudSnapshotSpec,
63 },
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
69#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
70pub struct CloudSnapshotDetails {
71 pub name: String,
73 pub location: CloudSnapshotLocation,
75 #[serde(default)]
77 pub sandbox_id: Option<String>,
78 pub digest: String,
80 pub size_bytes: u64,
82 pub manifest: SnapshotManifest,
84 pub labels: BTreeMap<String, String>,
86 #[cfg_attr(feature = "ts", ts(type = "string"))]
88 pub created_at: DateTime<Utc>,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
94#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
95#[serde(tag = "kind", rename_all = "snake_case")]
96pub enum CloudSnapshot {
97 Disk {
99 #[serde(flatten)]
101 snapshot: CloudSnapshotDetails,
102 },
103}
104
105#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
108#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
109#[serde(tag = "type", rename_all = "snake_case")]
110pub enum CloudSnapshotLocation {
111 Managed {
113 id: String,
115 },
116 HostVolume {
118 path: String,
120 },
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
126#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
127#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
128pub struct CloudSnapshotOperation {
129 pub id: String,
131 pub kind: CloudSnapshotKind,
133 pub status: CloudSnapshotOperationStatus,
135 #[serde(default)]
137 pub result: Option<CloudSnapshot>,
138 #[serde(default)]
140 pub error: Option<CloudErrorDetails>,
141 #[cfg_attr(feature = "ts", ts(type = "string"))]
143 pub created_at: DateTime<Utc>,
144 #[cfg_attr(feature = "ts", ts(type = "string"))]
146 pub updated_at: DateTime<Utc>,
147 #[serde(default)]
149 #[cfg_attr(feature = "ts", ts(type = "string | null"))]
150 pub completed_at: Option<DateTime<Utc>>,
151}
152
153#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
155#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
156#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
157#[serde(rename_all = "snake_case")]
158pub enum CloudSnapshotOperationStatus {
159 Queued,
161 InProgress,
163 Succeeded,
165 Failed,
167}
168
169impl CloudCreateSnapshotRequest {
174 pub const fn kind(&self) -> CloudSnapshotKind {
176 match self {
177 Self::Disk { .. } => CloudSnapshotKind::Disk,
178 }
179 }
180
181 pub const fn snapshot_spec(&self) -> &CloudSnapshotSpec {
183 match self {
184 Self::Disk { snapshot } => snapshot,
185 }
186 }
187
188 pub const fn snapshot_spec_mut(&mut self) -> &mut CloudSnapshotSpec {
190 match self {
191 Self::Disk { snapshot } => snapshot,
192 }
193 }
194}
195
196impl CloudSnapshot {
197 pub const fn kind(&self) -> CloudSnapshotKind {
199 match self {
200 Self::Disk { .. } => CloudSnapshotKind::Disk,
201 }
202 }
203
204 pub const fn details(&self) -> &CloudSnapshotDetails {
206 match self {
207 Self::Disk { snapshot } => snapshot,
208 }
209 }
210
211 pub fn into_details(self) -> CloudSnapshotDetails {
213 match self {
214 Self::Disk { snapshot } => snapshot,
215 }
216 }
217}