src/tools/systemd/types.rs: add Mount config
This commit is contained in:
parent
cdde66d277
commit
b9cf6ee797
|
@ -18,6 +18,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions};
|
|||
lazy_static! {
|
||||
pub static ref SERVICE_CONFIG: SectionConfig = init_service();
|
||||
pub static ref TIMER_CONFIG: SectionConfig = init_timer();
|
||||
pub static ref MOUNT_CONFIG: SectionConfig = init_mount();
|
||||
}
|
||||
|
||||
fn init_service() -> SectionConfig {
|
||||
|
@ -78,6 +79,35 @@ fn init_timer() -> SectionConfig {
|
|||
config
|
||||
}
|
||||
|
||||
fn init_mount() -> SectionConfig {
|
||||
|
||||
let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
|
||||
|
||||
match SystemdUnitSection::API_SCHEMA {
|
||||
Schema::Object(ref obj_schema) => {
|
||||
let plugin = SectionConfigPlugin::new("Unit".to_string(), None, obj_schema);
|
||||
config.register_plugin(plugin);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
match SystemdInstallSection::API_SCHEMA {
|
||||
Schema::Object(ref obj_schema) => {
|
||||
let plugin = SectionConfigPlugin::new("Install".to_string(), None, obj_schema);
|
||||
config.register_plugin(plugin);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
match SystemdMountSection::API_SCHEMA {
|
||||
Schema::Object(ref obj_schema) => {
|
||||
let plugin = SectionConfigPlugin::new("Mount".to_string(), None, obj_schema);
|
||||
config.register_plugin(plugin);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
fn parse_systemd_config(config: &SectionConfig, filename: &str) -> Result<SectionConfigData, Error> {
|
||||
|
||||
let raw = proxmox::tools::fs::file_get_contents(filename)?;
|
||||
|
@ -117,3 +147,7 @@ pub fn save_systemd_service(filename: &str, data: &SectionConfigData) -> Result<
|
|||
pub fn save_systemd_timer(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
|
||||
save_systemd_config(&TIMER_CONFIG, filename, data)
|
||||
}
|
||||
|
||||
pub fn save_systemd_mount(filename: &str, data: &SectionConfigData) -> Result<(), Error> {
|
||||
save_systemd_config(&MOUNT_CONFIG, filename, data)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ pub const SYSTEMD_SECTION_NAME_SCHEMA: Schema = StringSchema::new(
|
|||
EnumEntry::new("Unit", "Unit"),
|
||||
EnumEntry::new("Timer", "Timer"),
|
||||
EnumEntry::new("Install", "Install"),
|
||||
EnumEntry::new("Mount", "Mount"),
|
||||
EnumEntry::new("Service", "Service")]))
|
||||
.schema();
|
||||
|
||||
|
@ -185,6 +186,47 @@ pub struct SystemdInstallSection {
|
|||
pub RequiredBy: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
"TimeoutSec": {
|
||||
schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
}
|
||||
)]
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
#[allow(non_snake_case)]
|
||||
/// Systemd Service Section
|
||||
pub struct SystemdMountSection {
|
||||
/// absolute path of a device node, file or other resource to mount
|
||||
pub What: String,
|
||||
/// absolute path of a file or directory for the mount point
|
||||
pub Where: String,
|
||||
/// Takes a string for the file system type. See mount(8) for details.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub Type: Option<String>,
|
||||
/// Mount options to use when mounting. This takes a comma-separated list of options.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub Options: Option<String>,
|
||||
/// If true, parsing of the options specified in Options= is relaxed, and unknown mount options are tolerated.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub SloppyOptions: Option<bool>,
|
||||
/// Use lazy unmount
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub LazyUnmount: Option<bool>,
|
||||
/// Use forces unmount
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub ForceUnmount: Option<bool>,
|
||||
/// Directories of mount points (and any parent directories) are
|
||||
/// automatically created if needed. Takes an access mode in octal
|
||||
/// notation. Defaults to 0755.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub DirectoryMode: Option<String>,
|
||||
/// Configures the time to wait for the mount command to finish.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub TimeoutSec: Option<String>,
|
||||
}
|
||||
|
||||
#[api()]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
|
|
Loading…
Reference in New Issue