]>
git.proxmox.com Git - proxmox-backup.git/blob - src/config/datastore.rs
0098dca7905dfca3e737a6cb0952e5b6c83a1597
3 //use std::fs::{OpenOptions};
8 use crate::api
::schema
::*;
10 use crate::section_config
::*;
12 use lazy_static
::lazy_static
;
15 static ref CONFIG
: SectionConfig
= init();
18 fn init() -> SectionConfig
{
20 let plugin
= SectionConfigPlugin
::new(
21 "datastore".to_string(),
22 ObjectSchema
::new("DataStore properties")
23 .required("path", StringSchema
::new("Directory name"))
26 let id_schema
= StringSchema
::new("DataStore ID schema.")
30 let mut config
= SectionConfig
::new(id_schema
);
31 config
.register_plugin(plugin
);
36 const DATASTORE_CFG_FILENAME
: &str = "/etc/proxmox-backup/datastore.cfg";
38 pub fn config() -> Result
<SectionConfigData
, Error
> {
40 let mut contents
= String
::new();
43 match std
::fs
::File
::open(DATASTORE_CFG_FILENAME
) {
44 Ok(mut file
) => file
.read_to_string(&mut contents
),
46 if err
.kind() == std
::io
::ErrorKind
::NotFound
{
47 contents
= String
::from("");
54 }).map_err(|e
| format_err
!("unable to read '{}' - {}", DATASTORE_CFG_FILENAME
, e
))?
;
56 CONFIG
.parse(DATASTORE_CFG_FILENAME
, &contents
)
59 pub fn save_config(config
: &SectionConfigData
) -> Result
<(), Error
> {
61 let raw
= CONFIG
.write(DATASTORE_CFG_FILENAME
, &config
)?
;
63 tools
::file_set_contents(DATASTORE_CFG_FILENAME
, raw
.as_bytes(), None
)?
;
68 // shell completion helper
69 pub fn complete_datastore_name(_arg
: &str) -> Vec
<String
> {
71 Ok(data
) => data
.sections
.iter().map(|(id
,_
)| id
.to_string()).collect(),
72 Err(_
) => return vec
![],