diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs index 6948ad82..29811164 100644 --- a/pbs-config/src/lib.rs +++ b/pbs-config/src/lib.rs @@ -1,5 +1,6 @@ pub mod domains; pub mod drive; +pub mod media_pool; pub mod remote; use anyhow::{format_err, Error}; diff --git a/src/config/media_pool.rs b/pbs-config/src/media_pool.rs similarity index 90% rename from src/config/media_pool.rs rename to pbs-config/src/media_pool.rs index f7f544f0..3512c70a 100644 --- a/src/config/media_pool.rs +++ b/pbs-config/src/media_pool.rs @@ -22,14 +22,9 @@ use proxmox::{ }, }; -use pbs_config::{open_backup_lockfile, BackupLockGuard}; +use pbs_api_types::{MEDIA_POOL_NAME_SCHEMA, MediaPoolConfig}; -use crate::{ - api2::types::{ - MEDIA_POOL_NAME_SCHEMA, - MediaPoolConfig, - }, -}; +use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; lazy_static! { /// Static [`SectionConfig`] to access parser/writer functions. @@ -73,7 +68,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { /// Save the configuration file pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { let raw = CONFIG.write(MEDIA_POOL_CFG_FILENAME, &config)?; - pbs_config::replace_backup_config(MEDIA_POOL_CFG_FILENAME, raw.as_bytes()) + replace_backup_config(MEDIA_POOL_CFG_FILENAME, raw.as_bytes()) } // shell completion helper diff --git a/src/api2/config/media_pool.rs b/src/api2/config/media_pool.rs index 56b296af..3e583a29 100644 --- a/src/api2/config/media_pool.rs +++ b/src/api2/config/media_pool.rs @@ -10,15 +10,15 @@ use proxmox::{ }, }; +use pbs_api_types::{ + Authid, + MEDIA_POOL_NAME_SCHEMA, + MediaPoolConfig, + MediaPoolConfigUpdater, +}; + use crate::{ - api2::types::{ - Authid, - MEDIA_POOL_NAME_SCHEMA, - MediaPoolConfig, - MediaPoolConfigUpdater, - }, config::{ - self, cached_user_info::CachedUserInfo, acl::{ PRIV_TAPE_AUDIT, @@ -46,9 +46,9 @@ pub fn create_pool( config: MediaPoolConfig, ) -> Result<(), Error> { - let _lock = config::media_pool::lock()?; + let _lock = pbs_config::media_pool::lock()?; - let (mut section_config, _digest) = config::media_pool::config()?; + let (mut section_config, _digest) = pbs_config::media_pool::config()?; if section_config.sections.get(&config.name).is_some() { bail!("Media pool '{}' already exists", config.name); @@ -56,7 +56,7 @@ pub fn create_pool( section_config.set_data(&config.name, "pool", &config)?; - config::media_pool::save_config(§ion_config)?; + pbs_config::media_pool::save_config(§ion_config)?; Ok(()) } @@ -81,7 +81,7 @@ pub fn list_pools( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let (config, digest) = config::media_pool::config()?; + let (config, digest) = pbs_config::media_pool::config()?; let list = config.convert_to_typed_array::("pool")?; @@ -116,7 +116,7 @@ pub fn list_pools( /// Get media pool configuration pub fn get_config(name: String) -> Result { - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let data: MediaPoolConfig = config.lookup("pool", &name)?; @@ -172,9 +172,9 @@ pub fn update_pool( delete: Option>, ) -> Result<(), Error> { - let _lock = config::media_pool::lock()?; + let _lock = pbs_config::media_pool::lock()?; - let (mut config, _digest) = config::media_pool::config()?; + let (mut config, _digest) = pbs_config::media_pool::config()?; let mut data: MediaPoolConfig = config.lookup("pool", &name)?; @@ -206,7 +206,7 @@ pub fn update_pool( config.set_data(&name, "pool", &data)?; - config::media_pool::save_config(&config)?; + pbs_config::media_pool::save_config(&config)?; Ok(()) } @@ -227,16 +227,16 @@ pub fn update_pool( /// Delete a media pool configuration pub fn delete_pool(name: String) -> Result<(), Error> { - let _lock = config::media_pool::lock()?; + let _lock = pbs_config::media_pool::lock()?; - let (mut config, _digest) = config::media_pool::config()?; + let (mut config, _digest) = pbs_config::media_pool::config()?; match config.sections.get(&name) { Some(_) => { config.sections.remove(&name); }, None => bail!("delete pool '{}' failed - no such pool", name), } - config::media_pool::save_config(&config)?; + pbs_config::media_pool::save_config(&config)?; Ok(()) } diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 4e6c735d..1d3e3cc5 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -122,7 +122,7 @@ pub fn list_tape_backup_jobs( let user_info = CachedUserInfo::new()?; let (job_config, digest) = config::tape_job::config()?; - let (pool_config, _pool_digest) = config::media_pool::config()?; + let (pool_config, _pool_digest) = pbs_config::media_pool::config()?; let (drive_config, _digest) = pbs_config::drive::config()?; let job_list_iter = job_config @@ -191,7 +191,7 @@ pub fn do_tape_backup_job( let datastore = DataStore::lookup_datastore(&setup.store)?; - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let pool_config: MediaPoolConfig = config.lookup("pool", &setup.pool)?; let (drive_config, _digest) = pbs_config::drive::config()?; @@ -370,7 +370,7 @@ pub fn backup( let datastore = DataStore::lookup_datastore(&setup.store)?; - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let pool_config: MediaPoolConfig = config.lookup("pool", &setup.pool)?; let (drive_config, _digest) = pbs_config::drive::config()?; diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index f625ba03..8b60a2b4 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -514,7 +514,7 @@ pub fn label_media( rpcenv: &mut dyn RpcEnvironment, ) -> Result { if let Some(ref pool) = pool { - let (pool_config, _digest) = config::media_pool::config()?; + let (pool_config, _digest) = pbs_config::media_pool::config()?; if pool_config.sections.get(pool).is_none() { bail!("no such pool ('{}')", pool); @@ -1029,7 +1029,7 @@ pub fn barcode_label_media( rpcenv: &mut dyn RpcEnvironment, ) -> Result { if let Some(ref pool) = pool { - let (pool_config, _digest) = config::media_pool::config()?; + let (pool_config, _digest) = pbs_config::media_pool::config()?; if pool_config.sections.get(pool).is_none() { bail!("no such pool ('{}')", pool); diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs index feef3921..15514d52 100644 --- a/src/api2/tape/media.rs +++ b/src/api2/tape/media.rs @@ -18,13 +18,12 @@ use pbs_api_types::{ use crate::{ config::{ - self, cached_user_info::CachedUserInfo, acl::{ PRIV_TAPE_AUDIT, }, }, - tape::{ + tape::{ TAPE_STATUS_DIR, Inventory, MediaPool, @@ -54,7 +53,7 @@ pub async fn list_media_sets( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let status_path = Path::new(TAPE_STATUS_DIR); @@ -143,7 +142,7 @@ pub async fn list_media( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let status_path = Path::new(TAPE_STATUS_DIR); @@ -410,7 +409,7 @@ pub fn list_content( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let (config, _digest) = config::media_pool::config()?; + let (config, _digest) = pbs_config::media_pool::config()?; let status_path = Path::new(TAPE_STATUS_DIR); let inventory = Inventory::load(status_path)?; diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs index 12193fc8..4206274a 100644 --- a/src/bin/docgen.rs +++ b/src/bin/docgen.rs @@ -61,7 +61,7 @@ fn main() -> Result<(), Error> { "remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG), "sync.cfg" => dump_section_config(&config::sync::CONFIG), "verification.cfg" => dump_section_config(&config::verify::CONFIG), - "media-pool.cfg" => dump_section_config(&config::media_pool::CONFIG), + "media-pool.cfg" => dump_section_config(&pbs_config::media_pool::CONFIG), "config::acl::Role" => dump_enum_properties(&config::acl::Role::API_SCHEMA)?, _ => bail!("docgen: got unknown type"), }; diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 6d3c2d78..14216e69 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -22,6 +22,7 @@ use pbs_tools::format::{ }; use pbs_config::drive::complete_drive_name; +use pbs_config::media_pool::complete_pool_name; use proxmox_backup::{ api2::{ @@ -39,7 +40,6 @@ use proxmox_backup::{ }, config::{ datastore::complete_datastore_name, - media_pool::complete_pool_name, }, tape::{ BlockReadError, diff --git a/src/bin/proxmox_tape/backup_job.rs b/src/bin/proxmox_tape/backup_job.rs index f181868c..f658783b 100644 --- a/src/bin/proxmox_tape/backup_job.rs +++ b/src/bin/proxmox_tape/backup_job.rs @@ -125,7 +125,7 @@ pub fn backup_job_commands() -> CommandLineInterface { .completion_cb("id", config::tape_job::complete_tape_job_id) .completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("store", config::datastore::complete_datastore_name) - .completion_cb("pool", config::media_pool::complete_pool_name) + .completion_cb("pool", pbs_config::media_pool::complete_pool_name) .completion_cb("drive", crate::complete_drive_name) ) .insert("update", @@ -134,7 +134,7 @@ pub fn backup_job_commands() -> CommandLineInterface { .completion_cb("id", config::tape_job::complete_tape_job_id) .completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("store", config::datastore::complete_datastore_name) - .completion_cb("pool", config::media_pool::complete_pool_name) + .completion_cb("pool", pbs_config::media_pool::complete_pool_name) .completion_cb("drive", crate::complete_drive_name) ) .insert("remove", diff --git a/src/bin/proxmox_tape/media.rs b/src/bin/proxmox_tape/media.rs index 8b866e3e..e65108ec 100644 --- a/src/bin/proxmox_tape/media.rs +++ b/src/bin/proxmox_tape/media.rs @@ -15,6 +15,7 @@ use pbs_api_types::{ MediaContentListFilter, }; use pbs_config::drive::complete_changer_name; +use pbs_config::media_pool::complete_pool_name; use proxmox_backup::{ api2, @@ -23,9 +24,6 @@ use proxmox_backup::{ complete_media_uuid, complete_media_set_uuid, }, - config::{ - media_pool::complete_pool_name, - }, }; pub fn media_commands() -> CommandLineInterface { diff --git a/src/bin/proxmox_tape/pool.rs b/src/bin/proxmox_tape/pool.rs index a20bb33f..0889a764 100644 --- a/src/bin/proxmox_tape/pool.rs +++ b/src/bin/proxmox_tape/pool.rs @@ -10,6 +10,8 @@ use proxmox::{ }, }; +use pbs_config::media_pool::complete_pool_name; + use proxmox_backup::{ api2::{ self, @@ -18,9 +20,6 @@ use proxmox_backup::{ }, }, config::{ - media_pool::{ - complete_pool_name, - }, tape_encryption_keys:: { complete_key_fingerprint, }, diff --git a/src/config/mod.rs b/src/config/mod.rs index 80246407..89f155e0 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -25,7 +25,6 @@ pub mod tfa; pub mod token_shadow; pub mod user; pub mod verify; -pub mod media_pool; pub mod tape_encryption_keys; pub mod tape_job;