1use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13
14use super::{ContentType, Error, configuration};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum BindFloatingIpError {
21 Status400(models::GetFinances400Response),
22 Status401(models::GetFinances401Response),
23 Status403(models::GetAccountStatus403Response),
24 Status404(models::GetImage404Response),
25 Status429(models::GetFinances429Response),
26 Status500(models::GetFinances500Response),
27 UnknownValue(serde_json::Value)
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum CreateFloatingIpError {
34 Status400(models::GetFinances400Response),
35 Status401(models::GetFinances401Response),
36 Status403(models::GetAccountStatus403Response),
37 Status409(models::CreateDatabaseBackup409Response),
38 Status429(models::GetFinances429Response),
39 Status500(models::GetFinances500Response),
40 UnknownValue(serde_json::Value)
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum DeleteFloatingIpError {
47 Status400(models::GetFinances400Response),
48 Status401(models::GetFinances401Response),
49 Status403(models::GetAccountStatus403Response),
50 Status404(models::GetImage404Response),
51 Status429(models::GetFinances429Response),
52 Status500(models::GetFinances500Response),
53 UnknownValue(serde_json::Value)
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetFloatingIpError {
60 Status400(models::GetFinances400Response),
61 Status401(models::GetFinances401Response),
62 Status403(models::GetAccountStatus403Response),
63 Status404(models::GetImage404Response),
64 Status429(models::GetFinances429Response),
65 Status500(models::GetFinances500Response),
66 UnknownValue(serde_json::Value)
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetFloatingIpsError {
73 Status400(models::GetFinances400Response),
74 Status401(models::GetFinances401Response),
75 Status403(models::GetAccountStatus403Response),
76 Status404(models::GetImage404Response),
77 Status429(models::GetFinances429Response),
78 Status500(models::GetFinances500Response),
79 UnknownValue(serde_json::Value)
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum UnbindFloatingIpError {
86 Status400(models::GetFinances400Response),
87 Status401(models::GetFinances401Response),
88 Status403(models::GetAccountStatus403Response),
89 Status404(models::GetImage404Response),
90 Status429(models::GetFinances429Response),
91 Status500(models::GetFinances500Response),
92 UnknownValue(serde_json::Value)
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum UpdateFloatingIpError {
99 Status400(models::GetFinances400Response),
100 Status401(models::GetFinances401Response),
101 Status403(models::GetAccountStatus403Response),
102 Status404(models::GetImage404Response),
103 Status429(models::GetFinances429Response),
104 Status500(models::GetFinances500Response),
105 UnknownValue(serde_json::Value)
106}
107
108pub async fn bind_floating_ip(
111 configuration: &configuration::Configuration,
112 floating_ip_id: &str,
113 bind_floating_ip: models::BindFloatingIp
114) -> Result<(), Error<BindFloatingIpError>> {
115 let p_path_floating_ip_id = floating_ip_id;
117 let p_body_bind_floating_ip = bind_floating_ip;
118
119 let uri_str = format!(
120 "{}/api/v1/floating-ips/{floating_ip_id}/bind",
121 configuration.base_path,
122 floating_ip_id = crate::apis::urlencode(p_path_floating_ip_id)
123 );
124 let mut req_builder = configuration
125 .client
126 .request(reqwest::Method::POST, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref token) = configuration.bearer_access_token {
132 req_builder = req_builder.bearer_auth(token.to_owned());
133 };
134 req_builder = req_builder.json(&p_body_bind_floating_ip);
135
136 let req = req_builder.build()?;
137 let resp = configuration.client.execute(req).await?;
138
139 let status = resp.status();
140
141 if !status.is_client_error() && !status.is_server_error() {
142 Ok(())
143 } else {
144 let content = resp.text().await?;
145 let entity: Option<BindFloatingIpError> = serde_json::from_str(&content).ok();
146 Err(Error::ResponseError(ResponseContent {
147 status,
148 content,
149 entity
150 }))
151 }
152}
153
154pub async fn create_floating_ip(
157 configuration: &configuration::Configuration,
158 create_floating_ip: models::CreateFloatingIp
159) -> Result<models::CreateFloatingIp201Response, Error<CreateFloatingIpError>> {
160 let p_body_create_floating_ip = create_floating_ip;
162
163 let uri_str = format!("{}/api/v1/floating-ips", configuration.base_path);
164 let mut req_builder = configuration
165 .client
166 .request(reqwest::Method::POST, &uri_str);
167
168 if let Some(ref user_agent) = configuration.user_agent {
169 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
170 }
171 if let Some(ref token) = configuration.bearer_access_token {
172 req_builder = req_builder.bearer_auth(token.to_owned());
173 };
174 req_builder = req_builder.json(&p_body_create_floating_ip);
175
176 let req = req_builder.build()?;
177 let resp = configuration.client.execute(req).await?;
178
179 let status = resp.status();
180 let content_type = resp
181 .headers()
182 .get("content-type")
183 .and_then(|v| v.to_str().ok())
184 .unwrap_or("application/octet-stream");
185 let content_type = super::ContentType::from(content_type);
186
187 if !status.is_client_error() && !status.is_server_error() {
188 let content = resp.text().await?;
189 match content_type {
190 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191 ContentType::Text => {
192 return Err(Error::from(serde_json::Error::custom(
193 "Received `text/plain` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
194 )));
195 }
196 ContentType::Unsupported(unknown_type) => {
197 return Err(Error::from(serde_json::Error::custom(format!(
198 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
199 ))));
200 }
201 }
202 } else {
203 let content = resp.text().await?;
204 let entity: Option<CreateFloatingIpError> = serde_json::from_str(&content).ok();
205 Err(Error::ResponseError(ResponseContent {
206 status,
207 content,
208 entity
209 }))
210 }
211}
212
213pub async fn delete_floating_ip(
216 configuration: &configuration::Configuration,
217 floating_ip_id: &str
218) -> Result<(), Error<DeleteFloatingIpError>> {
219 let p_path_floating_ip_id = floating_ip_id;
221
222 let uri_str = format!(
223 "{}/api/v1/floating-ips/{floating_ip_id}",
224 configuration.base_path,
225 floating_ip_id = crate::apis::urlencode(p_path_floating_ip_id)
226 );
227 let mut req_builder = configuration
228 .client
229 .request(reqwest::Method::DELETE, &uri_str);
230
231 if let Some(ref user_agent) = configuration.user_agent {
232 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233 }
234 if let Some(ref token) = configuration.bearer_access_token {
235 req_builder = req_builder.bearer_auth(token.to_owned());
236 };
237
238 let req = req_builder.build()?;
239 let resp = configuration.client.execute(req).await?;
240
241 let status = resp.status();
242
243 if !status.is_client_error() && !status.is_server_error() {
244 Ok(())
245 } else {
246 let content = resp.text().await?;
247 let entity: Option<DeleteFloatingIpError> = serde_json::from_str(&content).ok();
248 Err(Error::ResponseError(ResponseContent {
249 status,
250 content,
251 entity
252 }))
253 }
254}
255
256pub async fn get_floating_ip(
259 configuration: &configuration::Configuration,
260 floating_ip_id: &str
261) -> Result<models::CreateFloatingIp201Response, Error<GetFloatingIpError>> {
262 let p_path_floating_ip_id = floating_ip_id;
264
265 let uri_str = format!(
266 "{}/api/v1/floating-ips/{floating_ip_id}",
267 configuration.base_path,
268 floating_ip_id = crate::apis::urlencode(p_path_floating_ip_id)
269 );
270 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
271
272 if let Some(ref user_agent) = configuration.user_agent {
273 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274 }
275 if let Some(ref token) = configuration.bearer_access_token {
276 req_builder = req_builder.bearer_auth(token.to_owned());
277 };
278
279 let req = req_builder.build()?;
280 let resp = configuration.client.execute(req).await?;
281
282 let status = resp.status();
283 let content_type = resp
284 .headers()
285 .get("content-type")
286 .and_then(|v| v.to_str().ok())
287 .unwrap_or("application/octet-stream");
288 let content_type = super::ContentType::from(content_type);
289
290 if !status.is_client_error() && !status.is_server_error() {
291 let content = resp.text().await?;
292 match content_type {
293 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294 ContentType::Text => {
295 return Err(Error::from(serde_json::Error::custom(
296 "Received `text/plain` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
297 )));
298 }
299 ContentType::Unsupported(unknown_type) => {
300 return Err(Error::from(serde_json::Error::custom(format!(
301 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
302 ))));
303 }
304 }
305 } else {
306 let content = resp.text().await?;
307 let entity: Option<GetFloatingIpError> = serde_json::from_str(&content).ok();
308 Err(Error::ResponseError(ResponseContent {
309 status,
310 content,
311 entity
312 }))
313 }
314}
315
316pub async fn get_floating_ips(
319 configuration: &configuration::Configuration
320) -> Result<models::GetFloatingIps200Response, Error<GetFloatingIpsError>> {
321 let uri_str = format!("{}/api/v1/floating-ips", configuration.base_path);
322 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
323
324 if let Some(ref user_agent) = configuration.user_agent {
325 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
326 }
327 if let Some(ref token) = configuration.bearer_access_token {
328 req_builder = req_builder.bearer_auth(token.to_owned());
329 };
330
331 let req = req_builder.build()?;
332 let resp = configuration.client.execute(req).await?;
333
334 let status = resp.status();
335 let content_type = resp
336 .headers()
337 .get("content-type")
338 .and_then(|v| v.to_str().ok())
339 .unwrap_or("application/octet-stream");
340 let content_type = super::ContentType::from(content_type);
341
342 if !status.is_client_error() && !status.is_server_error() {
343 let content = resp.text().await?;
344 match content_type {
345 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
346 ContentType::Text => {
347 return Err(Error::from(serde_json::Error::custom(
348 "Received `text/plain` content type response that cannot be converted to `models::GetFloatingIps200Response`"
349 )));
350 }
351 ContentType::Unsupported(unknown_type) => {
352 return Err(Error::from(serde_json::Error::custom(format!(
353 "Received `{unknown_type}` content type response that cannot be converted to `models::GetFloatingIps200Response`"
354 ))));
355 }
356 }
357 } else {
358 let content = resp.text().await?;
359 let entity: Option<GetFloatingIpsError> = serde_json::from_str(&content).ok();
360 Err(Error::ResponseError(ResponseContent {
361 status,
362 content,
363 entity
364 }))
365 }
366}
367
368pub async fn unbind_floating_ip(
371 configuration: &configuration::Configuration,
372 floating_ip_id: &str
373) -> Result<(), Error<UnbindFloatingIpError>> {
374 let p_path_floating_ip_id = floating_ip_id;
376
377 let uri_str = format!(
378 "{}/api/v1/floating-ips/{floating_ip_id}/unbind",
379 configuration.base_path,
380 floating_ip_id = crate::apis::urlencode(p_path_floating_ip_id)
381 );
382 let mut req_builder = configuration
383 .client
384 .request(reqwest::Method::POST, &uri_str);
385
386 if let Some(ref user_agent) = configuration.user_agent {
387 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
388 }
389 if let Some(ref token) = configuration.bearer_access_token {
390 req_builder = req_builder.bearer_auth(token.to_owned());
391 };
392
393 let req = req_builder.build()?;
394 let resp = configuration.client.execute(req).await?;
395
396 let status = resp.status();
397
398 if !status.is_client_error() && !status.is_server_error() {
399 Ok(())
400 } else {
401 let content = resp.text().await?;
402 let entity: Option<UnbindFloatingIpError> = serde_json::from_str(&content).ok();
403 Err(Error::ResponseError(ResponseContent {
404 status,
405 content,
406 entity
407 }))
408 }
409}
410
411pub async fn update_floating_ip(
414 configuration: &configuration::Configuration,
415 floating_ip_id: &str,
416 update_floating_ip: models::UpdateFloatingIp
417) -> Result<models::CreateFloatingIp201Response, Error<UpdateFloatingIpError>> {
418 let p_path_floating_ip_id = floating_ip_id;
420 let p_body_update_floating_ip = update_floating_ip;
421
422 let uri_str = format!(
423 "{}/api/v1/floating-ips/{floating_ip_id}",
424 configuration.base_path,
425 floating_ip_id = crate::apis::urlencode(p_path_floating_ip_id)
426 );
427 let mut req_builder = configuration
428 .client
429 .request(reqwest::Method::PATCH, &uri_str);
430
431 if let Some(ref user_agent) = configuration.user_agent {
432 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
433 }
434 if let Some(ref token) = configuration.bearer_access_token {
435 req_builder = req_builder.bearer_auth(token.to_owned());
436 };
437 req_builder = req_builder.json(&p_body_update_floating_ip);
438
439 let req = req_builder.build()?;
440 let resp = configuration.client.execute(req).await?;
441
442 let status = resp.status();
443 let content_type = resp
444 .headers()
445 .get("content-type")
446 .and_then(|v| v.to_str().ok())
447 .unwrap_or("application/octet-stream");
448 let content_type = super::ContentType::from(content_type);
449
450 if !status.is_client_error() && !status.is_server_error() {
451 let content = resp.text().await?;
452 match content_type {
453 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
454 ContentType::Text => {
455 return Err(Error::from(serde_json::Error::custom(
456 "Received `text/plain` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
457 )));
458 }
459 ContentType::Unsupported(unknown_type) => {
460 return Err(Error::from(serde_json::Error::custom(format!(
461 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateFloatingIp201Response`"
462 ))));
463 }
464 }
465 } else {
466 let content = resp.text().await?;
467 let entity: Option<UpdateFloatingIpError> = serde_json::from_str(&content).ok();
468 Err(Error::ResponseError(ResponseContent {
469 status,
470 content,
471 entity
472 }))
473 }
474}