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 NodesReplicationGetReplicationError {
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 NodesReplicationJobStatusError {
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 NodesReplicationReadJobLogError {
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 NodesReplicationScheduleNowError {
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 NodesReplicationStatusError {
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 nodes_replication_get_replication(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationGetReplicationResponse, Error<NodesReplicationGetReplicationError>> {
91 let p_path_id = id;
93 let p_path_node = node;
94
95 let uri_str = format!("{}/nodes/{node}/replication/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
96 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101 if let Some(ref apikey) = configuration.api_key {
102 let key = apikey.key.clone();
103 let value = match apikey.prefix {
104 Some(ref prefix) => format!("{} {}", prefix, key),
105 None => key,
106 };
107 req_builder = req_builder.header("Authorization", value);
108 };
109 if let Some(ref apikey) = configuration.api_key {
110 let key = apikey.key.clone();
111 let value = match apikey.prefix {
112 Some(ref prefix) => format!("{} {}", prefix, key),
113 None => key,
114 };
115 req_builder = req_builder.header("CSRFPreventionToken", value);
116 };
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::NodesReplicationGetReplicationResponse`"))),
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::NodesReplicationGetReplicationResponse`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<NodesReplicationGetReplicationError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn nodes_replication_job_status(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationJobStatusResponse, Error<NodesReplicationJobStatusError>> {
145 let p_path_id = id;
147 let p_path_node = node;
148
149 let uri_str = format!("{}/nodes/{node}/replication/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref apikey) = configuration.api_key {
156 let key = apikey.key.clone();
157 let value = match apikey.prefix {
158 Some(ref prefix) => format!("{} {}", prefix, key),
159 None => key,
160 };
161 req_builder = req_builder.header("Authorization", value);
162 };
163 if let Some(ref apikey) = configuration.api_key {
164 let key = apikey.key.clone();
165 let value = match apikey.prefix {
166 Some(ref prefix) => format!("{} {}", prefix, key),
167 None => key,
168 };
169 req_builder = req_builder.header("CSRFPreventionToken", value);
170 };
171
172 let req = req_builder.build()?;
173 let resp = configuration.client.execute(req).await?;
174
175 let status = resp.status();
176 let content_type = resp
177 .headers()
178 .get("content-type")
179 .and_then(|v| v.to_str().ok())
180 .unwrap_or("application/octet-stream");
181 let content_type = super::ContentType::from(content_type);
182
183 if !status.is_client_error() && !status.is_server_error() {
184 let content = resp.text().await?;
185 match content_type {
186 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
187 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesReplicationJobStatusResponse`"))),
188 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::NodesReplicationJobStatusResponse`")))),
189 }
190 } else {
191 let content = resp.text().await?;
192 let entity: Option<NodesReplicationJobStatusError> = serde_json::from_str(&content).ok();
193 Err(Error::ResponseError(ResponseContent { status, content, entity }))
194 }
195}
196
197pub async fn nodes_replication_read_job_log(configuration: &configuration::Configuration, id: &str, node: &str, limit: Option<i64>, start: Option<i64>) -> Result<models::NodesReplicationReadJobLogResponse, Error<NodesReplicationReadJobLogError>> {
199 let p_path_id = id;
201 let p_path_node = node;
202 let p_query_limit = limit;
203 let p_query_start = start;
204
205 let uri_str = format!("{}/nodes/{node}/replication/{id}/log", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
206 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
207
208 if let Some(ref param_value) = p_query_limit {
209 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
210 }
211 if let Some(ref param_value) = p_query_start {
212 req_builder = req_builder.query(&[("start", ¶m_value.to_string())]);
213 }
214 if let Some(ref user_agent) = configuration.user_agent {
215 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
216 }
217 if let Some(ref apikey) = configuration.api_key {
218 let key = apikey.key.clone();
219 let value = match apikey.prefix {
220 Some(ref prefix) => format!("{} {}", prefix, key),
221 None => key,
222 };
223 req_builder = req_builder.header("Authorization", value);
224 };
225 if let Some(ref apikey) = configuration.api_key {
226 let key = apikey.key.clone();
227 let value = match apikey.prefix {
228 Some(ref prefix) => format!("{} {}", prefix, key),
229 None => key,
230 };
231 req_builder = req_builder.header("CSRFPreventionToken", value);
232 };
233
234 let req = req_builder.build()?;
235 let resp = configuration.client.execute(req).await?;
236
237 let status = resp.status();
238 let content_type = resp
239 .headers()
240 .get("content-type")
241 .and_then(|v| v.to_str().ok())
242 .unwrap_or("application/octet-stream");
243 let content_type = super::ContentType::from(content_type);
244
245 if !status.is_client_error() && !status.is_server_error() {
246 let content = resp.text().await?;
247 match content_type {
248 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesReplicationReadJobLogResponse`"))),
250 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::NodesReplicationReadJobLogResponse`")))),
251 }
252 } else {
253 let content = resp.text().await?;
254 let entity: Option<NodesReplicationReadJobLogError> = serde_json::from_str(&content).ok();
255 Err(Error::ResponseError(ResponseContent { status, content, entity }))
256 }
257}
258
259pub async fn nodes_replication_schedule_now(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationScheduleNowResponse, Error<NodesReplicationScheduleNowError>> {
261 let p_path_id = id;
263 let p_path_node = node;
264
265 let uri_str = format!("{}/nodes/{node}/replication/{id}/schedule_now", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
266 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
267
268 if let Some(ref user_agent) = configuration.user_agent {
269 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
270 }
271 if let Some(ref apikey) = configuration.api_key {
272 let key = apikey.key.clone();
273 let value = match apikey.prefix {
274 Some(ref prefix) => format!("{} {}", prefix, key),
275 None => key,
276 };
277 req_builder = req_builder.header("Authorization", value);
278 };
279 if let Some(ref apikey) = configuration.api_key {
280 let key = apikey.key.clone();
281 let value = match apikey.prefix {
282 Some(ref prefix) => format!("{} {}", prefix, key),
283 None => key,
284 };
285 req_builder = req_builder.header("CSRFPreventionToken", value);
286 };
287
288 let req = req_builder.build()?;
289 let resp = configuration.client.execute(req).await?;
290
291 let status = resp.status();
292 let content_type = resp
293 .headers()
294 .get("content-type")
295 .and_then(|v| v.to_str().ok())
296 .unwrap_or("application/octet-stream");
297 let content_type = super::ContentType::from(content_type);
298
299 if !status.is_client_error() && !status.is_server_error() {
300 let content = resp.text().await?;
301 match content_type {
302 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
303 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesReplicationScheduleNowResponse`"))),
304 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::NodesReplicationScheduleNowResponse`")))),
305 }
306 } else {
307 let content = resp.text().await?;
308 let entity: Option<NodesReplicationScheduleNowError> = serde_json::from_str(&content).ok();
309 Err(Error::ResponseError(ResponseContent { status, content, entity }))
310 }
311}
312
313pub async fn nodes_replication_status(configuration: &configuration::Configuration, node: &str, guest: Option<i32>) -> Result<models::NodesReplicationStatusResponse, Error<NodesReplicationStatusError>> {
315 let p_path_node = node;
317 let p_query_guest = guest;
318
319 let uri_str = format!("{}/nodes/{node}/replication", configuration.base_path, node=crate::apis::urlencode(p_path_node));
320 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
321
322 if let Some(ref param_value) = p_query_guest {
323 req_builder = req_builder.query(&[("guest", ¶m_value.to_string())]);
324 }
325 if let Some(ref user_agent) = configuration.user_agent {
326 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
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("Authorization", value);
335 };
336 if let Some(ref apikey) = configuration.api_key {
337 let key = apikey.key.clone();
338 let value = match apikey.prefix {
339 Some(ref prefix) => format!("{} {}", prefix, key),
340 None => key,
341 };
342 req_builder = req_builder.header("CSRFPreventionToken", value);
343 };
344
345 let req = req_builder.build()?;
346 let resp = configuration.client.execute(req).await?;
347
348 let status = resp.status();
349 let content_type = resp
350 .headers()
351 .get("content-type")
352 .and_then(|v| v.to_str().ok())
353 .unwrap_or("application/octet-stream");
354 let content_type = super::ContentType::from(content_type);
355
356 if !status.is_client_error() && !status.is_server_error() {
357 let content = resp.text().await?;
358 match content_type {
359 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
360 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesReplicationStatusResponse`"))),
361 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::NodesReplicationStatusResponse`")))),
362 }
363 } else {
364 let content = resp.text().await?;
365 let entity: Option<NodesReplicationStatusError> = serde_json::from_str(&content).ok();
366 Err(Error::ResponseError(ResponseContent { status, content, entity }))
367 }
368}
369