1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ClusterReplicationCreateReplicationError {
22 Status400(models::PveError),
23 Status401(models::PveError),
24 Status403(models::PveError),
25 Status404(models::PveError),
26 Status500(models::PveError),
27 Status501(models::PveError),
28 Status503(models::PveError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ClusterReplicationDeleteReplicationError {
36 Status400(models::PveError),
37 Status401(models::PveError),
38 Status403(models::PveError),
39 Status404(models::PveError),
40 Status500(models::PveError),
41 Status501(models::PveError),
42 Status503(models::PveError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ClusterReplicationGetReplicationError {
50 Status400(models::PveError),
51 Status401(models::PveError),
52 Status403(models::PveError),
53 Status404(models::PveError),
54 Status500(models::PveError),
55 Status501(models::PveError),
56 Status503(models::PveError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ClusterReplicationReadGetReplicationError {
64 Status400(models::PveError),
65 Status401(models::PveError),
66 Status403(models::PveError),
67 Status404(models::PveError),
68 Status500(models::PveError),
69 Status501(models::PveError),
70 Status503(models::PveError),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ClusterReplicationUpdateReplicationError {
78 Status400(models::PveError),
79 Status401(models::PveError),
80 Status403(models::PveError),
81 Status404(models::PveError),
82 Status500(models::PveError),
83 Status501(models::PveError),
84 Status503(models::PveError),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn cluster_replication_create_replication(configuration: &configuration::Configuration, cluster_replication_create_replication_request: models::ClusterReplicationCreateReplicationRequest) -> Result<models::ClusterReplicationCreateReplicationResponse, Error<ClusterReplicationCreateReplicationError>> {
91 let p_body_cluster_replication_create_replication_request = cluster_replication_create_replication_request;
93
94 let uri_str = format!("{}/cluster/replication", configuration.base_path);
95 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
96
97 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100 if let Some(ref apikey) = configuration.api_key {
101 let key = apikey.key.clone();
102 let value = match apikey.prefix {
103 Some(ref prefix) => format!("{} {}", prefix, key),
104 None => key,
105 };
106 req_builder = req_builder.header("Authorization", value);
107 };
108 if let Some(ref apikey) = configuration.api_key {
109 let key = apikey.key.clone();
110 let value = match apikey.prefix {
111 Some(ref prefix) => format!("{} {}", prefix, key),
112 None => key,
113 };
114 req_builder = req_builder.header("CSRFPreventionToken", value);
115 };
116 req_builder = req_builder.json(&p_body_cluster_replication_create_replication_request);
117
118 let req = req_builder.build()?;
119 let resp = configuration.client.execute(req).await?;
120
121 let status = resp.status();
122 let content_type = resp
123 .headers()
124 .get("content-type")
125 .and_then(|v| v.to_str().ok())
126 .unwrap_or("application/octet-stream");
127 let content_type = super::ContentType::from(content_type);
128
129 if !status.is_client_error() && !status.is_server_error() {
130 let content = resp.text().await?;
131 match content_type {
132 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterReplicationCreateReplicationResponse`"))),
134 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterReplicationCreateReplicationResponse`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<ClusterReplicationCreateReplicationError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn cluster_replication_delete_replication(configuration: &configuration::Configuration, id: &str, force: Option<&str>, keep: Option<&str>) -> Result<models::ClusterReplicationDeleteReplicationResponse, Error<ClusterReplicationDeleteReplicationError>> {
145 let p_path_id = id;
147 let p_query_force = force;
148 let p_query_keep = keep;
149
150 let uri_str = format!("{}/cluster/replication/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
151 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
152
153 if let Some(ref param_value) = p_query_force {
154 req_builder = req_builder.query(&[("force", ¶m_value.to_string())]);
155 }
156 if let Some(ref param_value) = p_query_keep {
157 req_builder = req_builder.query(&[("keep", ¶m_value.to_string())]);
158 }
159 if let Some(ref user_agent) = configuration.user_agent {
160 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161 }
162 if let Some(ref apikey) = configuration.api_key {
163 let key = apikey.key.clone();
164 let value = match apikey.prefix {
165 Some(ref prefix) => format!("{} {}", prefix, key),
166 None => key,
167 };
168 req_builder = req_builder.header("Authorization", value);
169 };
170 if let Some(ref apikey) = configuration.api_key {
171 let key = apikey.key.clone();
172 let value = match apikey.prefix {
173 Some(ref prefix) => format!("{} {}", prefix, key),
174 None => key,
175 };
176 req_builder = req_builder.header("CSRFPreventionToken", value);
177 };
178
179 let req = req_builder.build()?;
180 let resp = configuration.client.execute(req).await?;
181
182 let status = resp.status();
183 let content_type = resp
184 .headers()
185 .get("content-type")
186 .and_then(|v| v.to_str().ok())
187 .unwrap_or("application/octet-stream");
188 let content_type = super::ContentType::from(content_type);
189
190 if !status.is_client_error() && !status.is_server_error() {
191 let content = resp.text().await?;
192 match content_type {
193 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterReplicationDeleteReplicationResponse`"))),
195 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterReplicationDeleteReplicationResponse`")))),
196 }
197 } else {
198 let content = resp.text().await?;
199 let entity: Option<ClusterReplicationDeleteReplicationError> = serde_json::from_str(&content).ok();
200 Err(Error::ResponseError(ResponseContent { status, content, entity }))
201 }
202}
203
204pub async fn cluster_replication_get_replication(configuration: &configuration::Configuration, ) -> Result<models::ClusterReplicationGetReplicationResponse, Error<ClusterReplicationGetReplicationError>> {
206
207 let uri_str = format!("{}/cluster/replication", configuration.base_path);
208 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
209
210 if let Some(ref user_agent) = configuration.user_agent {
211 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
212 }
213 if let Some(ref apikey) = configuration.api_key {
214 let key = apikey.key.clone();
215 let value = match apikey.prefix {
216 Some(ref prefix) => format!("{} {}", prefix, key),
217 None => key,
218 };
219 req_builder = req_builder.header("Authorization", value);
220 };
221 if let Some(ref apikey) = configuration.api_key {
222 let key = apikey.key.clone();
223 let value = match apikey.prefix {
224 Some(ref prefix) => format!("{} {}", prefix, key),
225 None => key,
226 };
227 req_builder = req_builder.header("CSRFPreventionToken", value);
228 };
229
230 let req = req_builder.build()?;
231 let resp = configuration.client.execute(req).await?;
232
233 let status = resp.status();
234 let content_type = resp
235 .headers()
236 .get("content-type")
237 .and_then(|v| v.to_str().ok())
238 .unwrap_or("application/octet-stream");
239 let content_type = super::ContentType::from(content_type);
240
241 if !status.is_client_error() && !status.is_server_error() {
242 let content = resp.text().await?;
243 match content_type {
244 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterReplicationGetReplicationResponse`"))),
246 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterReplicationGetReplicationResponse`")))),
247 }
248 } else {
249 let content = resp.text().await?;
250 let entity: Option<ClusterReplicationGetReplicationError> = serde_json::from_str(&content).ok();
251 Err(Error::ResponseError(ResponseContent { status, content, entity }))
252 }
253}
254
255pub async fn cluster_replication_read_get_replication(configuration: &configuration::Configuration, id: &str) -> Result<models::ClusterReplicationReadGetReplicationResponse, Error<ClusterReplicationReadGetReplicationError>> {
257 let p_path_id = id;
259
260 let uri_str = format!("{}/cluster/replication/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
261 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263 if let Some(ref user_agent) = configuration.user_agent {
264 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265 }
266 if let Some(ref apikey) = configuration.api_key {
267 let key = apikey.key.clone();
268 let value = match apikey.prefix {
269 Some(ref prefix) => format!("{} {}", prefix, key),
270 None => key,
271 };
272 req_builder = req_builder.header("Authorization", value);
273 };
274 if let Some(ref apikey) = configuration.api_key {
275 let key = apikey.key.clone();
276 let value = match apikey.prefix {
277 Some(ref prefix) => format!("{} {}", prefix, key),
278 None => key,
279 };
280 req_builder = req_builder.header("CSRFPreventionToken", value);
281 };
282
283 let req = req_builder.build()?;
284 let resp = configuration.client.execute(req).await?;
285
286 let status = resp.status();
287 let content_type = resp
288 .headers()
289 .get("content-type")
290 .and_then(|v| v.to_str().ok())
291 .unwrap_or("application/octet-stream");
292 let content_type = super::ContentType::from(content_type);
293
294 if !status.is_client_error() && !status.is_server_error() {
295 let content = resp.text().await?;
296 match content_type {
297 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
298 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterReplicationReadGetReplicationResponse`"))),
299 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterReplicationReadGetReplicationResponse`")))),
300 }
301 } else {
302 let content = resp.text().await?;
303 let entity: Option<ClusterReplicationReadGetReplicationError> = serde_json::from_str(&content).ok();
304 Err(Error::ResponseError(ResponseContent { status, content, entity }))
305 }
306}
307
308pub async fn cluster_replication_update_replication(configuration: &configuration::Configuration, id: &str, cluster_replication_update_replication_request: Option<models::ClusterReplicationUpdateReplicationRequest>) -> Result<models::ClusterReplicationUpdateReplicationResponse, Error<ClusterReplicationUpdateReplicationError>> {
310 let p_path_id = id;
312 let p_body_cluster_replication_update_replication_request = cluster_replication_update_replication_request;
313
314 let uri_str = format!("{}/cluster/replication/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
315 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
316
317 if let Some(ref user_agent) = configuration.user_agent {
318 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
319 }
320 if let Some(ref apikey) = configuration.api_key {
321 let key = apikey.key.clone();
322 let value = match apikey.prefix {
323 Some(ref prefix) => format!("{} {}", prefix, key),
324 None => key,
325 };
326 req_builder = req_builder.header("Authorization", value);
327 };
328 if let Some(ref apikey) = configuration.api_key {
329 let key = apikey.key.clone();
330 let value = match apikey.prefix {
331 Some(ref prefix) => format!("{} {}", prefix, key),
332 None => key,
333 };
334 req_builder = req_builder.header("CSRFPreventionToken", value);
335 };
336 req_builder = req_builder.json(&p_body_cluster_replication_update_replication_request);
337
338 let req = req_builder.build()?;
339 let resp = configuration.client.execute(req).await?;
340
341 let status = resp.status();
342 let content_type = resp
343 .headers()
344 .get("content-type")
345 .and_then(|v| v.to_str().ok())
346 .unwrap_or("application/octet-stream");
347 let content_type = super::ContentType::from(content_type);
348
349 if !status.is_client_error() && !status.is_server_error() {
350 let content = resp.text().await?;
351 match content_type {
352 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
353 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterReplicationUpdateReplicationResponse`"))),
354 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterReplicationUpdateReplicationResponse`")))),
355 }
356 } else {
357 let content = resp.text().await?;
358 let entity: Option<ClusterReplicationUpdateReplicationError> = serde_json::from_str(&content).ok();
359 Err(Error::ResponseError(ResponseContent { status, content, entity }))
360 }
361}
362