move media_pool config to pbs_config workspace

This commit is contained in:
Dietmar Maurer 2021-09-06 08:56:04 +02:00
parent 68149b9045
commit aad2d162ab
12 changed files with 38 additions and 47 deletions

View File

@ -1,5 +1,6 @@
pub mod domains; pub mod domains;
pub mod drive; pub mod drive;
pub mod media_pool;
pub mod remote; pub mod remote;
use anyhow::{format_err, Error}; use anyhow::{format_err, Error};

View File

@ -22,14 +22,9 @@ use proxmox::{
}, },
}; };
use pbs_config::{open_backup_lockfile, BackupLockGuard}; use pbs_api_types::{MEDIA_POOL_NAME_SCHEMA, MediaPoolConfig};
use crate::{ use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
api2::types::{
MEDIA_POOL_NAME_SCHEMA,
MediaPoolConfig,
},
};
lazy_static! { lazy_static! {
/// Static [`SectionConfig`] to access parser/writer functions. /// Static [`SectionConfig`] to access parser/writer functions.
@ -73,7 +68,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
/// Save the configuration file /// Save the configuration file
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
let raw = CONFIG.write(MEDIA_POOL_CFG_FILENAME, &config)?; 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 // shell completion helper

View File

@ -10,15 +10,15 @@ use proxmox::{
}, },
}; };
use pbs_api_types::{
Authid,
MEDIA_POOL_NAME_SCHEMA,
MediaPoolConfig,
MediaPoolConfigUpdater,
};
use crate::{ use crate::{
api2::types::{
Authid,
MEDIA_POOL_NAME_SCHEMA,
MediaPoolConfig,
MediaPoolConfigUpdater,
},
config::{ config::{
self,
cached_user_info::CachedUserInfo, cached_user_info::CachedUserInfo,
acl::{ acl::{
PRIV_TAPE_AUDIT, PRIV_TAPE_AUDIT,
@ -46,9 +46,9 @@ pub fn create_pool(
config: MediaPoolConfig, config: MediaPoolConfig,
) -> Result<(), Error> { ) -> 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() { if section_config.sections.get(&config.name).is_some() {
bail!("Media pool '{}' already exists", config.name); bail!("Media pool '{}' already exists", config.name);
@ -56,7 +56,7 @@ pub fn create_pool(
section_config.set_data(&config.name, "pool", &config)?; section_config.set_data(&config.name, "pool", &config)?;
config::media_pool::save_config(&section_config)?; pbs_config::media_pool::save_config(&section_config)?;
Ok(()) Ok(())
} }
@ -81,7 +81,7 @@ pub fn list_pools(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?; 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::<MediaPoolConfig>("pool")?; let list = config.convert_to_typed_array::<MediaPoolConfig>("pool")?;
@ -116,7 +116,7 @@ pub fn list_pools(
/// Get media pool configuration /// Get media pool configuration
pub fn get_config(name: String) -> Result<MediaPoolConfig, Error> { pub fn get_config(name: String) -> Result<MediaPoolConfig, Error> {
let (config, _digest) = config::media_pool::config()?; let (config, _digest) = pbs_config::media_pool::config()?;
let data: MediaPoolConfig = config.lookup("pool", &name)?; let data: MediaPoolConfig = config.lookup("pool", &name)?;
@ -172,9 +172,9 @@ pub fn update_pool(
delete: Option<Vec<DeletableProperty>>, delete: Option<Vec<DeletableProperty>>,
) -> Result<(), Error> { ) -> 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)?; let mut data: MediaPoolConfig = config.lookup("pool", &name)?;
@ -206,7 +206,7 @@ pub fn update_pool(
config.set_data(&name, "pool", &data)?; config.set_data(&name, "pool", &data)?;
config::media_pool::save_config(&config)?; pbs_config::media_pool::save_config(&config)?;
Ok(()) Ok(())
} }
@ -227,16 +227,16 @@ pub fn update_pool(
/// Delete a media pool configuration /// Delete a media pool configuration
pub fn delete_pool(name: String) -> Result<(), Error> { 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) { match config.sections.get(&name) {
Some(_) => { config.sections.remove(&name); }, Some(_) => { config.sections.remove(&name); },
None => bail!("delete pool '{}' failed - no such pool", name), None => bail!("delete pool '{}' failed - no such pool", name),
} }
config::media_pool::save_config(&config)?; pbs_config::media_pool::save_config(&config)?;
Ok(()) Ok(())
} }

View File

@ -122,7 +122,7 @@ pub fn list_tape_backup_jobs(
let user_info = CachedUserInfo::new()?; let user_info = CachedUserInfo::new()?;
let (job_config, digest) = config::tape_job::config()?; 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 (drive_config, _digest) = pbs_config::drive::config()?;
let job_list_iter = job_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 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 pool_config: MediaPoolConfig = config.lookup("pool", &setup.pool)?;
let (drive_config, _digest) = pbs_config::drive::config()?; let (drive_config, _digest) = pbs_config::drive::config()?;
@ -370,7 +370,7 @@ pub fn backup(
let datastore = DataStore::lookup_datastore(&setup.store)?; 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 pool_config: MediaPoolConfig = config.lookup("pool", &setup.pool)?;
let (drive_config, _digest) = pbs_config::drive::config()?; let (drive_config, _digest) = pbs_config::drive::config()?;

View File

@ -514,7 +514,7 @@ pub fn label_media(
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
if let Some(ref pool) = pool { 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() { if pool_config.sections.get(pool).is_none() {
bail!("no such pool ('{}')", pool); bail!("no such pool ('{}')", pool);
@ -1029,7 +1029,7 @@ pub fn barcode_label_media(
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
if let Some(ref pool) = pool { 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() { if pool_config.sections.get(pool).is_none() {
bail!("no such pool ('{}')", pool); bail!("no such pool ('{}')", pool);

View File

@ -18,13 +18,12 @@ use pbs_api_types::{
use crate::{ use crate::{
config::{ config::{
self,
cached_user_info::CachedUserInfo, cached_user_info::CachedUserInfo,
acl::{ acl::{
PRIV_TAPE_AUDIT, PRIV_TAPE_AUDIT,
}, },
}, },
tape::{ tape::{
TAPE_STATUS_DIR, TAPE_STATUS_DIR,
Inventory, Inventory,
MediaPool, MediaPool,
@ -54,7 +53,7 @@ pub async fn list_media_sets(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?; 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 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 auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?; 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 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 auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?; 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 status_path = Path::new(TAPE_STATUS_DIR);
let inventory = Inventory::load(status_path)?; let inventory = Inventory::load(status_path)?;

View File

@ -61,7 +61,7 @@ fn main() -> Result<(), Error> {
"remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG), "remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG),
"sync.cfg" => dump_section_config(&config::sync::CONFIG), "sync.cfg" => dump_section_config(&config::sync::CONFIG),
"verification.cfg" => dump_section_config(&config::verify::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)?, "config::acl::Role" => dump_enum_properties(&config::acl::Role::API_SCHEMA)?,
_ => bail!("docgen: got unknown type"), _ => bail!("docgen: got unknown type"),
}; };

View File

@ -22,6 +22,7 @@ use pbs_tools::format::{
}; };
use pbs_config::drive::complete_drive_name; use pbs_config::drive::complete_drive_name;
use pbs_config::media_pool::complete_pool_name;
use proxmox_backup::{ use proxmox_backup::{
api2::{ api2::{
@ -39,7 +40,6 @@ use proxmox_backup::{
}, },
config::{ config::{
datastore::complete_datastore_name, datastore::complete_datastore_name,
media_pool::complete_pool_name,
}, },
tape::{ tape::{
BlockReadError, BlockReadError,

View File

@ -125,7 +125,7 @@ pub fn backup_job_commands() -> CommandLineInterface {
.completion_cb("id", config::tape_job::complete_tape_job_id) .completion_cb("id", config::tape_job::complete_tape_job_id)
.completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("schedule", config::datastore::complete_calendar_event)
.completion_cb("store", config::datastore::complete_datastore_name) .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) .completion_cb("drive", crate::complete_drive_name)
) )
.insert("update", .insert("update",
@ -134,7 +134,7 @@ pub fn backup_job_commands() -> CommandLineInterface {
.completion_cb("id", config::tape_job::complete_tape_job_id) .completion_cb("id", config::tape_job::complete_tape_job_id)
.completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("schedule", config::datastore::complete_calendar_event)
.completion_cb("store", config::datastore::complete_datastore_name) .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) .completion_cb("drive", crate::complete_drive_name)
) )
.insert("remove", .insert("remove",

View File

@ -15,6 +15,7 @@ use pbs_api_types::{
MediaContentListFilter, MediaContentListFilter,
}; };
use pbs_config::drive::complete_changer_name; use pbs_config::drive::complete_changer_name;
use pbs_config::media_pool::complete_pool_name;
use proxmox_backup::{ use proxmox_backup::{
api2, api2,
@ -23,9 +24,6 @@ use proxmox_backup::{
complete_media_uuid, complete_media_uuid,
complete_media_set_uuid, complete_media_set_uuid,
}, },
config::{
media_pool::complete_pool_name,
},
}; };
pub fn media_commands() -> CommandLineInterface { pub fn media_commands() -> CommandLineInterface {

View File

@ -10,6 +10,8 @@ use proxmox::{
}, },
}; };
use pbs_config::media_pool::complete_pool_name;
use proxmox_backup::{ use proxmox_backup::{
api2::{ api2::{
self, self,
@ -18,9 +20,6 @@ use proxmox_backup::{
}, },
}, },
config::{ config::{
media_pool::{
complete_pool_name,
},
tape_encryption_keys:: { tape_encryption_keys:: {
complete_key_fingerprint, complete_key_fingerprint,
}, },

View File

@ -25,7 +25,6 @@ pub mod tfa;
pub mod token_shadow; pub mod token_shadow;
pub mod user; pub mod user;
pub mod verify; pub mod verify;
pub mod media_pool;
pub mod tape_encryption_keys; pub mod tape_encryption_keys;
pub mod tape_job; pub mod tape_job;