use proxmox::api::{api, Router, RpcEnvironment, Permission};
use proxmox::api::section_config::SectionConfigData;
use proxmox::api::schema::parse_property_string;
-
use pbs_datastore::task::TaskState;
use crate::api2::config::sync::delete_sync_job;
use crate::api2::types::*;
use crate::backup::*;
use crate::config::cached_user_info::CachedUserInfo;
-use crate::config::datastore::{self, DataStoreConfig, DIR_NAME_SCHEMA};
+use crate::config::datastore::{self, DataStoreConfig};
use crate::config::acl::{PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY};
use crate::server::{jobstate, WorkerTask};
returns: {
description: "List the configured datastores (with config digest).",
type: Array,
- items: { type: datastore::DataStoreConfig },
+ items: { type: DataStoreConfig },
},
access: {
permission: &Permission::Anybody,
Ok(())
}
-// fixme: impl. const fn get_object_schema(datastore::DataStoreConfig::API_SCHEMA),
-// but this need support for match inside const fn
-// see: https://github.com/rust-lang/rust/issues/49146
-
#[api(
protected: true,
input: {
properties: {
- name: {
- schema: DATASTORE_SCHEMA,
- },
- path: {
- schema: DIR_NAME_SCHEMA,
- },
- comment: {
- optional: true,
- schema: SINGLE_LINE_COMMENT_SCHEMA,
- },
- "notify-user": {
- optional: true,
- type: Userid,
- },
- "notify": {
- optional: true,
- schema: DATASTORE_NOTIFY_STRING_SCHEMA,
- },
- "gc-schedule": {
- optional: true,
- schema: GC_SCHEDULE_SCHEMA,
- },
- "prune-schedule": {
- optional: true,
- schema: PRUNE_SCHEDULE_SCHEMA,
- },
- "keep-last": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_LAST,
- },
- "keep-hourly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_HOURLY,
- },
- "keep-daily": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_DAILY,
- },
- "keep-weekly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_WEEKLY,
- },
- "keep-monthly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_MONTHLY,
- },
- "keep-yearly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_YEARLY,
+ config: {
+ type: DataStoreConfig,
+ flatten: true,
},
},
},
)]
/// Create new datastore config.
pub fn create_datastore(
- param: Value,
+ config: DataStoreConfig,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> {
let lock = datastore::lock_config()?;
- let datastore: datastore::DataStoreConfig = serde_json::from_value(param)?;
-
- let (config, _digest) = datastore::config()?;
+ let (section_config, _digest) = datastore::config()?;
- if config.sections.get(&datastore.name).is_some() {
- bail!("datastore '{}' already exists.", datastore.name);
+ if section_config.sections.get(&config.name).is_some() {
+ bail!("datastore '{}' already exists.", config.name);
}
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
WorkerTask::new_thread(
"create-datastore",
- Some(datastore.name.to_string()),
+ Some(config.name.to_string()),
auth_id,
false,
- move |worker| do_create_datastore(lock, config, datastore, Some(&worker)),
+ move |worker| do_create_datastore(lock, section_config, config, Some(&worker)),
)
}
},
},
},
- returns: { type: datastore::DataStoreConfig },
+ returns: { type: DataStoreConfig },
access: {
permission: &Permission::Privilege(&["datastore", "{name}"], PRIV_DATASTORE_AUDIT, false),
},
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
}
- let mut data: datastore::DataStoreConfig = config.lookup("datastore", &name)?;
+ let mut data: DataStoreConfig = config.lookup("datastore", &name)?;
if let Some(delete) = delete {
for delete_prop in delete {
use proxmox_backup::config;
use proxmox_backup::api2::{self, types::* };
-use proxmox_backup::config::datastore::DIR_NAME_SCHEMA;
+use proxmox_backup::config::datastore::DataStoreConfig;
#[api(
input: {
protected: true,
input: {
properties: {
- name: {
- schema: DATASTORE_SCHEMA,
- },
- path: {
- schema: DIR_NAME_SCHEMA,
- },
- comment: {
- optional: true,
- schema: SINGLE_LINE_COMMENT_SCHEMA,
- },
- "notify-user": {
- optional: true,
- type: Userid,
- },
- "notify": {
- optional: true,
- schema: DATASTORE_NOTIFY_STRING_SCHEMA,
- },
- "gc-schedule": {
- optional: true,
- schema: GC_SCHEDULE_SCHEMA,
- },
- "prune-schedule": {
- optional: true,
- schema: PRUNE_SCHEDULE_SCHEMA,
- },
- "keep-last": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_LAST,
- },
- "keep-hourly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_HOURLY,
- },
- "keep-daily": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_DAILY,
- },
- "keep-weekly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_WEEKLY,
- },
- "keep-monthly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_MONTHLY,
- },
- "keep-yearly": {
- optional: true,
- schema: PRUNE_SCHEMA_KEEP_YEARLY,
+ config: {
+ type: DataStoreConfig,
+ flatten: true,
},
"output-format": {
schema: OUTPUT_FORMAT,