api-types: add maintenance type
+ bump proxmox-schema dep to 1.2.1 (for quoted property string) Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
parent
66b88dadba
commit
2a05c75ff1
@ -14,7 +14,7 @@ regex = "1.5.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
proxmox-lang = "1.0.0"
|
||||
proxmox-schema = { version = "1.1", features = [ "api-macro" ] }
|
||||
proxmox-schema = { version = "1.2.1", features = [ "api-macro" ] }
|
||||
proxmox-serde = "0.1"
|
||||
proxmox-time = "1.1.1"
|
||||
proxmox-uuid = { version = "1.0.0", features = [ "serde" ] }
|
||||
|
@ -6,9 +6,9 @@ use proxmox_schema::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Authid, CryptMode, Fingerprint, Userid, DATASTORE_NOTIFY_STRING_SCHEMA, GC_SCHEDULE_SCHEMA,
|
||||
PROXMOX_SAFE_ID_FORMAT, PRUNE_SCHEDULE_SCHEMA, SHA256_HEX_REGEX, SINGLE_LINE_COMMENT_SCHEMA,
|
||||
UPID,
|
||||
Authid, CryptMode, Fingerprint, MaintenanceMode, Userid, DATASTORE_NOTIFY_STRING_SCHEMA,
|
||||
GC_SCHEDULE_SCHEMA, PROXMOX_SAFE_ID_FORMAT, PRUNE_SCHEDULE_SCHEMA, SHA256_HEX_REGEX,
|
||||
SINGLE_LINE_COMMENT_SCHEMA, UPID,
|
||||
};
|
||||
|
||||
const_regex! {
|
||||
@ -262,6 +262,11 @@ pub const DATASTORE_TUNING_STRING_SCHEMA: Schema = StringSchema::new("Datastore
|
||||
optional: true,
|
||||
schema: DATASTORE_TUNING_STRING_SCHEMA,
|
||||
},
|
||||
"maintenance-mode": {
|
||||
optional: true,
|
||||
format: &ApiStringFormat::PropertyString(&MaintenanceMode::API_SCHEMA),
|
||||
type: String,
|
||||
},
|
||||
}
|
||||
)]
|
||||
#[derive(Serialize, Deserialize, Updater)]
|
||||
@ -302,6 +307,18 @@ pub struct DataStoreConfig {
|
||||
/// Datastore tuning options
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tuning: Option<String>,
|
||||
/// Maintenance mode, type is either 'offline' or 'read-only', message should be enclosed in "
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub maintenance_mode: Option<String>,
|
||||
}
|
||||
|
||||
impl DataStoreConfig {
|
||||
pub fn get_maintenance_mode(&self) -> Option<MaintenanceMode> {
|
||||
self.maintenance_mode
|
||||
.as_ref()
|
||||
.and_then(|str| MaintenanceMode::API_SCHEMA.parse_property_string(str).ok())
|
||||
.and_then(|value| MaintenanceMode::deserialize(value).ok())
|
||||
}
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -49,6 +49,9 @@ pub use jobs::*;
|
||||
mod key_derivation;
|
||||
pub use key_derivation::{Kdf, KeyInfo};
|
||||
|
||||
mod maintenance;
|
||||
pub use maintenance::*;
|
||||
|
||||
mod network;
|
||||
pub use network::*;
|
||||
|
||||
|
59
pbs-api-types/src/maintenance.rs
Normal file
59
pbs-api-types/src/maintenance.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_schema::{api, ApiStringFormat, const_regex, Schema, StringSchema};
|
||||
|
||||
const_regex!{
|
||||
pub MAINTENANCE_MESSAGE_REGEX = r"^[[:^cntrl:]]*$";
|
||||
}
|
||||
|
||||
pub const MAINTENANCE_MESSAGE_FORMAT: ApiStringFormat =
|
||||
ApiStringFormat::Pattern(&MAINTENANCE_MESSAGE_REGEX);
|
||||
|
||||
|
||||
pub const MAINTENANCE_MESSAGE_SCHEMA: Schema =
|
||||
StringSchema::new("Message describing the reason for the maintenance.")
|
||||
.format(&MAINTENANCE_MESSAGE_FORMAT)
|
||||
.max_length(64)
|
||||
.schema();
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
/// Operation requirements, used when checking for maintenance mode.
|
||||
pub enum Operation {
|
||||
Read,
|
||||
Write,
|
||||
}
|
||||
|
||||
#[api]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all="kebab-case")]
|
||||
/// Maintenance type.
|
||||
pub enum MaintenanceType {
|
||||
/// Only read operations are allowed on the datastore.
|
||||
ReadOnly,
|
||||
/// Neither read nor write operations are allowed on the datastore.
|
||||
Offline,
|
||||
}
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
type: {
|
||||
type: MaintenanceType,
|
||||
},
|
||||
message: {
|
||||
optional: true,
|
||||
schema: MAINTENANCE_MESSAGE_SCHEMA,
|
||||
}
|
||||
},
|
||||
default_key: "type",
|
||||
)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
/// Maintenance mode
|
||||
pub struct MaintenanceMode {
|
||||
/// Type of maintenance ("read-only" or "offline").
|
||||
#[serde(rename = "type")]
|
||||
ty: MaintenanceType,
|
||||
|
||||
/// Reason for maintenance.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
message: Option<String>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user