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 NodesHardwareGetHardwareError {
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 NodesHardwareMdevscanError {
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 NodesHardwarePciIndexError {
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 NodesHardwarePciScanError {
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 NodesHardwareUsbscanError {
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_hardware_get_hardware(configuration: &configuration::Configuration, node: &str) -> Result<models::NodesHardwareGetHardwareResponse, Error<NodesHardwareGetHardwareError>> {
91 let p_path_node = node;
93
94 let uri_str = format!("{}/nodes/{node}/hardware", configuration.base_path, node=crate::apis::urlencode(p_path_node));
95 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
96
97 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100 if let Some(ref apikey) = configuration.api_key {
101 let key = apikey.key.clone();
102 let value = match apikey.prefix {
103 Some(ref prefix) => format!("{} {}", prefix, key),
104 None => key,
105 };
106 req_builder = req_builder.header("Authorization", value);
107 };
108 if let Some(ref apikey) = configuration.api_key {
109 let key = apikey.key.clone();
110 let value = match apikey.prefix {
111 Some(ref prefix) => format!("{} {}", prefix, key),
112 None => key,
113 };
114 req_builder = req_builder.header("CSRFPreventionToken", value);
115 };
116
117 let req = req_builder.build()?;
118 let resp = configuration.client.execute(req).await?;
119
120 let status = resp.status();
121 let content_type = resp
122 .headers()
123 .get("content-type")
124 .and_then(|v| v.to_str().ok())
125 .unwrap_or("application/octet-stream");
126 let content_type = super::ContentType::from(content_type);
127
128 if !status.is_client_error() && !status.is_server_error() {
129 let content = resp.text().await?;
130 match content_type {
131 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesHardwareGetHardwareResponse`"))),
133 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::NodesHardwareGetHardwareResponse`")))),
134 }
135 } else {
136 let content = resp.text().await?;
137 let entity: Option<NodesHardwareGetHardwareError> = serde_json::from_str(&content).ok();
138 Err(Error::ResponseError(ResponseContent { status, content, entity }))
139 }
140}
141
142pub async fn nodes_hardware_mdevscan(configuration: &configuration::Configuration, node: &str, pci_id_or_mapping: &str) -> Result<models::NodesHardwareMdevscanResponse, Error<NodesHardwareMdevscanError>> {
144 let p_path_node = node;
146 let p_path_pci_id_or_mapping = pci_id_or_mapping;
147
148 let uri_str = format!("{}/nodes/{node}/hardware/pci/{pci_id_or_mapping}/mdev", configuration.base_path, node=crate::apis::urlencode(p_path_node), pci_id_or_mapping=crate::apis::urlencode(p_path_pci_id_or_mapping));
149 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
150
151 if let Some(ref user_agent) = configuration.user_agent {
152 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153 }
154 if let Some(ref apikey) = configuration.api_key {
155 let key = apikey.key.clone();
156 let value = match apikey.prefix {
157 Some(ref prefix) => format!("{} {}", prefix, key),
158 None => key,
159 };
160 req_builder = req_builder.header("Authorization", value);
161 };
162 if let Some(ref apikey) = configuration.api_key {
163 let key = apikey.key.clone();
164 let value = match apikey.prefix {
165 Some(ref prefix) => format!("{} {}", prefix, key),
166 None => key,
167 };
168 req_builder = req_builder.header("CSRFPreventionToken", value);
169 };
170
171 let req = req_builder.build()?;
172 let resp = configuration.client.execute(req).await?;
173
174 let status = resp.status();
175 let content_type = resp
176 .headers()
177 .get("content-type")
178 .and_then(|v| v.to_str().ok())
179 .unwrap_or("application/octet-stream");
180 let content_type = super::ContentType::from(content_type);
181
182 if !status.is_client_error() && !status.is_server_error() {
183 let content = resp.text().await?;
184 match content_type {
185 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesHardwareMdevscanResponse`"))),
187 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::NodesHardwareMdevscanResponse`")))),
188 }
189 } else {
190 let content = resp.text().await?;
191 let entity: Option<NodesHardwareMdevscanError> = serde_json::from_str(&content).ok();
192 Err(Error::ResponseError(ResponseContent { status, content, entity }))
193 }
194}
195
196pub async fn nodes_hardware_pci_index(configuration: &configuration::Configuration, node: &str, pci_id_or_mapping: &str) -> Result<models::NodesHardwarePciIndexResponse, Error<NodesHardwarePciIndexError>> {
198 let p_path_node = node;
200 let p_path_pci_id_or_mapping = pci_id_or_mapping;
201
202 let uri_str = format!("{}/nodes/{node}/hardware/pci/{pci_id_or_mapping}", configuration.base_path, node=crate::apis::urlencode(p_path_node), pci_id_or_mapping=crate::apis::urlencode(p_path_pci_id_or_mapping));
203 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
204
205 if let Some(ref user_agent) = configuration.user_agent {
206 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207 }
208 if let Some(ref apikey) = configuration.api_key {
209 let key = apikey.key.clone();
210 let value = match apikey.prefix {
211 Some(ref prefix) => format!("{} {}", prefix, key),
212 None => key,
213 };
214 req_builder = req_builder.header("Authorization", value);
215 };
216 if let Some(ref apikey) = configuration.api_key {
217 let key = apikey.key.clone();
218 let value = match apikey.prefix {
219 Some(ref prefix) => format!("{} {}", prefix, key),
220 None => key,
221 };
222 req_builder = req_builder.header("CSRFPreventionToken", value);
223 };
224
225 let req = req_builder.build()?;
226 let resp = configuration.client.execute(req).await?;
227
228 let status = resp.status();
229 let content_type = resp
230 .headers()
231 .get("content-type")
232 .and_then(|v| v.to_str().ok())
233 .unwrap_or("application/octet-stream");
234 let content_type = super::ContentType::from(content_type);
235
236 if !status.is_client_error() && !status.is_server_error() {
237 let content = resp.text().await?;
238 match content_type {
239 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
240 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesHardwarePciIndexResponse`"))),
241 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::NodesHardwarePciIndexResponse`")))),
242 }
243 } else {
244 let content = resp.text().await?;
245 let entity: Option<NodesHardwarePciIndexError> = serde_json::from_str(&content).ok();
246 Err(Error::ResponseError(ResponseContent { status, content, entity }))
247 }
248}
249
250pub async fn nodes_hardware_pci_scan(configuration: &configuration::Configuration, node: &str, pci_class_blacklist: Option<&str>, verbose: Option<&str>) -> Result<models::NodesHardwarePciScanResponse, Error<NodesHardwarePciScanError>> {
252 let p_path_node = node;
254 let p_query_pci_class_blacklist = pci_class_blacklist;
255 let p_query_verbose = verbose;
256
257 let uri_str = format!("{}/nodes/{node}/hardware/pci", configuration.base_path, node=crate::apis::urlencode(p_path_node));
258 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
259
260 if let Some(ref param_value) = p_query_pci_class_blacklist {
261 req_builder = req_builder.query(&[("pci-class-blacklist", ¶m_value.to_string())]);
262 }
263 if let Some(ref param_value) = p_query_verbose {
264 req_builder = req_builder.query(&[("verbose", ¶m_value.to_string())]);
265 }
266 if let Some(ref user_agent) = configuration.user_agent {
267 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
268 }
269 if let Some(ref apikey) = configuration.api_key {
270 let key = apikey.key.clone();
271 let value = match apikey.prefix {
272 Some(ref prefix) => format!("{} {}", prefix, key),
273 None => key,
274 };
275 req_builder = req_builder.header("Authorization", value);
276 };
277 if let Some(ref apikey) = configuration.api_key {
278 let key = apikey.key.clone();
279 let value = match apikey.prefix {
280 Some(ref prefix) => format!("{} {}", prefix, key),
281 None => key,
282 };
283 req_builder = req_builder.header("CSRFPreventionToken", value);
284 };
285
286 let req = req_builder.build()?;
287 let resp = configuration.client.execute(req).await?;
288
289 let status = resp.status();
290 let content_type = resp
291 .headers()
292 .get("content-type")
293 .and_then(|v| v.to_str().ok())
294 .unwrap_or("application/octet-stream");
295 let content_type = super::ContentType::from(content_type);
296
297 if !status.is_client_error() && !status.is_server_error() {
298 let content = resp.text().await?;
299 match content_type {
300 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
301 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesHardwarePciScanResponse`"))),
302 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::NodesHardwarePciScanResponse`")))),
303 }
304 } else {
305 let content = resp.text().await?;
306 let entity: Option<NodesHardwarePciScanError> = serde_json::from_str(&content).ok();
307 Err(Error::ResponseError(ResponseContent { status, content, entity }))
308 }
309}
310
311pub async fn nodes_hardware_usbscan(configuration: &configuration::Configuration, node: &str) -> Result<models::NodesHardwareUsbscanResponse, Error<NodesHardwareUsbscanError>> {
313 let p_path_node = node;
315
316 let uri_str = format!("{}/nodes/{node}/hardware/usb", configuration.base_path, node=crate::apis::urlencode(p_path_node));
317 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
318
319 if let Some(ref user_agent) = configuration.user_agent {
320 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
321 }
322 if let Some(ref apikey) = configuration.api_key {
323 let key = apikey.key.clone();
324 let value = match apikey.prefix {
325 Some(ref prefix) => format!("{} {}", prefix, key),
326 None => key,
327 };
328 req_builder = req_builder.header("Authorization", value);
329 };
330 if let Some(ref apikey) = configuration.api_key {
331 let key = apikey.key.clone();
332 let value = match apikey.prefix {
333 Some(ref prefix) => format!("{} {}", prefix, key),
334 None => key,
335 };
336 req_builder = req_builder.header("CSRFPreventionToken", value);
337 };
338
339 let req = req_builder.build()?;
340 let resp = configuration.client.execute(req).await?;
341
342 let status = resp.status();
343 let content_type = resp
344 .headers()
345 .get("content-type")
346 .and_then(|v| v.to_str().ok())
347 .unwrap_or("application/octet-stream");
348 let content_type = super::ContentType::from(content_type);
349
350 if !status.is_client_error() && !status.is_server_error() {
351 let content = resp.text().await?;
352 match content_type {
353 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
354 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesHardwareUsbscanResponse`"))),
355 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::NodesHardwareUsbscanResponse`")))),
356 }
357 } else {
358 let content = resp.text().await?;
359 let entity: Option<NodesHardwareUsbscanError> = serde_json::from_str(&content).ok();
360 Err(Error::ResponseError(ResponseContent { status, content, entity }))
361 }
362}
363