1 //! Media Pool configuration (Tape backup)
3 //! This configuration module is based on [`SectionConfig`], and
4 //! provides a type safe interface to store [`MediaPoolConfig`],
6 //! [MediaPoolConfig]: crate::api2::types::MediaPoolConfig
7 //! [SectionConfig]: proxmox::api::section_config::SectionConfig
9 use std
::collections
::HashMap
;
12 use lazy_static
::lazy_static
;
25 use pbs_config
::{open_backup_lockfile, BackupLockGuard}
;
29 MEDIA_POOL_NAME_SCHEMA
,
35 /// Static [`SectionConfig`] to access parser/writer functions.
36 pub static ref CONFIG
: SectionConfig
= init();
39 fn init() -> SectionConfig
{
40 let mut config
= SectionConfig
::new(&MEDIA_POOL_NAME_SCHEMA
);
42 let obj_schema
= match MediaPoolConfig
::API_SCHEMA
{
43 Schema
::Object(ref obj_schema
) => obj_schema
,
46 let plugin
= SectionConfigPlugin
::new("pool".to_string(), Some("name".to_string()), obj_schema
);
47 config
.register_plugin(plugin
);
52 /// Configuration file name
53 pub const MEDIA_POOL_CFG_FILENAME
: &str = "/etc/proxmox-backup/media-pool.cfg";
54 /// Lock file name (used to prevent concurrent access)
55 pub const MEDIA_POOL_CFG_LOCKFILE
: &str = "/etc/proxmox-backup/.media-pool.lck";
57 /// Get exclusive lock
58 pub fn lock() -> Result
<BackupLockGuard
, Error
> {
59 open_backup_lockfile(MEDIA_POOL_CFG_LOCKFILE
, None
, true)
62 /// Read and parse the configuration file
63 pub fn config() -> Result
<(SectionConfigData
, [u8;32]), Error
> {
65 let content
= proxmox
::tools
::fs
::file_read_optional_string(MEDIA_POOL_CFG_FILENAME
)?
66 .unwrap_or_else(|| "".to_string());
68 let digest
= openssl
::sha
::sha256(content
.as_bytes());
69 let data
= CONFIG
.parse(MEDIA_POOL_CFG_FILENAME
, &content
)?
;
73 /// Save the configuration file
74 pub fn save_config(config
: &SectionConfigData
) -> Result
<(), Error
> {
75 let raw
= CONFIG
.write(MEDIA_POOL_CFG_FILENAME
, &config
)?
;
76 pbs_config
::replace_backup_config(MEDIA_POOL_CFG_FILENAME
, raw
.as_bytes())
79 // shell completion helper
81 /// List existing pool names
82 pub fn complete_pool_name(_arg
: &str, _param
: &HashMap
<String
, String
>) -> Vec
<String
> {
84 Ok((data
, _digest
)) => data
.sections
.iter().map(|(id
, _
)| id
.to_string()).collect(),
85 Err(_
) => return vec
![],