]> git.proxmox.com Git - proxmox-backup.git/blame - src/storage/config.rs
use const api definitions
[proxmox-backup.git] / src / storage / config.rs
CommitLineData
bfb1d69a
DM
1use failure::*;
2
ef2f2efb 3use crate::api_schema::*;
bfb1d69a
DM
4use crate::section_config::*;
5
6use lazy_static::lazy_static;
7
8lazy_static!{
9 static ref STORAGE_SECTION_CONFIG: SectionConfig = register_storage_plugins();
10}
11
255f378a
DM
12const ID_SCHEMA: Schema = StringSchema::new("Storage ID schema.")
13 .min_length(3)
14 .schema();
15
16const LVMTHIN_PROPERTIES: ObjectSchema = ObjectSchema::new(
17 "lvmthin properties",
18 &[
19 ("thinpool", false, &StringSchema::new("LVM thin pool name.").schema()),
20 ("vgname", false, &StringSchema::new("LVM volume group name.").schema()),
21 ("content", true, &StringSchema::new("Storage content types.").schema()),
22 ],
23);
24
bfb1d69a
DM
25fn register_storage_plugins() -> SectionConfig {
26
255f378a
DM
27 let plugin = SectionConfigPlugin::new("lvmthin".to_string(), &LVMTHIN_PROPERTIES);
28 let mut config = SectionConfig::new(&ID_SCHEMA);
bfb1d69a
DM
29 config.register_plugin(plugin);
30
31 config
32}
33
34pub fn parse_config(filename: &str, raw: &str) -> Result<SectionConfigData, Error> {
35
62ee2eb4 36 STORAGE_SECTION_CONFIG.parse(filename, raw)
bfb1d69a
DM
37}
38
39pub fn write_config(filename: &str, config: &SectionConfigData) -> Result<String, Error> {
40
41 STORAGE_SECTION_CONFIG.write(filename, config)
42}