src/api2/types.rs: factor out DATASTORE_SCHEMA

This commit is contained in:
Dietmar Maurer 2019-12-11 13:45:23 +01:00
parent 567d3e00fb
commit 66c49c21c3
6 changed files with 20 additions and 17 deletions

View File

@ -200,7 +200,7 @@ const API_METHOD_STATUS: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Get datastore status.", "Get datastore status.",
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
]), ]),
) )
); );
@ -299,7 +299,7 @@ const API_METHOD_PRUNE: ApiMethod = ApiMethod::new(
.schema() .schema()
), ),
],[ ],[
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
]) ])
) )
); );
@ -388,7 +388,7 @@ pub const API_METHOD_START_GARBAGE_COLLECTION: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Start garbage collection.", "Start garbage collection.",
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
]) ])
) )
); );
@ -423,7 +423,7 @@ pub const API_METHOD_GARBAGE_COLLECTION_STATUS: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Garbage collection status.", "Garbage collection status.",
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
]) ])
) )
); );
@ -463,7 +463,7 @@ pub const API_METHOD_DOWNLOAD_FILE: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Download single raw file from backup snapshot.", "Download single raw file from backup snapshot.",
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -526,7 +526,7 @@ pub const API_METHOD_UPLOAD_BACKUP_LOG: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Download single raw file from backup snapshot.", "Download single raw file from backup snapshot.",
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -585,8 +585,6 @@ fn upload_backup_log(
}.boxed() }.boxed()
} }
const STORE_SCHEMA: Schema = StringSchema::new("Datastore name.").schema();
#[sortable] #[sortable]
const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
( (
@ -603,7 +601,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&ObjectSchema::new( &ObjectSchema::new(
"List snapshot files.", "List snapshot files.",
&sorted!([ &sorted!([
("store", false, &STORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -626,7 +624,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&ApiHandler::Sync(&list_groups), &ApiHandler::Sync(&list_groups),
&ObjectSchema::new( &ObjectSchema::new(
"List backup groups.", "List backup groups.",
&sorted!([ ("store", false, &STORE_SCHEMA) ]), &sorted!([ ("store", false, &DATASTORE_SCHEMA) ]),
) )
) )
) )
@ -645,7 +643,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&ObjectSchema::new( &ObjectSchema::new(
"List backup groups.", "List backup groups.",
&sorted!([ &sorted!([
("store", false, &STORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-type", true, &BACKUP_TYPE_SCHEMA), ("backup-type", true, &BACKUP_TYPE_SCHEMA),
("backup-id", true, &BACKUP_ID_SCHEMA), ("backup-id", true, &BACKUP_ID_SCHEMA),
]), ]),
@ -658,7 +656,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&ObjectSchema::new( &ObjectSchema::new(
"Delete backup snapshot.", "Delete backup snapshot.",
&sorted!([ &sorted!([
("store", false, &STORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),

View File

@ -32,7 +32,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."), concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."),
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),

View File

@ -6,6 +6,7 @@ use serde_json::{json, Value};
use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment}; use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment};
use proxmox::api::schema::*; use proxmox::api::schema::*;
use crate::api2::types::*;
use crate::backup::*; use crate::backup::*;
use crate::config::datastore; use crate::config::datastore;
@ -30,7 +31,7 @@ pub const POST: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Create new datastore.", "Create new datastore.",
&[ &[
("name", false, &StringSchema::new("Datastore name.").schema()), ("name", false, &DATASTORE_SCHEMA),
("path", false, &StringSchema::new("Directory path (must exist).").schema()), ("path", false, &StringSchema::new("Directory path (must exist).").schema()),
], ],
) )
@ -71,7 +72,7 @@ pub const DELETE: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
"Remove a datastore configuration.", "Remove a datastore configuration.",
&[ &[
("name", false, &StringSchema::new("Datastore name.").schema()), ("name", false, &DATASTORE_SCHEMA),
], ],
) )
); );

View File

@ -280,7 +280,7 @@ pub const ROUTER: Router = Router::new()
.default(50) .default(50)
.schema() .schema()
), ),
("store", true, &StringSchema::new("Only lists tasks for datastore name.").schema()), ("store", true, &DATASTORE_SCHEMA),
("running", true, &BooleanSchema::new("Only list running tasks.").schema()), ("running", true, &BooleanSchema::new("Only list running tasks.").schema()),
("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()), ("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()),
("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()), ("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()),

View File

@ -28,7 +28,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
&ObjectSchema::new( &ObjectSchema::new(
concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_READER_PROTOCOL_ID_V1!(), "')."), concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_READER_PROTOCOL_ID_V1!(), "')."),
&sorted!([ &sorted!([
("store", false, &StringSchema::new("Datastore name.").schema()), ("store", false, &DATASTORE_SCHEMA),
("backup-type", false, &StringSchema::new("Backup type.") ("backup-type", false, &StringSchema::new("Backup type.")
.format(&ApiStringFormat::Enum(&["vm", "ct", "host"])) .format(&ApiStringFormat::Enum(&["vm", "ct", "host"]))
.schema() .schema()

View File

@ -101,3 +101,7 @@ pub const BACKUP_TIME_SCHEMA: Schema =
pub const UPID_SCHEMA: Schema = StringSchema::new("Unique Process/Task ID.") pub const UPID_SCHEMA: Schema = StringSchema::new("Unique Process/Task ID.")
.max_length(256) .max_length(256)
.schema(); .schema();
pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.")
.max_length(32)
.schema();