pub mod id;
#[derive(Debug, Clone)]
pub struct ReplicationClient<T> {
client: T,
path: String,
}
impl<T> ReplicationClient<T>
where
T: crate::client::Client,
{
pub fn new(client: T, parent_path: &str) -> Self {
Self {
client,
path: format!("{}{}", parent_path, "/replication"),
}
}
}
impl<T> ReplicationClient<T>
where
T: crate::client::Client,
{
#[doc = "List replication jobs."]
#[doc = ""]
#[doc = "Will only return replication jobs for which the calling user has VM.Audit permission on /vms/\\<vmid\\>."]
pub async fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
let path = self.path.to_string();
let optional_vec: Option<Vec<GetOutputItems>> = self.client.get(&path, &()).await?;
Ok(optional_vec.unwrap_or_default())
}
}
impl<T> ReplicationClient<T>
where
T: crate::client::Client,
{
#[doc = "Create a new replication job"]
#[doc = ""]
#[doc = "Requires the VM.Replicate permission on /vms/\\<vmid\\>."]
pub async fn post(&self, params: PostParams) -> Result<(), T::Error> {
let path = self.path.to_string();
self.client.post(&path, ¶ms).await
}
}
impl GetOutputItems {
pub fn new(guest: i64, id: IdStr, jobnum: i64, target: String, ty: Type) -> Self {
Self {
guest,
id,
jobnum,
target,
ty,
comment: ::std::default::Default::default(),
disable: ::std::default::Default::default(),
rate: ::std::default::Default::default(),
remove_job: ::std::default::Default::default(),
schedule: ::std::default::Default::default(),
source: ::std::default::Default::default(),
additional_properties: ::std::default::Default::default(),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
pub struct GetOutputItems {
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Description."]
#[doc = ""]
pub comment: Option<CommentStr>,
#[serde(
serialize_with = "crate::types::serialize_bool_optional",
deserialize_with = "crate::types::deserialize_bool_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Flag to disable/deactivate the entry."]
#[doc = ""]
pub disable: Option<bool>,
#[serde(
serialize_with = "crate::types::serialize_int",
deserialize_with = "crate::types::deserialize_int"
)]
#[doc = "Guest ID."]
#[doc = ""]
pub guest: i64,
#[doc = "Replication Job ID. The ID is composed of a Guest ID and a job number, separated by a hyphen, i.e. '\\\\<GUEST\\\\>-\\\\<JOBNUM\\\\>'."]
#[doc = ""]
pub id: IdStr,
#[serde(
serialize_with = "crate::types::serialize_int",
deserialize_with = "crate::types::deserialize_int"
)]
#[doc = "Unique, sequential ID assigned to each job."]
#[doc = ""]
pub jobnum: i64,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Rate limit in mbps (megabytes per second) as floating point number."]
#[doc = ""]
pub rate: Option<RateNum>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Mark the replication job for removal. The job will remove all local replication snapshots. When set to 'full', it also tries to remove replicated volumes on the target. The job then removes itself from the configuration file."]
#[doc = ""]
pub remove_job: Option<RemoveJob>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Storage replication schedule. The format is a subset of `systemd` calendar events."]
#[doc = ""]
pub schedule: Option<ScheduleStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "For internal use, to detect if the guest was stolen."]
#[doc = ""]
pub source: Option<String>,
#[doc = "Target node."]
#[doc = ""]
pub target: String,
#[serde(rename = "type")]
#[doc = "Section type."]
#[doc = ""]
pub ty: Type,
#[serde(
flatten,
default,
skip_serializing_if = "::std::collections::HashMap::is_empty"
)]
pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
}
impl PostParams {
pub fn new(id: IdStr, target: String, ty: Type) -> Self {
Self {
id,
target,
ty,
comment: ::std::default::Default::default(),
disable: ::std::default::Default::default(),
rate: ::std::default::Default::default(),
remove_job: ::std::default::Default::default(),
schedule: ::std::default::Default::default(),
source: ::std::default::Default::default(),
additional_properties: ::std::default::Default::default(),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
pub struct PostParams {
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Description."]
#[doc = ""]
pub comment: Option<CommentStr>,
#[serde(
serialize_with = "crate::types::serialize_bool_optional",
deserialize_with = "crate::types::deserialize_bool_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Flag to disable/deactivate the entry."]
#[doc = ""]
pub disable: Option<bool>,
#[doc = "Replication Job ID. The ID is composed of a Guest ID and a job number, separated by a hyphen, i.e. '\\\\<GUEST\\\\>-\\\\<JOBNUM\\\\>'."]
#[doc = ""]
pub id: IdStr,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Rate limit in mbps (megabytes per second) as floating point number."]
#[doc = ""]
pub rate: Option<RateNum>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Mark the replication job for removal. The job will remove all local replication snapshots. When set to 'full', it also tries to remove replicated volumes on the target. The job then removes itself from the configuration file."]
#[doc = ""]
pub remove_job: Option<RemoveJob>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Storage replication schedule. The format is a subset of `systemd` calendar events."]
#[doc = ""]
pub schedule: Option<ScheduleStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "For internal use, to detect if the guest was stolen."]
#[doc = ""]
pub source: Option<String>,
#[doc = "Target node."]
#[doc = ""]
pub target: String,
#[serde(rename = "type")]
#[doc = "Section type."]
#[doc = ""]
pub ty: Type,
#[serde(
flatten,
default,
skip_serializing_if = "::std::collections::HashMap::is_empty"
)]
pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
#[doc = "Mark the replication job for removal. The job will remove all local replication snapshots. When set to 'full', it also tries to remove replicated volumes on the target. The job then removes itself from the configuration file."]
#[doc = ""]
pub enum RemoveJob {
#[serde(rename = "full")]
Full,
#[serde(rename = "local")]
Local,
}
impl TryFrom<&str> for RemoveJob {
type Error = String;
fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
match value {
"full" => Ok(Self::Full),
"local" => Ok(Self::Local),
v => Err(format!("Unknown variant {v}")),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
#[doc = "Section type."]
#[doc = ""]
pub enum Type {
#[serde(rename = "local")]
Local,
}
impl TryFrom<&str> for Type {
type Error = String;
fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
match value {
"local" => Ok(Self::Local),
v => Err(format!("Unknown variant {v}")),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct RateNum(f64);
impl crate::types::bounded_number::BoundedNumber for RateNum {
const MIN: Option<f64> = Some(1f64);
const MAX: Option<f64> = None::<f64>;
const DEFAULT: Option<f64> = None::<f64>;
const TYPE_DESCRIPTION: &'static str = "an number greater than or equal to 1";
fn get(&self) -> f64 {
self.0
}
fn new(value: f64) -> Result<Self, crate::types::bounded_number::BoundedNumberError> {
Self::validate(value)?;
Ok(Self(value))
}
}
impl std::convert::TryFrom<f64> for RateNum {
type Error = crate::types::bounded_number::BoundedNumberError;
fn try_from(value: f64) -> Result<Self, Self::Error> {
crate::types::bounded_number::BoundedNumber::new(value)
}
}
impl std::convert::TryFrom<f32> for RateNum {
type Error = crate::types::bounded_number::BoundedNumberError;
fn try_from(value: f32) -> Result<Self, Self::Error> {
crate::types::bounded_number::BoundedNumber::new(value as f64)
}
}
impl std::convert::TryFrom<i32> for RateNum {
type Error = crate::types::bounded_number::BoundedNumberError;
fn try_from(value: i32) -> Result<Self, Self::Error> {
crate::types::bounded_number::BoundedNumber::new(value as f64)
}
}
impl std::convert::TryFrom<i64> for RateNum {
type Error = crate::types::bounded_number::BoundedNumberError;
fn try_from(value: i64) -> Result<Self, Self::Error> {
crate::types::bounded_number::BoundedNumber::new(value as f64)
}
}
impl ::serde::Serialize for RateNum {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_number::serialize_bounded_number(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for RateNum {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_number::deserialize_bounded_number(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct CommentStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for CommentStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(4096usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 4096";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for CommentStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for CommentStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for CommentStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct IdStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for IdStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = None::<usize>;
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = Some("[1-9][0-9]{2,8}-\\d{1,9}");
const TYPE_DESCRIPTION: &'static str =
"a string with pattern r\"[1-9][0-9]{2,8}-\\d{1,9}\" and no length constraints";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for IdStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for IdStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for IdStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct ScheduleStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for ScheduleStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(128usize);
const DEFAULT: Option<&'static str> = Some("*/15");
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 128";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for ScheduleStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for ScheduleStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for ScheduleStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
impl<T> ReplicationClient<T>
where
T: crate::client::Client,
{
pub fn id(&self, id: &str) -> id::IdClient<T> {
id::IdClient::<T>::new(self.client.clone(), &self.path, id)
}
}