]>
Commit | Line | Data |
---|---|---|
bfb1d69a DM |
1 | use failure::*; |
2 | ||
ef2f2efb | 3 | use crate::api_schema::*; |
bfb1d69a DM |
4 | use crate::section_config::*; |
5 | ||
6 | use lazy_static::lazy_static; | |
7 | ||
8 | lazy_static!{ | |
9 | static ref STORAGE_SECTION_CONFIG: SectionConfig = register_storage_plugins(); | |
10 | } | |
11 | ||
255f378a DM |
12 | const ID_SCHEMA: Schema = StringSchema::new("Storage ID schema.") |
13 | .min_length(3) | |
14 | .schema(); | |
15 | ||
16 | const 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 |
25 | fn 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 | ||
34 | pub fn parse_config(filename: &str, raw: &str) -> Result<SectionConfigData, Error> { | |
35 | ||
62ee2eb4 | 36 | STORAGE_SECTION_CONFIG.parse(filename, raw) |
bfb1d69a DM |
37 | } |
38 | ||
39 | pub fn write_config(filename: &str, config: &SectionConfigData) -> Result<String, Error> { | |
40 | ||
41 | STORAGE_SECTION_CONFIG.write(filename, config) | |
42 | } |