use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsCreateServerError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsDeleteServerError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsExportError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsGetMetricsError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsGetServerError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsServerIndexError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClusterMetricsUpdateServerError {
Status400(models::PveError),
Status401(models::PveError),
Status403(models::PveError),
Status404(models::PveError),
Status500(models::PveError),
Status501(models::PveError),
Status503(models::PveError),
UnknownValue(serde_json::Value),
}
pub async fn cluster_metrics_create_server(configuration: &configuration::Configuration, id: &str, cluster_metrics_create_server_request: models::ClusterMetricsCreateServerRequest) -> Result<models::ClusterMetricsCreateServerResponse, Error<ClusterMetricsCreateServerError>> {
let p_path_id = id;
let p_body_cluster_metrics_create_server_request = cluster_metrics_create_server_request;
let uri_str = format!("{}/cluster/metrics/server/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_cluster_metrics_create_server_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsCreateServerResponse`"))),
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::ClusterMetricsCreateServerResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsCreateServerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_delete_server(configuration: &configuration::Configuration, id: &str) -> Result<models::ClusterMetricsDeleteServerResponse, Error<ClusterMetricsDeleteServerError>> {
let p_path_id = id;
let uri_str = format!("{}/cluster/metrics/server/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsDeleteServerResponse`"))),
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::ClusterMetricsDeleteServerResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsDeleteServerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_export(configuration: &configuration::Configuration, history: Option<models::PveBoolean>, local_only: Option<models::PveBoolean>, node_list: Option<&str>, start_time: Option<i64>) -> Result<models::ClusterMetricsExportResponse, Error<ClusterMetricsExportError>> {
let p_query_history = history;
let p_query_local_only = local_only;
let p_query_node_list = node_list;
let p_query_start_time = start_time;
let uri_str = format!("{}/cluster/metrics/export", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_history {
req_builder = req_builder.query(&[("history", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_local_only {
req_builder = req_builder.query(&[("local-only", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_node_list {
req_builder = req_builder.query(&[("node-list", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_start_time {
req_builder = req_builder.query(&[("start-time", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsExportResponse`"))),
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::ClusterMetricsExportResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsExportError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_get_metrics(configuration: &configuration::Configuration, ) -> Result<models::ClusterMetricsGetMetricsResponse, Error<ClusterMetricsGetMetricsError>> {
let uri_str = format!("{}/cluster/metrics", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsGetMetricsResponse`"))),
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::ClusterMetricsGetMetricsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsGetMetricsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_get_server(configuration: &configuration::Configuration, id: &str) -> Result<models::ClusterMetricsGetServerResponse, Error<ClusterMetricsGetServerError>> {
let p_path_id = id;
let uri_str = format!("{}/cluster/metrics/server/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsGetServerResponse`"))),
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::ClusterMetricsGetServerResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsGetServerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_server_index(configuration: &configuration::Configuration, ) -> Result<models::ClusterMetricsServerIndexResponse, Error<ClusterMetricsServerIndexError>> {
let uri_str = format!("{}/cluster/metrics/server", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsServerIndexResponse`"))),
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::ClusterMetricsServerIndexResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsServerIndexError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn cluster_metrics_update_server(configuration: &configuration::Configuration, id: &str, cluster_metrics_update_server_request: models::ClusterMetricsUpdateServerRequest) -> Result<models::ClusterMetricsUpdateServerResponse, Error<ClusterMetricsUpdateServerError>> {
let p_path_id = id;
let p_body_cluster_metrics_update_server_request = cluster_metrics_update_server_request;
let uri_str = format!("{}/cluster/metrics/server/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_cluster_metrics_update_server_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterMetricsUpdateServerResponse`"))),
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::ClusterMetricsUpdateServerResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClusterMetricsUpdateServerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}