src/api2/backup.rs: cleanup schema definitions

This commit is contained in:
Dietmar Maurer 2019-07-26 09:07:29 +02:00
parent ca5d0b61ca
commit bbf9e7e951
4 changed files with 47 additions and 34 deletions

View File

@ -2,6 +2,7 @@ use failure::*;
use futures::*; use futures::*;
use crate::tools; use crate::tools;
use crate::api2::types::*;
use crate::api_schema::*; use crate::api_schema::*;
use crate::api_schema::router::*; use crate::api_schema::router::*;
//use crate::server::rest::*; //use crate::server::rest::*;
@ -458,12 +459,10 @@ pub fn api_method_download_file() -> ApiAsyncMethod {
download_file, download_file,
ObjectSchema::new("Download single raw file from backup snapshot.") ObjectSchema::new("Download single raw file from backup snapshot.")
.required("store", StringSchema::new("Datastore name.")) .required("store", StringSchema::new("Datastore name."))
.required("backup-type", StringSchema::new("Backup type.") .required("backup-type", BACKUP_TYPE_SCHEMA.clone())
.format(Arc::new(ApiStringFormat::Enum(&["ct", "host"])))) .required("backup-id", BACKUP_ID_SCHEMA.clone())
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-time", BACKUP_TIME_SCHEMA.clone())
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)") .required("file-name", StringSchema::new("Raw file name.").format(FILENAME_FORMAT.clone()))
.minimum(1547797308))
.required("file-name", StringSchema::new("Raw file name."))
) )
} }
@ -525,11 +524,9 @@ pub fn api_method_upload_backup_log() -> ApiAsyncMethod {
upload_backup_log, upload_backup_log,
ObjectSchema::new("Download single raw file from backup snapshot.") ObjectSchema::new("Download single raw file from backup snapshot.")
.required("store", StringSchema::new("Datastore name.")) .required("store", StringSchema::new("Datastore name."))
.required("backup-type", StringSchema::new("Backup type.") .required("backup-type", BACKUP_TYPE_SCHEMA.clone())
.format(Arc::new(ApiStringFormat::Enum(&["ct", "host"])))) .required("backup-id", BACKUP_ID_SCHEMA.clone())
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-time", BACKUP_TIME_SCHEMA.clone())
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
.minimum(1547797308))
) )
} }
@ -563,10 +560,9 @@ pub fn router() -> Router {
list_snapshot_files, list_snapshot_files,
ObjectSchema::new("List snapshot files.") ObjectSchema::new("List snapshot files.")
.required("store", store_schema.clone()) .required("store", store_schema.clone())
.required("backup-type", StringSchema::new("Backup type.")) .required("backup-type", BACKUP_TYPE_SCHEMA.clone())
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-id", BACKUP_ID_SCHEMA.clone())
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)") .required("backup-time", BACKUP_TIME_SCHEMA.clone())
.minimum(1547797308))
) )
) )
) )
@ -585,8 +581,8 @@ pub fn router() -> Router {
list_snapshots, list_snapshots,
ObjectSchema::new("List backup groups.") ObjectSchema::new("List backup groups.")
.required("store", store_schema.clone()) .required("store", store_schema.clone())
.optional("backup-type", StringSchema::new("Backup type.")) .optional("backup-type", BACKUP_TYPE_SCHEMA.clone())
.optional("backup-id", StringSchema::new("Backup ID.")) .optional("backup-id", BACKUP_ID_SCHEMA.clone())
) )
) )
.delete( .delete(
@ -594,10 +590,9 @@ pub fn router() -> Router {
delete_snapshots, delete_snapshots,
ObjectSchema::new("Delete backup snapshot.") ObjectSchema::new("Delete backup snapshot.")
.required("store", store_schema.clone()) .required("store", store_schema.clone())
.required("backup-type", StringSchema::new("Backup type.")) .required("backup-type", BACKUP_TYPE_SCHEMA.clone())
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-id", BACKUP_ID_SCHEMA.clone())
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)") .required("backup-time", BACKUP_TIME_SCHEMA.clone())
.minimum(1547797308))
) )
) )
) )

View File

@ -1,7 +1,7 @@
use failure::*; use failure::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::sync::Arc; //use std::sync::Arc;
use futures::*; use futures::*;
use hyper::header::{HeaderValue, UPGRADE}; use hyper::header::{HeaderValue, UPGRADE};
@ -34,11 +34,9 @@ pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
upgrade_to_backup_protocol, upgrade_to_backup_protocol,
ObjectSchema::new(concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "').")) ObjectSchema::new(concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."))
.required("store", StringSchema::new("Datastore name.")) .required("store", StringSchema::new("Datastore name."))
.required("backup-type", StringSchema::new("Backup type.") .required("backup-type", BACKUP_TYPE_SCHEMA.clone())
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"])))) .required("backup-id", BACKUP_ID_SCHEMA.clone())
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-time", BACKUP_TIME_SCHEMA.clone())
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
.minimum(1547797308))
.optional("debug", BooleanSchema::new("Enable verbose debug logging.")) .optional("debug", BooleanSchema::new("Enable verbose debug logging."))
) )
} }

View File

@ -67,4 +67,19 @@ lazy_static!{
StringSchema::new("Backup archive name.") StringSchema::new("Backup archive name.")
.format(FILENAME_FORMAT.clone()).into(); .format(FILENAME_FORMAT.clone()).into();
pub static ref BACKUP_TYPE_SCHEMA: Arc<Schema> =
StringSchema::new("Backup type.")
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"])))
.into();
pub static ref BACKUP_ID_SCHEMA: Arc<Schema> =
StringSchema::new("Backup ID.")
.format(FILENAME_FORMAT.clone())
.into();
pub static ref BACKUP_TIME_SCHEMA: Arc<Schema> =
IntegerSchema::new("Backup time (Unix epoch.)")
.minimum(1547797308)
.into();
} }

View File

@ -10,6 +10,7 @@ use std::io::Write;
use proxmox_backup::tools; use proxmox_backup::tools;
use proxmox_backup::cli::*; use proxmox_backup::cli::*;
use proxmox_backup::api2::types::*;
use proxmox_backup::api_schema::*; use proxmox_backup::api_schema::*;
use proxmox_backup::api_schema::router::*; use proxmox_backup::api_schema::router::*;
use proxmox_backup::client::*; use proxmox_backup::client::*;
@ -434,9 +435,9 @@ fn create_backup(
let keyfile = param["keyfile"].as_str().map(|p| PathBuf::from(p)); let keyfile = param["keyfile"].as_str().map(|p| PathBuf::from(p));
let backup_id = param["host-id"].as_str().unwrap_or(&tools::nodename()); let backup_id = param["backup-id"].as_str().unwrap_or(&tools::nodename());
let backup_type = "host"; let backup_type = param["backup-type"].as_str().unwrap_or("host");
let include_dev = param["include-dev"].as_array(); let include_dev = param["include-dev"].as_array();
@ -1327,12 +1328,16 @@ fn main() {
"skip-lost-and-found", "skip-lost-and-found",
BooleanSchema::new("Skip lost+found directory").default(false)) BooleanSchema::new("Skip lost+found directory").default(false))
.optional( .optional(
"host-id", "backup-type",
StringSchema::new("Use specified ID for the backup group name ('host/<id>'). The default is the system hostname.")) BACKUP_TYPE_SCHEMA.clone()
)
.optional(
"backup-id",
BACKUP_ID_SCHEMA.clone()
)
.optional( .optional(
"backup-time", "backup-time",
IntegerSchema::new("Backup time (Unix epoch.)") BACKUP_TIME_SCHEMA.clone()
.minimum(1547797308)
) )
.optional( .optional(
"chunk-size", "chunk-size",