Skip to main content

clientapi_pve/apis/
nodes_time_api.rs

1/*
2 * Proxmox Virtual Environment API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
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 [`nodes_time_set_timezone`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum NodesTimeSetTimezoneError {
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/// struct for typed errors of method [`nodes_time_time`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum NodesTimeTimeError {
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
47/// Set time zone.
48pub async fn nodes_time_set_timezone(configuration: &configuration::Configuration, node: &str, nodes_time_set_timezone_request: models::NodesTimeSetTimezoneRequest) -> Result<models::NodesTimeSetTimezoneResponse, Error<NodesTimeSetTimezoneError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_node = node;
51    let p_body_nodes_time_set_timezone_request = nodes_time_set_timezone_request;
52
53    let uri_str = format!("{}/nodes/{node}/time", configuration.base_path, node=crate::apis::urlencode(p_path_node));
54    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
55
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref apikey) = configuration.api_key {
60        let key = apikey.key.clone();
61        let value = match apikey.prefix {
62            Some(ref prefix) => format!("{} {}", prefix, key),
63            None => key,
64        };
65        req_builder = req_builder.header("Authorization", value);
66    };
67    if let Some(ref apikey) = configuration.api_key {
68        let key = apikey.key.clone();
69        let value = match apikey.prefix {
70            Some(ref prefix) => format!("{} {}", prefix, key),
71            None => key,
72        };
73        req_builder = req_builder.header("CSRFPreventionToken", value);
74    };
75    req_builder = req_builder.json(&p_body_nodes_time_set_timezone_request);
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81    let content_type = resp
82        .headers()
83        .get("content-type")
84        .and_then(|v| v.to_str().ok())
85        .unwrap_or("application/octet-stream");
86    let content_type = super::ContentType::from(content_type);
87
88    if !status.is_client_error() && !status.is_server_error() {
89        let content = resp.text().await?;
90        match content_type {
91            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
92            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesTimeSetTimezoneResponse`"))),
93            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::NodesTimeSetTimezoneResponse`")))),
94        }
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<NodesTimeSetTimezoneError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent { status, content, entity }))
99    }
100}
101
102/// Read server time and time zone settings.
103pub async fn nodes_time_time(configuration: &configuration::Configuration, node: &str) -> Result<models::NodesTimeTimeResponse, Error<NodesTimeTimeError>> {
104    // add a prefix to parameters to efficiently prevent name collisions
105    let p_path_node = node;
106
107    let uri_str = format!("{}/nodes/{node}/time", configuration.base_path, node=crate::apis::urlencode(p_path_node));
108    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref apikey) = configuration.api_key {
114        let key = apikey.key.clone();
115        let value = match apikey.prefix {
116            Some(ref prefix) => format!("{} {}", prefix, key),
117            None => key,
118        };
119        req_builder = req_builder.header("Authorization", value);
120    };
121    if let Some(ref apikey) = configuration.api_key {
122        let key = apikey.key.clone();
123        let value = match apikey.prefix {
124            Some(ref prefix) => format!("{} {}", prefix, key),
125            None => key,
126        };
127        req_builder = req_builder.header("CSRFPreventionToken", value);
128    };
129
130    let req = req_builder.build()?;
131    let resp = configuration.client.execute(req).await?;
132
133    let status = resp.status();
134    let content_type = resp
135        .headers()
136        .get("content-type")
137        .and_then(|v| v.to_str().ok())
138        .unwrap_or("application/octet-stream");
139    let content_type = super::ContentType::from(content_type);
140
141    if !status.is_client_error() && !status.is_server_error() {
142        let content = resp.text().await?;
143        match content_type {
144            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
145            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesTimeTimeResponse`"))),
146            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::NodesTimeTimeResponse`")))),
147        }
148    } else {
149        let content = resp.text().await?;
150        let entity: Option<NodesTimeTimeError> = serde_json::from_str(&content).ok();
151        Err(Error::ResponseError(ResponseContent { status, content, entity }))
152    }
153}
154