diff --git a/src/api2/config/media_pool.rs b/src/api2/config/media_pool.rs index 33e4993e..90e1d293 100644 --- a/src/api2/config/media_pool.rs +++ b/src/api2/config/media_pool.rs @@ -11,7 +11,6 @@ use proxmox::{ use crate::{ api2::types::{ - DRIVE_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA, MEDIA_SET_NAMING_TEMPLATE_SCHEMA, MEDIA_SET_ALLOCATION_POLICY_SCHEMA, @@ -19,12 +18,7 @@ use crate::{ TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA, MediaPoolConfig, }, - config::{ - self, - drive::{ - check_drive_exists, - }, - }, + config, }; #[api( @@ -34,9 +28,6 @@ use crate::{ name: { schema: MEDIA_POOL_NAME_SCHEMA, }, - drive: { - schema: DRIVE_NAME_SCHEMA, - }, allocation: { schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA, optional: true, @@ -59,7 +50,6 @@ use crate::{ /// Create a new media pool pub fn create_pool( name: String, - drive: String, allocation: Option, retention: Option, template: Option, @@ -74,12 +64,8 @@ pub fn create_pool( bail!("Media pool '{}' already exists", name); } - let (drive_config, _) = config::drive::config()?; - check_drive_exists(&drive_config, &drive)?; - let item = MediaPoolConfig { name: name.clone(), - drive, allocation, retention, template, @@ -160,10 +146,6 @@ pub enum DeletableProperty { name: { schema: MEDIA_POOL_NAME_SCHEMA, }, - drive: { - schema: DRIVE_NAME_SCHEMA, - optional: true, - }, allocation: { schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA, optional: true, @@ -194,7 +176,6 @@ pub enum DeletableProperty { /// Update media pool settings pub fn update_pool( name: String, - drive: Option, allocation: Option, retention: Option, template: Option, @@ -219,7 +200,6 @@ pub fn update_pool( } } - if let Some(drive) = drive { data.drive = drive; } if allocation.is_some() { data.allocation = allocation; } if retention.is_some() { data.retention = retention; } if template.is_some() { data.template = template; } diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 91f5983e..b512ef98 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -28,6 +28,7 @@ use crate::{ Authid, DATASTORE_SCHEMA, MEDIA_POOL_NAME_SCHEMA, + DRIVE_NAME_SCHEMA, UPID_SCHEMA, MediaPoolConfig, }, @@ -53,6 +54,9 @@ use crate::{ pool: { schema: MEDIA_POOL_NAME_SCHEMA, }, + drive: { + schema: DRIVE_NAME_SCHEMA, + }, "eject-media": { description: "Eject media upon job completion.", type: bool, @@ -73,6 +77,7 @@ use crate::{ pub fn backup( store: String, pool: String, + drive: String, eject_media: Option, export_media_set: Option, rpcenv: &mut dyn RpcEnvironment, @@ -87,7 +92,7 @@ pub fn backup( let (drive_config, _digest) = config::drive::config()?; // early check before starting worker - check_drive_exists(&drive_config, &pool_config.drive)?; + check_drive_exists(&drive_config, &drive)?; let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; @@ -100,7 +105,7 @@ pub fn backup( auth_id, to_stdout, move |worker| { - backup_worker(&worker, datastore, &pool_config, eject_media, export_media_set)?; + backup_worker(&worker, datastore, &drive, &pool_config, eject_media, export_media_set)?; Ok(()) } )?; @@ -115,6 +120,7 @@ pub const ROUTER: Router = Router::new() fn backup_worker( worker: &WorkerTask, datastore: Arc, + drive: &str, pool_config: &MediaPoolConfig, eject_media: bool, export_media_set: bool, @@ -125,13 +131,13 @@ fn backup_worker( let _lock = MediaPool::lock(status_path, &pool_config.name)?; task_log!(worker, "update media online status"); - let has_changer = update_media_online_status(&pool_config.drive)?; + let has_changer = update_media_online_status(drive)?; let use_offline_media = !has_changer; let pool = MediaPool::with_config(status_path, &pool_config, use_offline_media)?; - let mut pool_writer = PoolWriter::new(pool, &pool_config.drive)?; + let mut pool_writer = PoolWriter::new(pool, drive)?; let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?; diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index b740fb48..f9a6e125 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -27,6 +27,7 @@ use crate::{ tools::compute_file_csum, api2::types::{ DATASTORE_SCHEMA, + DRIVE_NAME_SCHEMA, UPID_SCHEMA, Authid, MediaPoolConfig, @@ -82,6 +83,9 @@ pub const ROUTER: Router = Router::new() store: { schema: DATASTORE_SCHEMA, }, + drive: { + schema: DRIVE_NAME_SCHEMA, + }, "media-set": { description: "Media set UUID.", type: String, @@ -95,6 +99,7 @@ pub const ROUTER: Router = Router::new() /// Restore data from media-set pub fn restore( store: String, + drive: String, media_set: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { @@ -110,12 +115,13 @@ pub fn restore( let pool = inventory.lookup_media_set_pool(&media_set_uuid)?; + // check if pool exists let (config, _digest) = config::media_pool::config()?; - let pool_config: MediaPoolConfig = config.lookup("pool", &pool)?; + let _pool_config: MediaPoolConfig = config.lookup("pool", &pool)?; let (drive_config, _digest) = config::drive::config()?; // early check before starting worker - check_drive_exists(&drive_config, &pool_config.drive)?; + check_drive_exists(&drive_config, &drive)?; let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; @@ -153,8 +159,6 @@ pub fn restore( } } - let drive = &pool_config.drive; - worker.log(format!("Restore mediaset '{}'", media_set)); if let Some(fingerprint) = encryption_key_fingerprint { worker.log(format!("Encryption key fingerprint: {}", fingerprint)); @@ -175,7 +179,7 @@ pub fn restore( &worker, media_id, &drive_config, - drive, + &drive, &datastore, &auth_id, )?; diff --git a/src/api2/types/tape/media_pool.rs b/src/api2/types/tape/media_pool.rs index fbee8a69..c28f7efe 100644 --- a/src/api2/types/tape/media_pool.rs +++ b/src/api2/types/tape/media_pool.rs @@ -21,7 +21,6 @@ use crate::{ parse_calendar_event, }, api2::types::{ - DRIVE_NAME_SCHEMA, PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_FORMAT, TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA, @@ -116,9 +115,6 @@ impl std::str::FromStr for RetentionPolicy { name: { schema: MEDIA_POOL_NAME_SCHEMA, }, - drive: { - schema: DRIVE_NAME_SCHEMA, - }, allocation: { schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA, optional: true, @@ -142,8 +138,6 @@ impl std::str::FromStr for RetentionPolicy { pub struct MediaPoolConfig { /// The pool name pub name: String, - /// The associated drive - pub drive: String, /// Media Set allocation policy #[serde(skip_serializing_if="Option::is_none")] pub allocation: Option, diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index dd7d3a78..76c58108 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -765,6 +765,10 @@ async fn clean_drive(param: Value) -> Result<(), Error> { pool: { schema: MEDIA_POOL_NAME_SCHEMA, }, + drive: { + schema: DRIVE_NAME_SCHEMA, + optional: true, + }, "eject-media": { description: "Eject media upon job completion.", type: bool, @@ -783,10 +787,14 @@ async fn clean_drive(param: Value) -> Result<(), Error> { }, )] /// Backup datastore to tape media pool -async fn backup(param: Value) -> Result<(), Error> { +async fn backup(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); + let (config, _digest) = config::drive::config()?; + + param["drive"] = lookup_drive_name(¶m, &config)?.into(); + let mut client = connect_to_localhost()?; let result = client.post("api2/json/tape/backup", Some(param)).await?; @@ -802,6 +810,10 @@ async fn backup(param: Value) -> Result<(), Error> { store: { schema: DATASTORE_SCHEMA, }, + drive: { + schema: DRIVE_NAME_SCHEMA, + optional: true, + }, "media-set": { description: "Media set UUID.", type: String, @@ -814,10 +826,14 @@ async fn backup(param: Value) -> Result<(), Error> { }, )] /// Restore data from media-set -async fn restore(param: Value) -> Result<(), Error> { +async fn restore(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); + let (config, _digest) = config::drive::config()?; + + param["drive"] = lookup_drive_name(¶m, &config)?.into(); + let mut client = connect_to_localhost()?; let result = client.post("api2/json/tape/restore", Some(param)).await?; diff --git a/src/bin/proxmox_tape/pool.rs b/src/bin/proxmox_tape/pool.rs index a1b471eb..fc6bf4da 100644 --- a/src/bin/proxmox_tape/pool.rs +++ b/src/bin/proxmox_tape/pool.rs @@ -18,9 +18,6 @@ use proxmox_backup::{ }, }, config::{ - drive::{ - complete_drive_name, - }, media_pool::{ complete_pool_name, }, @@ -50,7 +47,6 @@ pub fn pool_commands() -> CommandLineInterface { CliCommand::new(&api2::config::media_pool::API_METHOD_CREATE_POOL) .arg_param(&["name"]) .completion_cb("name", complete_pool_name) - .completion_cb("drive", complete_drive_name) .completion_cb("encrypt", complete_key_fingerprint) ) .insert( @@ -58,7 +54,6 @@ pub fn pool_commands() -> CommandLineInterface { CliCommand::new(&api2::config::media_pool::API_METHOD_UPDATE_POOL) .arg_param(&["name"]) .completion_cb("name", complete_pool_name) - .completion_cb("drive", complete_drive_name) .completion_cb("encrypt", complete_key_fingerprint) ) ; @@ -99,7 +94,6 @@ fn list_pools( let options = default_table_format_options() .column(ColumnConfig::new("name")) - .column(ColumnConfig::new("drive")) .column(ColumnConfig::new("allocation")) .column(ColumnConfig::new("retention")) .column(ColumnConfig::new("template"))