clientapi-pve 2026.5.24

Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
Documentation
/*
 * Proxmox Virtual Environment API
 *
 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
 *
 * The version of the OpenAPI document: 9.x
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`nodes_replication_get_replication`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NodesReplicationGetReplicationError {
    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),
}

/// struct for typed errors of method [`nodes_replication_job_status`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NodesReplicationJobStatusError {
    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),
}

/// struct for typed errors of method [`nodes_replication_read_job_log`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NodesReplicationReadJobLogError {
    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),
}

/// struct for typed errors of method [`nodes_replication_schedule_now`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NodesReplicationScheduleNowError {
    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),
}

/// struct for typed errors of method [`nodes_replication_status`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NodesReplicationStatusError {
    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),
}


/// Directory index.
pub async fn nodes_replication_get_replication(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationGetReplicationResponse, Error<NodesReplicationGetReplicationError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_id = id;
    let p_path_node = node;

    let uri_str = format!("{}/nodes/{node}/replication/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
    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::NodesReplicationGetReplicationResponse`"))),
            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::NodesReplicationGetReplicationResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NodesReplicationGetReplicationError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get replication job status.  Permissions: Requires the VM.Audit permission on /vms/<vmid>.
pub async fn nodes_replication_job_status(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationJobStatusResponse, Error<NodesReplicationJobStatusError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_id = id;
    let p_path_node = node;

    let uri_str = format!("{}/nodes/{node}/replication/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
    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::NodesReplicationJobStatusResponse`"))),
            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::NodesReplicationJobStatusResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NodesReplicationJobStatusError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Read replication job log.  Permissions: Requires the VM.Audit permission on /vms/<vmid>, or 'Sys.Audit' on '/nodes/<node>'
pub async fn nodes_replication_read_job_log(configuration: &configuration::Configuration, id: &str, node: &str, limit: Option<i64>, start: Option<i64>) -> Result<models::NodesReplicationReadJobLogResponse, Error<NodesReplicationReadJobLogError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_id = id;
    let p_path_node = node;
    let p_query_limit = limit;
    let p_query_start = start;

    let uri_str = format!("{}/nodes/{node}/replication/{id}/log", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_start {
        req_builder = req_builder.query(&[("start", &param_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::NodesReplicationReadJobLogResponse`"))),
            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::NodesReplicationReadJobLogResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NodesReplicationReadJobLogError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Schedule replication job to start as soon as possible.  Permissions: Requires the VM.Replicate permission on /vms/<vmid>.
pub async fn nodes_replication_schedule_now(configuration: &configuration::Configuration, id: &str, node: &str) -> Result<models::NodesReplicationScheduleNowResponse, Error<NodesReplicationScheduleNowError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_id = id;
    let p_path_node = node;

    let uri_str = format!("{}/nodes/{node}/replication/{id}/schedule_now", configuration.base_path, id=crate::apis::urlencode(p_path_id), node=crate::apis::urlencode(p_path_node));
    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);
    };

    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::NodesReplicationScheduleNowResponse`"))),
            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::NodesReplicationScheduleNowResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NodesReplicationScheduleNowError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// List status of all replication jobs on this node.  Permissions: Requires the VM.Audit permission on /vms/<vmid>.
pub async fn nodes_replication_status(configuration: &configuration::Configuration, node: &str, guest: Option<i32>) -> Result<models::NodesReplicationStatusResponse, Error<NodesReplicationStatusError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_node = node;
    let p_query_guest = guest;

    let uri_str = format!("{}/nodes/{node}/replication", configuration.base_path, node=crate::apis::urlencode(p_path_node));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_guest {
        req_builder = req_builder.query(&[("guest", &param_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::NodesReplicationStatusResponse`"))),
            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::NodesReplicationStatusResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NodesReplicationStatusError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}