1 use std
::path
::PathBuf
;
6 use proxmox
::api
::{api, ApiMethod, Router, RpcEnvironment}
;
8 use crate::api2
::types
::*;
10 use crate::config
::datastore
;
17 description
: "List the configured datastores.",
20 type: datastore
::DataStoreConfig
,
24 /// List all datastores
25 pub fn list_datastores(
28 _rpcenv
: &mut dyn RpcEnvironment
,
29 ) -> Result
<Value
, Error
> {
31 let (config
, digest
) = datastore
::config()?
;
33 Ok(config
.convert_to_array("name", Some(&digest
)))
41 schema
: DATASTORE_SCHEMA
,
45 schema
: SINGLE_LINE_COMMENT_SCHEMA
,
48 schema
: datastore
::DIR_NAME_SCHEMA
,
53 /// Create new datastore config.
54 pub fn create_datastore(name
: String
, param
: Value
) -> Result
<(), Error
> {
58 let datastore
: datastore
::DataStoreConfig
= serde_json
::from_value(param
.clone())?
;
60 let (mut config
, _digest
) = datastore
::config()?
;
62 if let Some(_
) = config
.sections
.get(&name
) {
63 bail
!("datastore '{}' already exists.", name
);
66 let path
: PathBuf
= datastore
.path
.clone().into();
68 let backup_user
= crate::backup
::backup_user()?
;
69 let _store
= ChunkStore
::create(&name
, path
, backup_user
.uid
, backup_user
.gid
)?
;
71 config
.set_data(&name
, "datastore", &datastore
)?
;
73 datastore
::save_config(&config
)?
;
83 schema
: DATASTORE_SCHEMA
,
88 /// Remove a datastore configuration.
89 pub fn delete_datastore(name
: String
) -> Result
<(), Error
> {
92 // fixme: check digest ?
94 let (mut config
, _digest
) = datastore
::config()?
;
96 match config
.sections
.get(&name
) {
97 Some(_
) => { config.sections.remove(&name); }
,
98 None
=> bail
!("datastore '{}' does not exist.", name
),
101 datastore
::save_config(&config
)?
;
106 pub const ROUTER
: Router
= Router
::new()
107 .get(&API_METHOD_LIST_DATASTORES
)
108 .post(&API_METHOD_CREATE_DATASTORE
)
109 .delete(&API_METHOD_DELETE_DATASTORE
);