Skip to main content

incus_client/apis/
operations_api.rs

1/*
2 * Incus external REST API
3 *
4 * This is the REST API used by all Incus clients. Internal endpoints aren't included in this documentation.  The Incus API is available over both a local unix+http and remote https API. Authentication for local users relies on group membership and access to the unix socket. For remote users, the default authentication method is TLS client certificates.
5 *
6 * The version of the OpenAPI document: 1.0
7 * Contact: lxc-devel@lists.linuxcontainers.org
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`operation_wait_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum OperationWaitGetError {
22    Status403(models::InstancesGet403Response),
23    Status500(models::InstancesGet500Response),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`operations_get`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum OperationsGetError {
31    Status403(models::InstancesGet403Response),
32    Status500(models::InstancesGet500Response),
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Waits for the operation to reach a final state (or timeout) and retrieve its final state.
38pub async fn operation_wait_get(configuration: &configuration::Configuration, id: &str, timeout: Option<i32>) -> Result<models::OperationWaitGet200Response, Error<OperationWaitGetError>> {
39    // add a prefix to parameters to efficiently prevent name collisions
40    let p_path_id = id;
41    let p_query_timeout = timeout;
42
43    let uri_str = format!("{}/1.0/operations/{id}/wait", configuration.base_path, id=crate::apis::urlencode(p_path_id));
44    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46    if let Some(ref param_value) = p_query_timeout {
47        req_builder = req_builder.query(&[("timeout", &param_value.to_string())]);
48    }
49    if let Some(ref user_agent) = configuration.user_agent {
50        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
51    }
52
53    let req = req_builder.build()?;
54    let resp = configuration.client.execute(req).await?;
55
56    let status = resp.status();
57    let content_type = resp
58        .headers()
59        .get("content-type")
60        .and_then(|v| v.to_str().ok())
61        .unwrap_or("application/octet-stream");
62    let content_type = super::ContentType::from(content_type);
63
64    if !status.is_client_error() && !status.is_server_error() {
65        let content = resp.text().await?;
66        match content_type {
67            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
68            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OperationWaitGet200Response`"))),
69            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::OperationWaitGet200Response`")))),
70        }
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<OperationWaitGetError> = serde_json::from_str(&content).ok();
74        Err(Error::ResponseError(ResponseContent { status, content, entity }))
75    }
76}
77
78/// Returns a JSON object of operation type to operation list (URLs).
79pub async fn operations_get(configuration: &configuration::Configuration, project: Option<&str>, all_projects: Option<bool>) -> Result<models::OperationsGet200Response, Error<OperationsGetError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_query_project = project;
82    let p_query_all_projects = all_projects;
83
84    let uri_str = format!("{}/1.0/operations", configuration.base_path);
85    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
86
87    if let Some(ref param_value) = p_query_project {
88        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
89    }
90    if let Some(ref param_value) = p_query_all_projects {
91        req_builder = req_builder.query(&[("all-projects", &param_value.to_string())]);
92    }
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96
97    let req = req_builder.build()?;
98    let resp = configuration.client.execute(req).await?;
99
100    let status = resp.status();
101    let content_type = resp
102        .headers()
103        .get("content-type")
104        .and_then(|v| v.to_str().ok())
105        .unwrap_or("application/octet-stream");
106    let content_type = super::ContentType::from(content_type);
107
108    if !status.is_client_error() && !status.is_server_error() {
109        let content = resp.text().await?;
110        match content_type {
111            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
112            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OperationsGet200Response`"))),
113            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::OperationsGet200Response`")))),
114        }
115    } else {
116        let content = resp.text().await?;
117        let entity: Option<OperationsGetError> = serde_json::from_str(&content).ok();
118        Err(Error::ResponseError(ResponseContent { status, content, entity }))
119    }
120}
121