2019-11-21 13:36:28 +00:00
|
|
|
use std::path::PathBuf;
|
2018-12-08 13:44:55 +00:00
|
|
|
|
2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{bail, Error};
|
2019-12-20 11:28:28 +00:00
|
|
|
use serde_json::Value;
|
2020-04-29 07:09:59 +00:00
|
|
|
use ::serde::{Deserialize, Serialize};
|
2018-12-08 13:44:55 +00:00
|
|
|
|
2020-05-20 09:29:59 +00:00
|
|
|
use proxmox::api::{api, Router, RpcEnvironment, Permission};
|
2020-11-05 10:32:59 +00:00
|
|
|
use proxmox::api::schema::parse_property_string;
|
2020-08-04 09:33:02 +00:00
|
|
|
use proxmox::tools::fs::open_file_locked;
|
2019-11-21 13:36:28 +00:00
|
|
|
|
2019-12-11 12:45:23 +00:00
|
|
|
use crate::api2::types::*;
|
2019-11-21 13:36:28 +00:00
|
|
|
use crate::backup::*;
|
2020-09-18 09:45:11 +00:00
|
|
|
use crate::config::cached_user_info::CachedUserInfo;
|
2020-05-20 09:29:59 +00:00
|
|
|
use crate::config::datastore::{self, DataStoreConfig, DIR_NAME_SCHEMA};
|
2020-10-06 10:08:54 +00:00
|
|
|
use crate::config::acl::{PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY};
|
2020-10-28 06:33:05 +00:00
|
|
|
use crate::server::jobstate;
|
2018-12-08 13:51:08 +00:00
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {},
|
|
|
|
},
|
|
|
|
returns: {
|
2020-01-14 13:55:58 +00:00
|
|
|
description: "List the configured datastores (with config digest).",
|
2020-01-11 09:42:09 +00:00
|
|
|
type: Array,
|
2020-05-20 09:29:59 +00:00
|
|
|
items: { type: datastore::DataStoreConfig },
|
2020-01-11 09:42:09 +00:00
|
|
|
},
|
2020-04-17 12:51:29 +00:00
|
|
|
access: {
|
2020-09-18 09:45:11 +00:00
|
|
|
permission: &Permission::Anybody,
|
2020-04-17 12:51:29 +00:00
|
|
|
},
|
2020-01-11 09:42:09 +00:00
|
|
|
)]
|
|
|
|
/// List all datastores
|
|
|
|
pub fn list_datastores(
|
2019-01-26 13:50:37 +00:00
|
|
|
_param: Value,
|
2020-05-20 09:29:59 +00:00
|
|
|
mut rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<Vec<DataStoreConfig>, Error> {
|
2018-12-08 13:51:08 +00:00
|
|
|
|
2020-01-14 11:57:03 +00:00
|
|
|
let (config, digest) = datastore::config()?;
|
2018-12-09 09:23:19 +00:00
|
|
|
|
2020-10-23 11:33:21 +00:00
|
|
|
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
2020-09-18 09:45:11 +00:00
|
|
|
let user_info = CachedUserInfo::new()?;
|
2020-05-20 09:29:59 +00:00
|
|
|
|
|
|
|
rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
|
|
|
|
|
2020-09-18 09:45:11 +00:00
|
|
|
let list:Vec<DataStoreConfig> = config.convert_to_typed_array("datastore")?;
|
|
|
|
let filter_by_privs = |store: &DataStoreConfig| {
|
2020-10-23 11:33:21 +00:00
|
|
|
let user_privs = user_info.lookup_privs(&auth_id, &["datastore", &store.name]);
|
2020-09-18 09:45:11 +00:00
|
|
|
(user_privs & PRIV_DATASTORE_AUDIT) != 0
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(list.into_iter().filter(filter_by_privs).collect())
|
2018-12-09 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 09:29:59 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
#[api(
|
|
|
|
protected: true,
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
2020-05-20 09:29:59 +00:00
|
|
|
path: {
|
|
|
|
schema: DIR_NAME_SCHEMA,
|
|
|
|
},
|
2020-01-11 09:42:09 +00:00
|
|
|
comment: {
|
|
|
|
optional: true,
|
2020-01-13 11:02:13 +00:00
|
|
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
2020-01-11 09:42:09 +00:00
|
|
|
},
|
2020-11-04 09:42:22 +00:00
|
|
|
"notify-user": {
|
|
|
|
optional: true,
|
|
|
|
type: Userid,
|
|
|
|
},
|
|
|
|
"notify": {
|
|
|
|
optional: true,
|
2020-11-05 10:32:59 +00:00
|
|
|
schema: DATASTORE_NOTIFY_STRING_SCHEMA,
|
2020-11-04 09:42:22 +00:00
|
|
|
},
|
2020-05-20 06:38:10 +00:00
|
|
|
"gc-schedule": {
|
|
|
|
optional: true,
|
|
|
|
schema: GC_SCHEDULE_SCHEMA,
|
|
|
|
},
|
2020-05-20 09:29:59 +00:00
|
|
|
"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,
|
2020-01-11 09:42:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-17 12:51:29 +00:00
|
|
|
access: {
|
2020-10-06 10:08:54 +00:00
|
|
|
permission: &Permission::Privilege(&["datastore"], PRIV_DATASTORE_ALLOCATE, false),
|
2020-04-17 12:51:29 +00:00
|
|
|
},
|
2020-01-11 09:42:09 +00:00
|
|
|
)]
|
|
|
|
/// Create new datastore config.
|
2020-05-20 09:29:59 +00:00
|
|
|
pub fn create_datastore(param: Value) -> Result<(), Error> {
|
2018-12-09 10:59:32 +00:00
|
|
|
|
2020-09-28 08:50:44 +00:00
|
|
|
let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
2018-12-09 11:51:31 +00:00
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
let datastore: datastore::DataStoreConfig = serde_json::from_value(param.clone())?;
|
2018-12-09 11:51:31 +00:00
|
|
|
|
2020-01-14 11:57:03 +00:00
|
|
|
let (mut config, _digest) = datastore::config()?;
|
2018-12-09 11:51:31 +00:00
|
|
|
|
2020-05-20 09:29:59 +00:00
|
|
|
if let Some(_) = config.sections.get(&datastore.name) {
|
|
|
|
bail!("datastore '{}' already exists.", datastore.name);
|
2018-12-09 11:51:31 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
let path: PathBuf = datastore.path.clone().into();
|
|
|
|
|
|
|
|
let backup_user = crate::backup::backup_user()?;
|
2020-05-20 09:29:59 +00:00
|
|
|
let _store = ChunkStore::create(&datastore.name, path, backup_user.uid, backup_user.gid)?;
|
2020-01-11 09:42:09 +00:00
|
|
|
|
2020-05-20 09:29:59 +00:00
|
|
|
config.set_data(&datastore.name, "datastore", &datastore)?;
|
2018-12-09 11:51:31 +00:00
|
|
|
|
|
|
|
datastore::save_config(&config)?;
|
|
|
|
|
2020-10-28 06:33:05 +00:00
|
|
|
jobstate::create_state_file("prune", &datastore.name)?;
|
|
|
|
jobstate::create_state_file("garbage_collection", &datastore.name)?;
|
2020-09-18 14:03:52 +00:00
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
Ok(())
|
2018-12-08 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-09 09:54:38 +00:00
|
|
|
returns: { type: datastore::DataStoreConfig },
|
2020-04-17 12:51:29 +00:00
|
|
|
access: {
|
|
|
|
permission: &Permission::Privilege(&["datastore", "{name}"], PRIV_DATASTORE_AUDIT, false),
|
|
|
|
},
|
2020-01-14 13:45:56 +00:00
|
|
|
)]
|
|
|
|
/// Read a datastore configuration.
|
2020-05-20 09:29:59 +00:00
|
|
|
pub fn read_datastore(
|
|
|
|
name: String,
|
|
|
|
mut rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<DataStoreConfig, Error> {
|
2020-01-14 13:45:56 +00:00
|
|
|
let (config, digest) = datastore::config()?;
|
2020-05-20 09:29:59 +00:00
|
|
|
|
|
|
|
let store_config = config.lookup("datastore", &name)?;
|
|
|
|
rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
|
|
|
|
|
|
|
|
Ok(store_config)
|
2020-01-14 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 07:09:59 +00:00
|
|
|
#[api()]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2020-05-20 06:38:10 +00:00
|
|
|
#[serde(rename_all="kebab-case")]
|
2020-04-29 07:09:59 +00:00
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
/// Deletable property name
|
|
|
|
pub enum DeletableProperty {
|
|
|
|
/// Delete the comment property.
|
|
|
|
comment,
|
2020-05-20 06:38:10 +00:00
|
|
|
/// Delete the garbage collection schedule.
|
|
|
|
gc_schedule,
|
2020-05-20 09:29:59 +00:00
|
|
|
/// Delete the prune job schedule.
|
|
|
|
prune_schedule,
|
|
|
|
/// Delete the keep-last property
|
|
|
|
keep_last,
|
|
|
|
/// Delete the keep-hourly property
|
|
|
|
keep_hourly,
|
|
|
|
/// Delete the keep-daily property
|
|
|
|
keep_daily,
|
|
|
|
/// Delete the keep-weekly property
|
|
|
|
keep_weekly,
|
|
|
|
/// Delete the keep-monthly property
|
|
|
|
keep_monthly,
|
|
|
|
/// Delete the keep-yearly property
|
|
|
|
keep_yearly,
|
2020-11-06 13:08:01 +00:00
|
|
|
/// Delete the verify-new property
|
|
|
|
verify_new,
|
2020-11-04 09:42:22 +00:00
|
|
|
/// Delete the notify-user property
|
|
|
|
notify_user,
|
|
|
|
/// Delete the notify property
|
|
|
|
notify,
|
2020-04-29 07:09:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
#[api(
|
|
|
|
protected: true,
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
|
|
|
comment: {
|
|
|
|
optional: true,
|
|
|
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
|
|
|
},
|
2020-11-04 09:42:22 +00:00
|
|
|
"notify-user": {
|
|
|
|
optional: true,
|
|
|
|
type: Userid,
|
|
|
|
},
|
|
|
|
"notify": {
|
|
|
|
optional: true,
|
2020-11-05 10:32:59 +00:00
|
|
|
schema: DATASTORE_NOTIFY_STRING_SCHEMA,
|
2020-11-04 09:42:22 +00:00
|
|
|
},
|
2020-05-20 06:38:10 +00:00
|
|
|
"gc-schedule": {
|
|
|
|
optional: true,
|
|
|
|
schema: GC_SCHEDULE_SCHEMA,
|
|
|
|
},
|
2020-05-20 09:29:59 +00:00
|
|
|
"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,
|
|
|
|
},
|
2020-11-06 13:08:01 +00:00
|
|
|
"verify-new": {
|
|
|
|
description: "If enabled, all new backups will be verified right after completion.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-04-29 07:09:59 +00:00
|
|
|
delete: {
|
|
|
|
description: "List of properties to delete.",
|
|
|
|
type: Array,
|
|
|
|
optional: true,
|
|
|
|
items: {
|
|
|
|
type: DeletableProperty,
|
|
|
|
}
|
|
|
|
},
|
2020-01-15 11:27:05 +00:00
|
|
|
digest: {
|
|
|
|
optional: true,
|
|
|
|
schema: PROXMOX_CONFIG_DIGEST_SCHEMA,
|
|
|
|
},
|
2020-01-14 13:45:56 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-17 12:51:29 +00:00
|
|
|
access: {
|
2020-04-27 04:50:35 +00:00
|
|
|
permission: &Permission::Privilege(&["datastore", "{name}"], PRIV_DATASTORE_MODIFY, false),
|
2020-04-17 12:51:29 +00:00
|
|
|
},
|
2020-01-14 13:45:56 +00:00
|
|
|
)]
|
2020-04-22 06:53:16 +00:00
|
|
|
/// Update datastore config.
|
2020-01-14 13:45:56 +00:00
|
|
|
pub fn update_datastore(
|
|
|
|
name: String,
|
|
|
|
comment: Option<String>,
|
2020-05-20 06:38:10 +00:00
|
|
|
gc_schedule: Option<String>,
|
2020-05-20 09:29:59 +00:00
|
|
|
prune_schedule: Option<String>,
|
2020-05-20 11:00:13 +00:00
|
|
|
keep_last: Option<u64>,
|
|
|
|
keep_hourly: Option<u64>,
|
|
|
|
keep_daily: Option<u64>,
|
|
|
|
keep_weekly: Option<u64>,
|
|
|
|
keep_monthly: Option<u64>,
|
|
|
|
keep_yearly: Option<u64>,
|
2020-11-06 13:08:01 +00:00
|
|
|
verify_new: Option<bool>,
|
2020-11-05 10:32:59 +00:00
|
|
|
notify: Option<String>,
|
2020-11-04 09:42:22 +00:00
|
|
|
notify_user: Option<Userid>,
|
2020-04-29 07:09:59 +00:00
|
|
|
delete: Option<Vec<DeletableProperty>>,
|
2020-01-15 11:27:05 +00:00
|
|
|
digest: Option<String>,
|
2020-01-14 13:45:56 +00:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
2020-09-28 08:50:44 +00:00
|
|
|
let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
2020-01-15 10:57:12 +00:00
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
// pass/compare digest
|
2020-01-15 11:27:05 +00:00
|
|
|
let (mut config, expected_digest) = datastore::config()?;
|
|
|
|
|
|
|
|
if let Some(ref digest) = digest {
|
|
|
|
let digest = proxmox::tools::hex_to_digest(digest)?;
|
|
|
|
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
|
|
|
|
}
|
2020-01-14 13:45:56 +00:00
|
|
|
|
|
|
|
let mut data: datastore::DataStoreConfig = config.lookup("datastore", &name)?;
|
|
|
|
|
2020-04-29 07:09:59 +00:00
|
|
|
if let Some(delete) = delete {
|
|
|
|
for delete_prop in delete {
|
|
|
|
match delete_prop {
|
|
|
|
DeletableProperty::comment => { data.comment = None; },
|
2020-05-20 06:38:10 +00:00
|
|
|
DeletableProperty::gc_schedule => { data.gc_schedule = None; },
|
2020-05-20 09:29:59 +00:00
|
|
|
DeletableProperty::prune_schedule => { data.prune_schedule = None; },
|
|
|
|
DeletableProperty::keep_last => { data.keep_last = None; },
|
|
|
|
DeletableProperty::keep_hourly => { data.keep_hourly = None; },
|
|
|
|
DeletableProperty::keep_daily => { data.keep_daily = None; },
|
|
|
|
DeletableProperty::keep_weekly => { data.keep_weekly = None; },
|
|
|
|
DeletableProperty::keep_monthly => { data.keep_monthly = None; },
|
|
|
|
DeletableProperty::keep_yearly => { data.keep_yearly = None; },
|
2020-11-06 13:08:01 +00:00
|
|
|
DeletableProperty::verify_new => { data.verify_new = None; },
|
2020-11-04 09:42:22 +00:00
|
|
|
DeletableProperty::notify => { data.notify = None; },
|
|
|
|
DeletableProperty::notify_user => { data.notify_user = None; },
|
2020-04-29 07:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
if let Some(comment) = comment {
|
|
|
|
let comment = comment.trim().to_string();
|
|
|
|
if comment.is_empty() {
|
|
|
|
data.comment = None;
|
|
|
|
} else {
|
|
|
|
data.comment = Some(comment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 14:13:54 +00:00
|
|
|
let mut gc_schedule_changed = false;
|
|
|
|
if gc_schedule.is_some() {
|
|
|
|
gc_schedule_changed = data.gc_schedule != gc_schedule;
|
|
|
|
data.gc_schedule = gc_schedule;
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:03:52 +00:00
|
|
|
let mut prune_schedule_changed = false;
|
|
|
|
if prune_schedule.is_some() {
|
2020-09-24 14:13:54 +00:00
|
|
|
prune_schedule_changed = data.prune_schedule != prune_schedule;
|
2020-09-18 14:03:52 +00:00
|
|
|
data.prune_schedule = prune_schedule;
|
|
|
|
}
|
2020-09-24 14:13:54 +00:00
|
|
|
|
2020-05-20 09:29:59 +00:00
|
|
|
if keep_last.is_some() { data.keep_last = keep_last; }
|
|
|
|
if keep_hourly.is_some() { data.keep_hourly = keep_hourly; }
|
|
|
|
if keep_daily.is_some() { data.keep_daily = keep_daily; }
|
|
|
|
if keep_weekly.is_some() { data.keep_weekly = keep_weekly; }
|
|
|
|
if keep_monthly.is_some() { data.keep_monthly = keep_monthly; }
|
|
|
|
if keep_yearly.is_some() { data.keep_yearly = keep_yearly; }
|
2020-05-20 06:38:10 +00:00
|
|
|
|
2020-11-05 10:32:59 +00:00
|
|
|
if let Some(notify_str) = notify {
|
|
|
|
let value = parse_property_string(¬ify_str, &DatastoreNotify::API_SCHEMA)?;
|
|
|
|
let notify: DatastoreNotify = serde_json::from_value(value)?;
|
|
|
|
if let DatastoreNotify { gc: None, verify: None, sync: None } = notify {
|
|
|
|
data.notify = None;
|
|
|
|
} else {
|
|
|
|
data.notify = Some(notify_str);
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 13:08:01 +00:00
|
|
|
if verify_new.is_some() { data.verify_new = verify_new; }
|
|
|
|
|
2020-11-04 09:42:22 +00:00
|
|
|
if notify_user.is_some() { data.notify_user = notify_user; }
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
config.set_data(&name, "datastore", &data)?;
|
|
|
|
|
|
|
|
datastore::save_config(&config)?;
|
|
|
|
|
2020-09-24 14:13:54 +00:00
|
|
|
// we want to reset the statefiles, to avoid an immediate action in some cases
|
2020-09-18 14:03:52 +00:00
|
|
|
// (e.g. going from monthly to weekly in the second week of the month)
|
2020-09-24 14:13:54 +00:00
|
|
|
if gc_schedule_changed {
|
2020-10-28 06:33:05 +00:00
|
|
|
jobstate::create_state_file("garbage_collection", &name)?;
|
2020-09-24 14:13:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 14:03:52 +00:00
|
|
|
if prune_schedule_changed {
|
2020-10-28 06:33:05 +00:00
|
|
|
jobstate::create_state_file("prune", &name)?;
|
2020-09-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
#[api(
|
|
|
|
protected: true,
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
2020-04-17 12:51:29 +00:00
|
|
|
digest: {
|
|
|
|
optional: true,
|
|
|
|
schema: PROXMOX_CONFIG_DIGEST_SCHEMA,
|
|
|
|
},
|
2020-01-11 09:42:09 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-17 12:51:29 +00:00
|
|
|
access: {
|
2020-10-08 07:16:02 +00:00
|
|
|
permission: &Permission::Privilege(&["datastore", "{name}"], PRIV_DATASTORE_ALLOCATE, false),
|
2020-04-17 12:51:29 +00:00
|
|
|
},
|
2020-01-11 09:42:09 +00:00
|
|
|
)]
|
|
|
|
/// Remove a datastore configuration.
|
2020-04-17 12:51:29 +00:00
|
|
|
pub fn delete_datastore(name: String, digest: Option<String>) -> Result<(), Error> {
|
2018-12-09 15:52:32 +00:00
|
|
|
|
2020-09-28 08:50:44 +00:00
|
|
|
let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
2018-12-09 15:52:32 +00:00
|
|
|
|
2020-04-17 12:51:29 +00:00
|
|
|
let (mut config, expected_digest) = datastore::config()?;
|
|
|
|
|
|
|
|
if let Some(ref digest) = digest {
|
|
|
|
let digest = proxmox::tools::hex_to_digest(digest)?;
|
|
|
|
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
|
|
|
|
}
|
2018-12-09 15:52:32 +00:00
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
match config.sections.get(&name) {
|
|
|
|
Some(_) => { config.sections.remove(&name); },
|
2018-12-09 15:52:32 +00:00
|
|
|
None => bail!("datastore '{}' does not exist.", name),
|
|
|
|
}
|
|
|
|
|
|
|
|
datastore::save_config(&config)?;
|
|
|
|
|
2020-09-24 14:13:54 +00:00
|
|
|
// ignore errors
|
2020-10-28 06:33:05 +00:00
|
|
|
let _ = jobstate::remove_state_file("prune", &name);
|
|
|
|
let _ = jobstate::remove_state_file("garbage_collection", &name);
|
2020-09-18 14:03:52 +00:00
|
|
|
|
2020-01-11 09:42:09 +00:00
|
|
|
Ok(())
|
2018-12-09 15:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:45:56 +00:00
|
|
|
const ITEM_ROUTER: Router = Router::new()
|
|
|
|
.get(&API_METHOD_READ_DATASTORE)
|
|
|
|
.put(&API_METHOD_UPDATE_DATASTORE)
|
|
|
|
.delete(&API_METHOD_DELETE_DATASTORE);
|
|
|
|
|
2019-11-21 08:36:41 +00:00
|
|
|
pub const ROUTER: Router = Router::new()
|
2020-01-11 09:42:09 +00:00
|
|
|
.get(&API_METHOD_LIST_DATASTORES)
|
|
|
|
.post(&API_METHOD_CREATE_DATASTORE)
|
2020-01-14 13:45:56 +00:00
|
|
|
.match_all("name", &ITEM_ROUTER);
|