clientapi_pve/apis/
nodes_config_api.rs1use 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 NodesConfigGetConfigError {
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 NodesConfigSetOptionsError {
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
47pub async fn nodes_config_get_config(configuration: &configuration::Configuration, node: &str, property: Option<&str>) -> Result<models::NodesConfigGetConfigResponse, Error<NodesConfigGetConfigError>> {
49 let p_path_node = node;
51 let p_query_property = property;
52
53 let uri_str = format!("{}/nodes/{node}/config", configuration.base_path, node=crate::apis::urlencode(p_path_node));
54 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
55
56 if let Some(ref param_value) = p_query_property {
57 req_builder = req_builder.query(&[("property", ¶m_value.to_string())]);
58 }
59 if let Some(ref user_agent) = configuration.user_agent {
60 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61 }
62 if let Some(ref apikey) = configuration.api_key {
63 let key = apikey.key.clone();
64 let value = match apikey.prefix {
65 Some(ref prefix) => format!("{} {}", prefix, key),
66 None => key,
67 };
68 req_builder = req_builder.header("Authorization", value);
69 };
70 if let Some(ref apikey) = configuration.api_key {
71 let key = apikey.key.clone();
72 let value = match apikey.prefix {
73 Some(ref prefix) => format!("{} {}", prefix, key),
74 None => key,
75 };
76 req_builder = req_builder.header("CSRFPreventionToken", value);
77 };
78
79 let req = req_builder.build()?;
80 let resp = configuration.client.execute(req).await?;
81
82 let status = resp.status();
83 let content_type = resp
84 .headers()
85 .get("content-type")
86 .and_then(|v| v.to_str().ok())
87 .unwrap_or("application/octet-stream");
88 let content_type = super::ContentType::from(content_type);
89
90 if !status.is_client_error() && !status.is_server_error() {
91 let content = resp.text().await?;
92 match content_type {
93 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesConfigGetConfigResponse`"))),
95 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::NodesConfigGetConfigResponse`")))),
96 }
97 } else {
98 let content = resp.text().await?;
99 let entity: Option<NodesConfigGetConfigError> = serde_json::from_str(&content).ok();
100 Err(Error::ResponseError(ResponseContent { status, content, entity }))
101 }
102}
103
104pub async fn nodes_config_set_options(configuration: &configuration::Configuration, node: &str, nodes_config_set_options_request: Option<models::NodesConfigSetOptionsRequest>) -> Result<models::NodesConfigSetOptionsResponse, Error<NodesConfigSetOptionsError>> {
106 let p_path_node = node;
108 let p_body_nodes_config_set_options_request = nodes_config_set_options_request;
109
110 let uri_str = format!("{}/nodes/{node}/config", configuration.base_path, node=crate::apis::urlencode(p_path_node));
111 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
112
113 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116 if let Some(ref apikey) = configuration.api_key {
117 let key = apikey.key.clone();
118 let value = match apikey.prefix {
119 Some(ref prefix) => format!("{} {}", prefix, key),
120 None => key,
121 };
122 req_builder = req_builder.header("Authorization", value);
123 };
124 if let Some(ref apikey) = configuration.api_key {
125 let key = apikey.key.clone();
126 let value = match apikey.prefix {
127 Some(ref prefix) => format!("{} {}", prefix, key),
128 None => key,
129 };
130 req_builder = req_builder.header("CSRFPreventionToken", value);
131 };
132 req_builder = req_builder.json(&p_body_nodes_config_set_options_request);
133
134 let req = req_builder.build()?;
135 let resp = configuration.client.execute(req).await?;
136
137 let status = resp.status();
138 let content_type = resp
139 .headers()
140 .get("content-type")
141 .and_then(|v| v.to_str().ok())
142 .unwrap_or("application/octet-stream");
143 let content_type = super::ContentType::from(content_type);
144
145 if !status.is_client_error() && !status.is_server_error() {
146 let content = resp.text().await?;
147 match content_type {
148 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesConfigSetOptionsResponse`"))),
150 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::NodesConfigSetOptionsResponse`")))),
151 }
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<NodesConfigSetOptionsError> = serde_json::from_str(&content).ok();
155 Err(Error::ResponseError(ResponseContent { status, content, entity }))
156 }
157}
158